ESP_WiFiManager for ESP32 and ESP8266. Now supporting ESP32 LittleFS

Just post the v1.0.1 release of ESP_WiFiManager on GitHub.

This library is based on, modified, bug-fixed and improved from:

  1. [Tzapu WiFiManager] (https://github.com/tzapu/WiFiManager)
  2. [Ken Taylor WiFiManager] (https://github.com/kentaylor/WiFiManager)

to add support to ESP32 besides ESP8266.

This library is tested and working with :

  1. The ESP8266 Arduino platform with a recent stable release [ ESP8266 Core 2.6.2 or newer ] (https://github.com/esp8266/Arduino)
  2. The ESP32 Arduino platform with a recent stable release [ ESP32 Core 1.0.4 or newer ] (https://github.com/espressif/arduino-esp32)

Will post examples using Blynk later.

5 Likes

I’ve always had a hard time getting my esp-01 to reconnect to WiFi and Blynk when I have a reserved IP address setup in my router for the ESP-01 and the router’s power is cycled. It seems to reconnect no problem when I do not reserve an IP address in the router. I’m curious to see if this library behaves any differently.

You’re very welcome to try.
I’ve tested and currently use Static as well as Dynamic IP address for many of my test boards without any issue, whether the routers’ power recycled or not.
If you experience any problem, I’m excited to know. Please post to the [Issue section] (https://github.com/khoih-prog/ESP_WiFiManager/issues).

Many thanks ahead.

Note
This library is written for ESP8266/ESP32 running its own Blynk / Arduino software, not for ESP-01 running AT firmware on top of Arduino Mega / UNO / Nano boards.
It’s been also tested on ESP-01 (WiFi Relay) as well as ESP8285 (in Son-OFF WiFi Smart Switches)

Thanks. I’ll give it a shot at some point. I run the esp-01 standalone not piggybacked so should be good there :slight_smile:

Updated: Dec 17th 2019

ESP_WiFiManager libraries v1.0.1 just got included into Arduino Library Manager.
Now you can install this library directly from Arduino Library Manager.

You’re welcome. I think you’ll be good there.

Update Dec 19th 2019

New version v1.0.2

Just added an example to enable ConfigPortal credentials to be changed at runtime, not hardcoded.

ConfigPortalParamsOnSwitch

This example demonstrates how to reconfigure ConfigPortal credentials (SSID and Password) at runtime, instead of hardcoding, by pressing configurable buttons (FLASH, BOOT, etc.).

Why do we need this feature?
In case we forget ConfigPortal credentials or they have been hacked / modified by someone having access to the hardware.

See more in

Updated Dec 29th 2019

  1. ESP_WiFiManager Library

Included in Platform.io

  1. ESP_DoubleResetDetector Library

The ESP_DoubleResetDetector library needed for [ConfigOnDoubleReset example] (https://github.com/khoih-prog/ESP_WiFiManager/blob/master/examples/ConfigOnDoubleReset/ConfigOnDoubleReset.ino) has just been included into Arduino Library Manager

This example demonstrates the open of ConfigPortal whenever the reset button is pressed twice so that you can change WiFi credentials, any stored data or do some out-of-schedule work whenever double press of reset button is detected.

1 Like

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