ESP_WiFiManager for ESP32 and ESP8266. Now supporting ESP32 LittleFS

Can you please clarify which version of ArduinoJson your library needs

Version 5.13.5
Don’t use later version yet.

Can you please add the ability to pass dns address in WiFi.Config in static ip connection section :slight_smile:

I’m sorry I still don’t fully understand your idea.

From my understanding, WiFi.config() function belongs to these corresponding libraries (ESP8266WiFi or ESP32’s WiFi).
Whenever you are still calling WiFi library function, you’re still dealing with local WiFi network, and at that time, you’re more concerned about :

  • SSID and password of the router you’re trying to connect to
  • If you need to specify board’s static IP address for that local WiFi, instead of using DHCP, you can call the same function such as WiFi.config(StaticIP, GateWayIP, Subnet).
  • You can also specify up to 2 static DNS server IPs.

The following are relating function prototypes

  • ESP8266, file ./esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress arg2, IPAddress arg3, IPAddress dns2)

  • ESP32, file ./espressif/esp32/libraries/WiFi/src/WiFiSTA.cpp

bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)

You’re not dealing with (D)DNS address (of the Blynk Server, boards. etc. ) at this time yet.

I still don’t think we need to change anything in the ESP8266 / ESP32 WiFi as well as ESP_WiFiManager libraries to fulfill your needs.

It’s possibly I still don’t fully know what you meant. If this is the case, can you post a more detailed request / usage / application, and/or sample code.

Updated Jan 5th 2020

New version v1.0.3.

  1. Add option not displaying AvailablePages in Info page.
  2. Delete unnecessary files
  3. Modify examples, Images and enhance README.md
  4. Example to use DHCP personalized HostName conforming to RFC952

Updated Jan 7th 2020

New version v1.0.4

  1. Add ESP_WiFiManager built-in yet configurable RFC952 DHCP hostname.
  2. Modify examples to use latest features.
  3. Add example ESP_FSWebServer
  4. Enhance and update README.md

Now, you just call the constructor with the “Personalized-Hostname” as argument. You don’t need to call WiFi.hostname("Personalized-Hostname"); or WiFi.setHostname("Personalized-Hostname"); anymore.

  //Local intialization. Once its business is done, there is no need to keep it around
  // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
  //ESP_WiFiManager ESP_wifiManager;
  // Use this to personalize DHCP hostname (RFC952 conformed)
  ESP_WiFiManager ESP_wifiManager("Personalized-Hostname");
2 Likes

Thanks for your response. Sorry it took so long to get back to you.

What I’m looking for is the ability to configure the 2 static DNS server IP’s inside the wifimanager portal. Tzapu’s wifimanager doesn’t have that ability. You can only enter the static IP address, the gateway IP address and the subnet mask in the portal. Maybe I’m doing something wrong, but I can’t get my device to connect to blynk without at least 1 DNS IP address specified in WiFi.config(). I therefore had to modify the Tzapu’s wifimanager library myself to achieve what I just described. See below for details.

Within the following function

int WiFiManager::connectWifi(String ssid, String pass)

I replaced

if (_sta_static_ip) {
    DEBUG_WM(F("Custom STA IP/GW/Subnet"));
	WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
	DEBUG_WM(WiFi.localIP());
  }

with

if (_sta_static_ip) {
    DEBUG_WM(F("Custom STA IP/GW/Subnet"));
	//***** Added section for DNS config option *****
	if (_sta_static_dns1 && _sta_static_dns2) {
		DEBUG_WM(F("dns1 and dns2 set"));
		WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns1, _sta_static_dns2);
	}
	else if (_sta_static_dns1) {
		DEBUG_WM(F("only dns1 set"));
		WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns1);
	}
	else {
		DEBUG_WM(F("No DNS server set"));
		WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
    }
	//***** End added section for DNS config option *****
	
	DEBUG_WM(WiFi.localIP());
  }

Then I modified this function

void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns_address_1, IPAddress dns_address_2) {
  _sta_static_ip = ip;
  _sta_static_gw = gw;
  _sta_static_sn = sn;
  _sta_static_dns1 = dns_address_1; //***** Added argument *****
  _sta_static_dns2 = dns_address_2; //***** Added argument *****
}

I then added the DNS options to the portal form inside the following function

void WiFiManager::handleWifi(boolean scan) {

like so

//***** Added for DNS address options *****
	page += item;

    item = FPSTR(HTTP_FORM_PARAM);
    item.replace("{i}", "dns1");
    item.replace("{n}", "dns1");
    item.replace("{p}", "DNS Address 1");
    item.replace("{l}", "15");
    item.replace("{v}", _sta_static_dns1.toString());
	
	page += item;

    item = FPSTR(HTTP_FORM_PARAM);
    item.replace("{i}", "dns2");
    item.replace("{n}", "dns2");
    item.replace("{p}", "DNS Address 2");
    item.replace("{l}", "15");
    item.replace("{v}", _sta_static_dns2.toString());
	//***** End added for DNS address options *****

And also inside the handleWifiSave function like so

//*****  Added for DNS Options *****
  if (server->arg("dns1") != "") {
    DEBUG_WM(F("DNS address 1"));
    DEBUG_WM(server->arg("dns1"));
    String dns1 = server->arg("dns1");
    optionalIPFromString(&_sta_static_dns1, dns1.c_str());
  }
  if (server->arg("dns2") != "") {
    DEBUG_WM(F("DNS address 2"));
    DEBUG_WM(server->arg("dns2"));
    String dns2 = server->arg("dns2");
    optionalIPFromString(&_sta_static_dns2, dns2.c_str());
  }
  //*****  End added for DNS Options *****

Finally, Inside the .h file, I modified the setSTAStaticIPConfig as follows

void          setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns_address_1, IPAddress dns_address_2);

And also added these two private variables

IPAddress     _sta_static_dns1;
IPAddress     _sta_static_dns2;
1 Like

Hello,

Normally, you don’t need to specify static DNS servers. If you have problem, I believe your settings of the Internet Modem / routers (or even the modem / routers themselves) / creating the issue.
Many people, and I personally never have to explicitly specify the DNS servers, yet we rely on the DHCP Protocol to do the dirty work for us.

So, you’ll get the IP, gateway, DNS server(s) IP, etc. at the same time.
Most of the times, we force the local router to act as caching local DNS server.

#### Recursive and caching name server
...
Internet service providers typically provide recursive and caching name servers for their customers. In addition, many home networking routers implement DNS caches and recursors to improve efficiency in the local network.

Anyway, your fixing code is impressive, showing you have very deep knowledge of the WiFiManager.
I’ll have a more detailed look at the code, and find a way to include in the library later to add more features to it.

Thanks and Regards,
KH

Dear @Amorphous

I just include the feature you suggest along with your code into the new Library version v1.0.5 (certainly with comments to thank your contribution)

Contributions and thanks
2. Thanks to [Amorphous](https://community.blynk.cc/t/esp-wifimanager-for-esp32-and-esp8266/42257/13) for the static DNS feature and code, included in v1.0.5

Here is the Config Page to allow you to input those parameters.

Thanks and Regards,
KH

2 Likes

Wow! That was quick! Thanks for adding that that option. I’m going to have to switch libraries now and try it out :wink:. Hopefully more people than just myself will find it useful when setting a static IP address. And hopefully my cludged together code works OK and doesn’t break anything else. If it does causes problems, everyone will know who to blame :rofl:.

1 Like

Don’t be so humble. I checked and even haven’t change a letter. I tested and it’s very stable.
Waiting for your real test, then next idea :wink:
Thanks again.
Regards,
KH

PS: BTW, did you find out why you still need to specify static DNS? Is this some router settings?

A current discussion about adding new configurable features (OTA and NTP timezone) for this library is going on

Everybody is welcome to have suggestion.

4 Likes

Hello , can you help ?
ESP_WiFiManager v1.05

exit status 1
no matching function for call to ‘ESP_WiFiManager::setSTAStaticIPConfig(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress)’

And can you add " Change auth token "
const char* auth =

To use the new function

`ESP_WiFiManager::setSTAStaticIPConfig(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress)’

you must install / update to ESP_WiFiManager v1.0.5.

Please use Arduino Library Manager to install/update from Menu (Tools -> Manage Libraries…)

Load one of the examples, then test compile it using ESP8266 or ESP32 board from Tools in the menu.

1 Like

This looks extremely promising @khoih, thanks for sharing! I’ve been frustrated for a long time that there hasn’t been an easy to use WiFi manager for ESP32. I’ll definitely need to try this on my next project.

1 Like

Hello @ristomatti,

You’re very welcome to use the library.

Please share your experience, difficulties, bugs, etc in

or bugs, feature requests, etc. in GitHub

Update

New version v1.0.6-beta

  • Add NTP data to show current TimeZone so that you can use in your sketch
  • Add support to ArduinoJson 6.0.0+ (currently v6.14.1) as well as 5.13.5- to examples

Update

New version v1.0.6

2 Likes

Update June 11th 2020

Releases 1.0.8

  1. Fix setSTAStaticIPConfig issue. See Static Station IP doesn’t work
  2. Add LittleFS support for ESP8266 core 2.7.1+ in examples to replace deprecated SPIFFS.
  3. Restructure code.

Releases 1.0.7

  1. Use just-in-time scanWiFiNetworks() to reduce connection time necessary for battery-operated DeepSleep application. Thanks to CrispinP for identifying, requesting and testing. See Starting WiFIManger is very slow (2000ms)
  2. Fix bug relating SPIFFS in examples :
  1. Fix README. See Accessing manager after connection
2 Likes

Hi Hoang
Thank you for sharing, that’s great. Wish you a good day.

Updated December 4th 2020

Releases v1.3.0

  1. Add LittleFS support to ESP32-related examples to use LittleFS_esp32 Library
  2. Add Version String

Releases v1.2.0

  1. Restore cpp code besides Impl.h code to use in case of multiple definition linker error. See Change Implementation to seperate *.h and *.cpp file instead of *.h and *-Impl.h and Support building in PlatformIO PR. Also have a look at HOWTO Fix Multiple Definitions Linker Error
  2. Fix bug /close does not close the config portal.

Releases v1.1.2

  1. Fix bug in examples.
  2. Add example.

Releases v1.1.1

  1. Add setCORSHeader function to allow configurable CORS Header. See Using CORS feature
  2. Fix typo and minor improvement.
  3. Shorten MultiWiFi connection time

Major Releases v1.1.0

  1. Add MultiWiFi feature to auto(Re)connect to the best WiFi at runtime
  2. Fix bug.
  3. Completely enhanced examples to use new MultiWiFi feature.

Releases v1.0.11

  1. Add optional CORS (Cross-Origin Resource Sharing) feature. Thanks to AlesSt. See more in Issue #27: CORS protection fires up with AJAX and Cross Origin Resource Sharing. To use, you must explicitly use #define USING_CORS_FEATURE true
  2. Solve issue softAP with custom IP sometimes not working. Thanks to AlesSt. See Issue #26: softAP with custom IP not working and Wifi.softAPConfig() sometimes set the wrong IP address.
  3. Temporary fix for issue of not clearing WiFi SSID/PW from flash of ESP32. Thanks to AlesSt. See more in Issue #25: API call /r doesnt clear credentials and WiFi.disconnect(true) problem.
  4. Fix autoConnect() feature to permit autoConnect() to use STA static IP or DHCP IP. Remove from deprecated function list.
  5. Enhance README.md with more instructions and illustrations.

Releases v1.0.10

  1. Don’t need to reinput already working SSID in Config Port to update other parameters, such as StaticIP.
  2. Disable/Enable StaticIP configuration in Config Portal from sketch. Valid only if DHCP is used.
  3. Change HTTP_XYZ constants to WM_HTTP_XYZ to avoid conflicts with future releases of ESP32 and ESP8266 cores.
  4. Add feature to change WiFi AP channel (fixed or random) to avoid conflict in AP-overcrowded environments.
  5. Enhance Config Portal GUI and get the item out of the bucket list.
  6. Enhance README.md with more instructions and illustrations.

Releases v1.0.9

  1. Fix ESP32 STAstaticIP bug.
  2. Enable changing from DHCP <-> static IP using Config Portal.
  3. Enable NTP configuration from sketch (USE_ESP_WIFIMANAGER_NTP, USE_CLOUDFLARE_NTP). See Issue #21: CloudFlare link in the default portal.
  4. Add, enhance examples (fix MDNS for ESP32 examples, add DRD feature).

Update December 23rd 2020

Major Releases v1.4.1

  1. Fix staticIP not saved in examples. See ESP32 static IP not saved after restarting the device
  2. Add structures and functions to handle AP and STA IPs.
  3. Add complex examples
  1. Add simple minimal examples
  1. Fix bug.
  2. Fix compiler warnings.
  3. Modify Version String
  4. Add Table of Contents

Hi,
I recently found your library and this forum. Nice library and support!
Is there any progress about adding OTA feature?
Regards.