0

I have the problem with a NodeMCU with an ESP8266 and the ArduinoIDE:

I want the to use a softAP and the password for this is supposed to be generated randomly everytime the devices is starting, it is supposed to be 8 digits long, just enough to be displayed on my 8digit 7segment display. I created a number that is being 8digits long and being converted to a String directly. Sadly, the "WiFi.softAP" command only accepts the variable type constant character, in brackets. How can I somehow get the string into a char with brackets or get WiFi.softAP to swallow a String type?

I am already this far:

MAX7219_7segment PWScreen(14,12,13);
String A,B,C;
const char *ssid = "Sellerie";

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
    server.send(200, "text/plain", C);
}

void setup() {
  int pw = random(10000000,99999999);
  String spassword = String(pw);
  //const char *password = spassword;
  pinMode(0, INPUT);  // D0
  pinMode(5, INPUT);  //D1 
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(14, OUTPUT);
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  WiFi.softAP(ssid, spassword);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
  PWScreen.write_number(pw);

Best regards Sellerie

3
  • const char *password = spassword.c_str(); Commented Mar 26, 2017 at 18:54
  • arduino.cc/en/Reference/CStr Commented Mar 26, 2017 at 18:55
  • That worked, thank you! Commented Mar 26, 2017 at 19:11

1 Answer 1

1

To solve this I simply uncommented the integer to string line

//const char *password = spassword;

and made const char *password = spassword; to const char *password = spassword.c_str(); as Bence Kaulics answered in the comment under my post, which works flawlessly. Thanks!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.