Hi,
I used following tutorial Input Data on HTML Form ESP32/ESP8266 Web Server Arduino IDE | Random Nerd Tutorials
and able save some variables values in the file. It works well. I can read them as String. The challenge I am facing is how to use them instead of hardcoded values.
IPAddress local_IP(192, 168, 200, 99); // hardcoded
boolean flg =true;
IPAddress l_IP;
if(!SPIFFS.begin()){
Serial.println(“An Error has occurred while mounting SPIFFS”);
flg =false;
// return;
}
if(flg)
{
String Sip = processor(“input_ip”);
Serial.print(“SIP “);
Serial.println(Sip);
flg =l_IP.fromString(Sip);
}
// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
// Configures static IP address
if(flg){
if (!WiFi.config(l_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
// Serial.println(“STA Failed to configure”);
}
}
else{
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
// Serial.println(“STA Failed to configure”);
}
}
WiFi.begin(ssid, password);
The above does not work. How to change the string value read from file to IP address.
Thanks
Hi.
When you say that it doesn’t work, what happens exactly?
What’s the error that you get?
Regards,
Sara
Hi Sara,
It appears you did understand my question or either I did not explain properly. My question was about how to change the String value IP address read from file to be converted into IPAddress. If you look at my code the error is in the following statement;
flg =l_IP.fromString(Sip); —— Wrong
flg =l_IP.fromString(Sip.c_str()); ——- Correct.
Anyway using this tutorial Input Data on HTML Form ESP32/ESP8266 Web Server Arduino IDE | Random Nerd Tutorials plus others. I have build a webserver plus a TCP/IP server to control a relay. When GPIO3 is held to low. It will start on AP mode. User can use webserver to input site specific ssid, psk,ip, mask, Gateway, and dns values. Hence, you do not need to hardcode this values. On the next boot GPIO3 not held to low it will start in station mode log into the user defined WIFI with a static IP address. User can control the app from a TCP/IP application from a specific port.
Thank you
Johan
Hi Sara,
Yes. it is working as expected. Keep up your good work.
Best regards
Johan