ESP32 connecting to Wi-fi using String ssid

I cannot connect to Wi-fi on my ESP32 DEV-KIT; I have a String which contains ssid and password, but the WIFI.begin() function accepts only const char*, and I don't know how to convert String to const char*. I have tried the c_str() function, but the result I am getting is != (not equal) to the actual ssid.

String ssid = "DIR-615A";
char ssidR;
const char* ssidR2 = "DIR-615A";

void setup() {
   ssidR = ssid.c_str();
   Serial.println(ssidR == ssidR2); //this returns 0

Both ssidR and ssidR2 look identical when printing them, but when I use ssidR to connect to wi-fi, it is not working.

The correct way:

const char* SSID          = "MyPassWord";
1 Like

ssid.c_str(); is the correct way to convert a String to a const char*
Do you pass a password as well as the SSID?

@faqeerdankgerm, your topic has been moved to a more suitable location on the forum as it is a more general question and not specific to Emergency Response: Covid-19 Projects.

Ah, yes, I hadn't even noticed that ssidR was a char... light_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.