Arduino Forum

Development => Other Software Development => Topic started by: khoih-prog on Feb 19, 2020, 11:05 pm

Title: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS and ESP32_S2
Post by: khoih-prog on Feb 19, 2020, 11:05 pm
https://github.com/khoih-prog/ESP_WiFiManager (https://github.com/khoih-prog/ESP_WiFiManager)


How To Install Using Arduino Library Manager (https://www.ardu-badge.com/ESP_WiFiManager)


This is an ESP32 / ESP8266 WiFi Connection Manager with fallback web configuration portal. Use this library for configuring ESP32, ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName. With examples supporting ArduinoJson 6.0.0+ as well as 5.13.5- .


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.


## So, how it works?
In Configuration Portal Mode, it starts an access point called ESP_XXXXXX. Connect to it using the configurable password you can define in the code. For example, your_password (see examples):

Code: [Select]

// SSID and PW for Config Portal
String ssid = "ESP_" + String(ESP_getChipId(), HEX);
const char* password = "your_password";



After you connected, please, go to http://192.168.4.1, you'll see this Main page:

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Main.png)

Select Information to enter the Info page where the board info will be shown (long page)

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Info.png)

or short page (default)

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Info_Short.png)


Select Configuration to enter this page where you can select an AP and specify its WiFi Credentials

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Configuration.png)

Enter your credentials, then click Save. The WiFi Credentials will be saved and the board reboots to connect to the selected WiFi AP.

If you're already connected to a listed WiFi AP and don't want to change anything, just select Exit Portal from the Main page to reboot the board and connect to the previously-stored AP. The WiFi Credentials are still intact.


Sample Code

Code: [Select]

//Ported to ESP32
#ifdef ESP32
#include <esp_wifi.h>
#include <WiFi.h>
#include <WiFiClient.h>

#define ESP_getChipId()   ((uint32_t)ESP.getEfuseMac())

#define LED_ON      HIGH
#define LED_OFF     LOW
#else
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>

#define ESP_getChipId()   (ESP.getChipId())

#define LED_ON      LOW
#define LED_OFF     HIGH
#endif

#include <ESP_WiFiManager.h>              //https://github.com/khoih-prog/ESP_WiFiManager

// SSID and PW for your Router
String Router_SSID;
String Router_Pass;

void heartBeatPrint(void)
{
  static int num = 1;

  if (WiFi.status() == WL_CONNECTED)
    Serial.print("H");        // H means connected to WiFi
  else
    Serial.print("F");        // F means not connected to WiFi

  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(" ");
  }
}

void check_status()
{
  static ulong checkstatus_timeout = 0;

#define HEARTBEAT_INTERVAL    10000L
  // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    heartBeatPrint();
    checkstatus_timeout = millis() + HEARTBEAT_INTERVAL;
  }
}

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("\nStarting AutoConnectAP");

  // 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("AutoConnectAP");

  ESP_wifiManager.setDebugOutput(true);

  //set custom ip for portal
  ESP_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255, 255, 255, 0));

  ESP_wifiManager.setMinimumSignalQuality(-1);
  // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5+
  ESP_wifiManager.setSTAStaticIPConfig(IPAddress(192, 168, 2, 114), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0),
                                       IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8));

  // We can't use WiFi.SSID() in ESP32 as it's only valid after connected.
  // SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot
  // Have to create a new function to store in EEPROM/SPIFFS for this purpose
  Router_SSID = ESP_wifiManager.WiFi_SSID();
  Router_Pass = ESP_wifiManager.WiFi_Pass();

  //Remove this line if you do not want to see WiFi password printed
  Serial.println("Stored: SSID = " + Router_SSID + ", Pass = " + Router_Pass);

  if (Router_SSID != "")
  {
    ESP_wifiManager.setConfigPortalTimeout(60); //If no access point name has been previously entered disable timeout.
    Serial.println("Got stored Credentials. Timeout 60s");
  }
  else
  {
    Serial.println("No stored Credentials. No timeout");
  }

  String chipID = String(ESP_getChipId(), HEX);
  chipID.toUpperCase();
  
  // SSID and PW for Config Portal
  String AP_SSID = "ESP_" + chipID + "_AutoConnectAP";
  String AP_PASS = "MyESP_" + chipID;

  // Get Router SSID and PASS from EEPROM, then open Config portal AP named "ESP_XXXXXX_AutoConnectAP" and PW "MyESP_XXXXXX"
  // 1) If got stored Credentials, Config portal timeout is 60s
  // 2) If no stored Credentials, stay in Config portal until get WiFi Credentials
  ESP_wifiManager.autoConnect(AP_SSID.c_str(), AP_PASS.c_str());
  //or use this for Config portal AP named "ESP_XXXXXX" and NULL password
  //ESP_wifiManager.autoConnect();

  //if you get here you have connected to the WiFi
  Serial.println("WiFi connected");
}

void loop()
{
  // put your main code here, to run repeatedly
  check_status();
}




Title: Re: ESP_WiFiManager for ESP32 and ESP8266
Post by: khoih-prog on Aug 29, 2020, 09:30 am
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.

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Main.png)

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Configuration.png)

(https://github.com/khoih-prog/ESP_WiFiManager/raw/master/Images/Saved.png)

Debug Termimal Output Samples

This is terminal debug output when running ESP32_FSWebServer_DRD (https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ESP32_FSWebServer_DRD) on  ESP32 ESP32_DEV. Config Portal was requested by DRD to input and save Credentials. The boards then connected to WiFi AP HueNet1 using new Static IP successfully. WiFi AP HueNet1 is then lost, and board autoreconnects itself to backup WiFi AP HueNet2.


Code: [Select]
Starting ESP32_FSWebServer_DRD with DoubleResetDetect using SPIFFS on ESP32_DEV
FS File: /ConfigSW.json, size: 150B
FS File: /CanadaFlag_1.png, size: 40.25KB
FS File: /CanadaFlag_2.png, size: 8.12KB
FS File: /CanadaFlag_3.jpg, size: 10.89KB
FS File: /edit.htm.gz, size: 4.02KB
FS File: /favicon.ico, size: 1.12KB
FS File: /graphs.js.gz, size: 1.92KB
FS File: /index.htm, size: 3.63KB
FS File: /drd.dat, size: 4B
FS File: /wifi_cred.dat, size: 192B

[WM] RFC925 Hostname = ESP32-FSWebServerDRD
[WM] setAPStaticIPConfig
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
Stored: SSID = HueNet2, Pass = 12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
Got stored Credentials. Timeout 120s for Config Portal
SPIFFS Flag read = 0xd0d04321
No doubleResetDetected
Saving config file...
Saving config file OK
[WM] LoadWiFiCfgFile
[WM] OK
[WM] * Add SSID =  HueNet1 , PW =  12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
ConnectMultiWiFi in setup
[WM] ConnectMultiWiFi with :
[WM] * Flash-stored Router_SSID =  HueNet2 , Router_Pass =  12345678
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  1
[WM] SSID: HueNet1 ,RSSI= -27
[WM] Channel: 2 ,IP address: 192.168.2.232
After waiting 5 secs more in setup(), connection result is connected. Local IP: 192.168.2.232
HTTP server started @ 192.168.2.232
Open http://esp32-fs-browser.local/edit to see the file browser
[WM] freeing allocated params!
Stop doubleResetDetecting
Saving config file...
Saving config file OK

WiFi lost. Call connectMultiWiFi in loop
[WM] ConnectMultiWiFi with :
[WM] * Flash-stored Router_SSID =  HueNet2 , Router_Pass =  12345678
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  3
[WM] SSID: HueNet2 ,RSSI= -59
[WM] Channel: 4 ,IP address: 192.168.2.232
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: khoih-prog on Nov 25, 2020, 01:59 am
Just add a section HOWTO Add Dynamic Parameters (https://github.com/khoih-prog/ESP_WiFiManager#howto-add-dynamic-parameters).

There are step-by-step instructions to guide you through these following complicated steps

Code: [Select]
1. Determine the variables to be configured via Config Portal (CP)

2. Initialize the variables to prepare for Config Portal (CP)

3. Add the variables to Config Portal (CP)
 3.1 addParameter() function Prototype
 3.2 Code to add variables to CP

4. Save the variables configured in Config Portal (CP)
 4.1 Getting variables' data from CP

5. Write to FS (SPIFFS, LittleFS, etc.) using JSON format
 5.1 Create a DynamicJsonDocument Object
 5.2 Fill the DynamicJsonDocument Object with data got from Config Portal
 5.3 Open file to write the Jsonified data
 5.4 Write the Jsonified data to CONFIG_FILE
 5.5 Close CONFIG_FILE to flush and save the data

6. Read from FS using JSON format
 6.1 Open CONFIG_FILE to read
 6.2 Open CONFIG_FILE to read
 6.3 Populate the just-read Jsonified data into the DynamicJsonDocument json object
 6.4 Parse the Jsonified data from the DynamicJsonDocument json object to store into corresponding parameters
 6.5 Then what to do now


to help you use successfully the Dynamic Parameters in Config Portal
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: rwanrooy on Nov 26, 2020, 11:58 pm
This is a very nice library!

Is there a way to enter a static ip address in the portal? I want users to choose between dhcp or static in the portal.
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: khoih-prog on Nov 27, 2020, 12:16 am
Thanks for your interests in the library.


Quote
Is there a way to enter a static ip address in the portal? I want users to choose between dhcp or static in the portal.
It's currently supported and suggested that you go through all the Examples (https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples) to familiarize yourself and take advantage of all the provided features .

Please have a look at 

How It Works (https://github.com/khoih-prog/ESP_WiFiManager#how-it-works)

especially these parts:

4. Using STA-mode DHCP, but permit to change to static IP and display in Config Portal (https://github.com/khoih-prog/ESP_WiFiManager#4-using-sta-mode-dhcp-but-permit-to-change-to-static-ip-and-display-in-config-portal)
5. Using STA-mode StaticIP, and be able to change to DHCP IP and display in Config Portal (https://github.com/khoih-prog/ESP_WiFiManager#how-it-workshttps://github.com/khoih-prog/ESP_WiFiManager#5-using-sta-mode-staticip-and-be-able-to-change-to-dhcp-ip-and-display-in-config-portal)
6. Using STA-mode StaticIP and configurable DNS, and be able to change to DHCP IP and display in Config Portal (https://github.com/khoih-prog/ESP_WiFiManager#6-using-sta-mode-staticip-and-configurable-dns-and-be-able-to-change-to-dhcp-ip-and-display-in-config-portal)
7. Using STA-mode StaticIP and auto DNS, and be able to change to DHCP IP and display in Config Portal (https://github.com/khoih-prog/ESP_WiFiManager#7-using-sta-mode-staticip-and-auto-dns-and-be-able-to-change-to-dhcp-ip-and-display-in-config-portal)
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: rwanrooy on Nov 27, 2020, 12:22 am
Thank you for your quick reply.

I looked at the examples and found the code. I can enter a fixed ip in the sketch and show it in the portal but I am not able to set an ip in the portal itself. What I want is that the esp boots using dhcp as default and that it is possible to enter a fixed ip in the portal, not in the sketch. Am I missing something in the examples?
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: khoih-prog on Nov 27, 2020, 12:44 am
I suggested you to use this ConfigOnDoubleReset (https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigOnDoubleReset) 

and follow:

4. Using STA-mode DHCP, but permit to change to static IP and display in Config Portal (https://github.com/khoih-prog/ESP_WiFiManager#4-using-sta-mode-dhcp-but-permit-to-change-to-static-ip-and-display-in-config-portal)

You have to spend time playing with the examples to get the experience. No easy way. I'm sorry I can't help any further with the basic usage.

The Terminal output

Code: [Select]

Starting ConfigOnDoubleReset with DoubleResetDetect using SPIFFS on ESP32_DEV
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to :  Your Access-Control-Allow-Origin
Stored: SSID = HueNet1, Pass = 12345678
[WM] * Add SSID =  HueNet1 , PW =  12345678
Got stored Credentials. Timeout 120s for Config Portal
SPIFFS Flag read = 0xd0d04321
No doubleResetDetected
Saving config file...
Saving config file OK
[WM] LoadWiFiCfgFile
[WM] OK
[WM] * Add SSID =  HueNet1 , PW =  12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
ConnectMultiWiFi in setup
[WM] ConnectMultiWiFi with :
[WM] * Flash-stored Router_SSID =  HueNet1 , Router_Pass =  12345678
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  1
[WM] SSID: HueNet1 ,RSSI= -38
[WM] Channel: 2 ,IP address: 192.168.2.101
After waiting 4.42 secs more in setup(), connection result is connected. Local IP: 192.168.2.101
[WM] freeing allocated params!
HStop doubleResetDetecting
Saving config file...
Saving config file OK



==========================
DoubleReset Detected Here
==========================

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
=====================
Static IP now
================
Starting ConfigOnDoubleReset with DoubleResetDetect using SPIFFS on ESP32_DEV
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to :  Your Access-Control-Allow-Origin
Stored: SSID = HueNet1, Pass = 12345678
[WM] * Add SSID =  HueNet1 , PW =  12345678
Got stored Credentials. Timeout 120s for Config Portal
SPIFFS Flag read = 0xd0d01234
doubleResetDetected
Saving config file...
Saving config file OK
Open Config Portal without Timeout: Double Reset Detected
Starting configuration portal.
[WM] WiFi.waitForConnectResult Done
[WM] SET AP
[WM] Configuring AP SSID = ESP_9ABF498
[WM] AP PWD = your_password
[WM] AP Channel = 1
[WM] AP IP address = 192.168.4.1
[WM] HTTP server started
[WM] ESP_WiFiManager::startConfigPortal : Enter loop
[WM] Connecting to new AP
[WM] Custom STA IP/GW/Subnet
[WM] DNS1 and DNS2 set
[WM] setWifiStaticIP IP = 192.168.2.235   <=== Static IP got from Config Portal
[WM] Connect to previous WiFi using new IP parameters
[WM] Connected after waiting (s) : 1.40
[WM] Local ip = 192.168.2.235
[WM] Connection result:  WL_CONNECTED
WiFi connected...yeey :)
[WM] SaveWiFiCfgFile
[WM] OK
After waiting 0.00 secs more in setup(), connection result is connected. Local IP: 192.168.2.235
[WM] freeing allocated params!
HHHHHHH
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: rwanrooy on Nov 27, 2020, 04:00 pm
Thanks for your answer. I configured the sketch as you said and I am able to change the ip address in the portal. I notice that the ip address is changed after I save the settings. I am able to ping the configured ip so that works perfect. After a reboot of the esp the configured address is lost. Is there a way to store the configured ip in spiffs?
Title: Re: ESP_WiFiManager for ESP32 and ESP8266 supporting MultiWiFi
Post by: khoih-prog on Nov 28, 2020, 04:13 am
You're very welcome. I'm now happy that you independently found your way and met the current so-called bug of one example, mentioned in the following issue

ESP32 static IP not saved after restarting the device (https://github.com/khoih-prog/ESPAsync_WiFiManager/issues/19)

This can be fixed easily by writing the Static IP settings, got from CP, into EEPROM/SPIFFS/LittleFS, and retrieving / using them after rebooting.

The steps to write to/read from SPIFFS/LittleFS are described in details here

HOWTO Add Dynamic Parameters (https://github.com/khoih-prog/ESP_WiFiManager#howto-add-dynamic-parameters)

If urgently needed and possible, you can rewrite the example. Then make a Pull-Request (PR) and contribute back to the Community.
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi, LittleFS
Post by: khoih-prog on Dec 04, 2020, 05:06 am
Releases v1.3.0

1. Add LittleFS support to ESP32-related examples to use LittleFS_esp32 Library (https://github.com/lorol/LITTLEFS)
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.
2. Fix bug /close does not close the config portal (https://github.com/khoih-prog/ESPAsync_WiFiManager/issues/16)
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS
Post by: rwanrooy on Jan 19, 2021, 10:33 pm
I saw the sketches were updated with the static ip configuration in the portal. I'm using the https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigOnSwitchFS_MQTT_Ptr sketch now which saves the static ip to FS. I am only able to do this the first time. When I press the button, the portal comes up and when I configure the static ip, it does not remember the new ip.

I then tried the https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigPortalParamsOnSwitch so without MQTT and that does save the ip after the initial config is done and reconfigured with the button.

I have searched all day but didn't find the code which saves the ip after the initial setup. Can you give me a hint or correct the MQTT sketch so that I can alter the static ip after the initial config is done?
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS
Post by: khoih-prog on Jan 19, 2021, 11:26 pm
You have to use the latest releases (v1.4.1+) where the bug has been fixed

Releases v1.4.2

1. Fix examples' bug not using saved WiFi Credentials after losing all WiFi connections.
2. Fix compiler warnings.

Major Releases v1.4.1

1. Fix staticIP not saved in examples. Check ESP32 static IP not saved after restarting the device (https://github.com/khoih-prog/ESPAsync_WiFiManager/issues/19)
2. Add structures and functions to handle AP and STA IPs.
3. Add complex examples
4. Add simple minimal examples
5. Fix bug.
6. Fix compiler warnings.
7. Modify Version String
8. Add Table of Contents
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS
Post by: rwanrooy on Jan 19, 2021, 11:54 pm
I am using version 1.4.2 and the ip is saved at the initial setup. when you do it again it doesn't save the new ip address with the https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigOnSwitchFS_MQTT_Ptr example. with the https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigPortalParamsOnSwitch it is working ok. so there has to be a difference but I can't find it
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS
Post by: khoih-prog on Jan 20, 2021, 12:20 am
I've just spent some time to re-test and am sure the example is working OK as intended. It's possibly you're using the different, not-yet-fixed or modified version of it.

If you experience something different, it's a good opportunity for you to read the code / examples to get deeper understanding of the library.

I'm sorry I won't spend more time on the same issue until convincing proof of bug is provided.

Hereafter are the debug terminal outputs to show you it's currently working OK

1. Start with static IP 192.168.2.188

Code: [Select]

Starting ConfigOnSwichFS_MQTT_Ptr using LittleFS on ESP8266_NODEMCU
ESP_WiFiManager v1.4.2
{"AIO_SERVER_Label":"io.adafruit.com","AIO_SERVERPORT_Label":"1883","AIO_USERNAME_Label":"user_name","AIO_KEY_Label":"aio_key"}
Config File successfully parsed
{"AIO_SERVER_Label":"io.adafruit.com","AIO_SERVERPORT_Label":"1883","AIO_USERNAME_Label":"user_name","AIO_KEY_Label":"aio_key"}
Config File successfully parsed
[WM] LoadWiFiCfgFile
[WM] OK
[WM] stationIP = 192.168.2.188 , gatewayIP = 192.168.2.1    <=== Previously set @ 192.168.2.188
[WM] netMask = 255.255.255.0
[WM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8
[WM] * Add SSID =  HueNet1 , PW =  12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
ConnectMultiWiFi in setup
[WM] ConnectMultiWiFi with :
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  1
[WM] SSID: HueNet1 ,RSSI= -45
[WM] Channel: 2 ,IP address: 192.168.2.188
W
Creating new WiFi client object : OK
Creating new MQTT object : OK
AIO_SERVER = io.adafruit.com, AIO_SERVERPORT = 1883
AIO_USERNAME = user_name, AIO_KEY = aio_key
Creating new MQTT_Pub_Topic,  Temperature = user_name/feeds/Temperature
Creating new Temperature object : OK
Temperature MQTT_Pub_Topic = user_name/feeds/Temperature
Connecting to WiFi MQTT (3 attempts)...
WiFi MQTT connection successful!
TWWWW WTW
Button clicked!


2. SW pressed  and entering CP, then input new static IP 192.168.2.189

Code: [Select]

Config Portal requested.
[WM] RFC925 Hostname = ConfigOnSwitchFS-MQTT
Opening Configuration Portal. Got stored Credentials. Timeout 120s
[WM] Adding parameter AIO_SERVER_Label
[WM] Adding parameter AIO_SERVERPORT_Label
[WM] Adding parameter AIO_USERNAME_Label
[WM] Adding parameter AIO_KEY_Label
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
[WM] Set CORS Header to :  Your Access-Control-Allow-Origin
[WM] WiFi.waitForConnectResult Done
[WM] SET AP_STA
[WM] Configuring AP SSID = ESP_705385
[WM] AP PWD = your_password
[WM] AP Channel = 11
[WM] AP IP address = 192.168.4.1
[WM] HTTP server started
[WM] ESP_WiFiManager::startConfigPortal : Enter loop
[WM] Connecting to new AP
[WM] Already connected. Bailing out.
Connected...yeey :)
Local IP: 192.168.2.188
[WM] * Add SSID =  HueNet1 , PW =  12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
[WM] getSTAStaticIPConfig
[WM] stationIP = 192.168.2.189 , gatewayIP = 192.168.2.1  <==== New staticIP @ 192.168.2.189
[WM] netMask = 255.255.255.0
[WM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8
[WM] SaveWiFiCfgFile
[WM] OK
Saving Config File
{
  "AIO_SERVER_Label": "io.adafruit.com",
  "AIO_SERVERPORT_Label": "1883",
  "AIO_USERNAME_Label": "user_name",
  "AIO_KEY_Label": "aio_key"
}
Config File successfully saved
Deleting old MQTT object
Deleting old Temperature object
Creating new MQTT object : OK
AIO_SERVER = io.adafruit.com, AIO_SERVERPORT = 1883
AIO_USERNAME = user_name, AIO_KEY = aio_key
Creating new MQTT_Pub_Topic,  Temperature = user_name/feeds/Temperature
Creating new Temperature object : OK
Temperature MQTT_Pub_Topic = user_name/feeds/Temperature
[WM] freeing allocated params!
WTW


3. After reboot, still static IP 192.168.2.189

Code: [Select]

Starting ConfigOnSwichFS_MQTT_Ptr using LittleFS on ESP8266_NODEMCU
ESP_WiFiManager v1.4.2
{"AIO_SERVER_Label":"io.adafruit.com","AIO_SERVERPORT_Label":"1883","AIO_USERNAME_Label":"user_name","AIO_KEY_Label":"aio_key"}
Config File successfully parsed
{"AIO_SERVER_Label":"io.adafruit.com","AIO_SERVERPORT_Label":"1883","AIO_USERNAME_Label":"user_name","AIO_KEY_Label":"aio_key"}
Config File successfully parsed
[WM] LoadWiFiCfgFile
[WM] OK
[WM] stationIP = 192.168.2.189 , gatewayIP = 192.168.2.1
[WM] netMask = 255.255.255.0
[WM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8
[WM] * Add SSID =  HueNet1 , PW =  12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
ConnectMultiWiFi in setup
[WM] ConnectMultiWiFi with :
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  1
[WM] SSID: HueNet1 ,RSSI= -40
[WM] Channel: 2 ,IP address: 192.168.2.189     <==== New staticIP @ 192.168.2.189 after reset
W
Creating new WiFi client object : OK
Creating new MQTT object : OK
AIO_SERVER = io.adafruit.com, AIO_SERVERPORT = 1883
AIO_USERNAME = user_name, AIO_KEY = aio_key
Creating new MQTT_Pub_Topic,  Temperature = user_name/feeds/Temperature
Creating new Temperature object : OK
Temperature MQTT_Pub_Topic = user_name/feeds/Temperature
Connecting to WiFi MQTT (3 attempts)...
WiFi MQTT connection successful!
TWWWW WTWWWW WW
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS
Post by: rwanrooy on Jan 23, 2021, 12:12 pm
Thanks for your answer and testing. I did some testing too. When a static ip of dhcp address is already configured/used it is nessecary to enter the wifi credentials when setting a static ip address. When you don't enter the wifi credentials the static ip is not stored.

So I have another question. There are two SSID credential forms displayed on the portal. When I set
Code: [Select]
#define NUM_WIFI_CREDENTIALS      2
to
Code: [Select]
#define NUM_WIFI_CREDENTIALS      1
the config portal does not change to display only one ssid configuration form. Is it possible to make this dynamic or just remove SSID1 from the portal? Most people don't use two ssid's and reconfigure the esp when they make changes to their wifi network.

I also changed the following in the example
Code: [Select]
IPAddress stationIP   = IPAddress(192, 168, 2, 232);
to
Code: [Select]
IPAddress stationIP   = IPAddress(0, 0, 0, 0);

This changes the behaviour when the 0.0.0.0 address is not altered, it stays at dhcp. When changed it is set to static. This makes it easier for people to see if the esp is set to dhcp or static.

Your help would be really appreciated.
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS
Post by: khoih-prog on Jan 23, 2021, 03:39 pm
I think you'd better check the closed issues at Issues of ESP_WiFiManager (https://github.com/khoih-prog/ESP_WiFiManager/issues) first. Then post any new issue there from now on.
Title: Re: ESP_WiFiManager for ESP32/ESP8266 supporting MultiWiFi/LittleFS and ESP32_S2
Post by: khoih-prog on Feb 13, 2021, 07:17 am
Releases v1.5.0

1. Add support to ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, ESP32S2 Dev Module, UM FeatherS2, UM ProS2, microS2, etc.)
2. Add Instructions to install ESP32-S2 core (https://github.com/khoih-prog/ESP_WiFiManager/#howto-install-esp32-s2-core-for-esp32-s2-saola-ai-thinker-esp-12k-boards-into-arduino-ide)

Releases v1.4.3

1. Fix examples' bug not saving Static IP in certain cases.
2. Add feature to warn if using examples with old library versions