Skip to main content
deleted 43 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

Char* and string conversion from an esp8266 webserverESP8266 web server

I have the following arduinoArduino code for configuring a wifi connection through a simple webpage:

I declare:

char* ssid;

char* ssid;. Later I read a value from a SPIFFS config file where q_ssid ifq_ssid is declared as a string and successfully populated from the file:

strncpy(ssid, q_ssid.c_str(), 10 );

In the line above, I am limiting it to exactly 10 as that is the length of my wifi AP name that this connects to.If If I change the initial char*char* to:

char ssid[10];

then char ssid[10];, all works well, but SSIDs can have varying names, and if I do not use 10 chars, then the trailing spaces prevent connection in the statement: WiFi.begin(ssid, password);.

WiFi.begin(ssid, password);

On the webclientweb client handler that reads in values from the user, I use this:

String q_ssid = server.arg("ssid");
strncpy(ssid, q_ssid.c_str(), 10 );    

My question here is howHow can I dynamically assign the size of: char* ssid; So char* ssid; so that it can be used with the correct number of characters for the AP name that the user has stored from the webpage.?

Any help is greatly appreciated.

thanksThanks.

Char* and string conversion from an esp8266 webserver

I have the following arduino code for configuring wifi connection through a simple webpage:

I declare:

char* ssid;

Later I read a value from SPIFFS config file where q_ssid if declared as a string and successfully populated from the file:

strncpy(ssid, q_ssid.c_str(), 10 );

In the line above, I am limiting it to exactly 10 as that is the length of my wifi AP name that this connects to.If I change the initial char* to:

char ssid[10];

then all works well, but SSIDs can have varying names, and if I do not use 10 chars, then the trailing spaces prevent connection in the statement:

WiFi.begin(ssid, password);

On the webclient handler that reads in values from the user, I use this:

String q_ssid = server.arg("ssid");
strncpy(ssid, q_ssid.c_str(), 10 );    

My question here is how can I dynamically assign the size of: char* ssid; So that it can be used with the correct number of characters for the AP name that the user has stored from the webpage.

Any help greatly appreciated.

thanks

Char* and string conversion from an ESP8266 web server

I have the following Arduino code for configuring a wifi connection through a simple webpage:

I declare char* ssid;. Later I read a value from a SPIFFS config file where q_ssid is declared as a string and successfully populated from the file:

strncpy(ssid, q_ssid.c_str(), 10);

In the line above, I am limiting it to exactly 10 as that is the length of my wifi AP name that this connects to. If I change the initial char* to char ssid[10];, all works well, but SSIDs can have varying names, and if I do not use 10 chars, then the trailing spaces prevent connection in the statement WiFi.begin(ssid, password);.

On the web client handler that reads in values from the user, I use this:

String q_ssid = server.arg("ssid");
strncpy(ssid, q_ssid.c_str(), 10 );    

How can I dynamically assign the size of char* ssid; so that it can be used with the correct number of characters for the AP name that the user has stored from the webpage?

Any help is greatly appreciated.

Thanks.

Source Link

Char* and string conversion from an esp8266 webserver

I have the following arduino code for configuring wifi connection through a simple webpage:

I declare:

char* ssid;

Later I read a value from SPIFFS config file where q_ssid if declared as a string and successfully populated from the file:

strncpy(ssid, q_ssid.c_str(), 10 );

In the line above, I am limiting it to exactly 10 as that is the length of my wifi AP name that this connects to.If I change the initial char* to:

char ssid[10];

then all works well, but SSIDs can have varying names, and if I do not use 10 chars, then the trailing spaces prevent connection in the statement:

WiFi.begin(ssid, password);

On the webclient handler that reads in values from the user, I use this:

String q_ssid = server.arg("ssid");
strncpy(ssid, q_ssid.c_str(), 10 );    

My question here is how can I dynamically assign the size of: char* ssid; So that it can be used with the correct number of characters for the AP name that the user has stored from the webpage.

Any help greatly appreciated.

thanks