• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Change String from file to IPAddress

Q&A Forum › Category: ESP8266 › Change String from file to IPAddress
0 Vote Up Vote Down
Johan Romuald asked 2 years ago

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
 
 

5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
When you say that it doesn’t work, what happens exactly?
What’s the error that you get?
Regards,
Sara

0 Vote Up Vote Down
Johan Romuald answered 2 years ago

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
 

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi Johan.
Just to clarify, is now everything working as expected?
Regards,
Sra

0 Vote Up Vote Down
Johan Romuald answered 2 years ago

Hi Sara,
Yes. it is working as expected. Keep up your good work. 
Best regards
Johan

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Great!
I’ll mark this issue as resolved.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.