[GH-ISSUE #948] WifiManager hangs setup after successful configuration save #803

Open
opened 2026-02-28 01:27:07 +03:00 by kerem · 5 comments
Owner

Originally created by @afagard on GitHub (Sep 24, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/948

Basic Infos

Hardware

WiFimanager Branch/Release:

  • Master
  • Development

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25
Lolin D1 mini pro

ESP Core Version: 2.4.0, staging

  • 2.3.0
  • 2.4.0
  • staging (master/dev)

Description

On first run, with clear memory, the device starts and I can go to the configuration portal to modify the wifi credentials and save it. On save, and over serial, the device immediately spits out:

*WM: WiFi save
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
(few seconds later)
connected with XXXX, channel 1
dhcp client start...
ip:10.0.0.236,mask:255.255.255.0,gw:10.0.0.1
*WM: Connection result:
*WM: 3
station: c0:ee:fb🇩🇪08:61 leave, AID = 1
rm 1
bcn 0
del if1
pm open,type:2 0
mode : sta(84:0d:8e:8f:4e:2e)

And stops. Then, after about a minute and a half, my own setup begins and everything goes on normally.

pm open,type:2 0
mode : sta(84:0d:8e:8f:4e:2e)
[CONFIG] There was an error opening config.json for reading. This is normal on first-run startup.
[CONFIG] Failed to read file. Using default configuration. This is normal on first-run startup.
[WIFI] mDNS responder started
[WIFI] TCP server started
[DS] Locating Dallas temperature sensors...[DS] Found 2 sensor(s).
[DS] Added temp sensor.
[DS] Added temp sensor.
[BME] Locating BME280...
[BME] Found sensor.
[IRRIGATION] Pump off.
[IRRIGATION] Pump on.
[IRRIGATION] Pump off.
[IRRIGATION] Pump on.
*WM: freeing allocated params!
[RAINFALL] Attempting to save rainfall data...
[RAINFALL] rainfall.txt does not exist. At startup this is expected.
[RAINFALL] File was written.
[IRRIGATION] Running routine...
[RAINFALL] Tip count from memory: 0

What exactly is happening during this timeperiod? Is this normal? Because as the serial prints suggest, the device has successfully connected after the credentials were correctly entered then the delay. Without wifimanager, and using hard-coded configuration variables, there is no delay.

Please note: after initial configuration, if I restart the device everything happens within 10-15 seconds:

connected with 113OceanPines, channel 1
dhcp client start...
ip:10.0.0.236,mask:255.255.255.0,gw:10.0.0.1
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 10.0.0.236
[CONFIG] There was an error opening config.json for reading. This is normal on first-run startup.
[CONFIG] Failed to read file. Using default configuration. This is normal on first-run startup.
[WIFI] mDNS responder started
[WIFI] TCP server started
[DS] Locating Dallas temperature sensors...[DS] Found 2 sensor(s).
[DS] Added temp sensor.
[DS] Added temp sensor.
[BME] Locating BME280...
[BME] Found sensor.
[IRRIGATION] Pump off.
[IRRIGATION] Pump on.
[IRRIGATION] Pump off.
[IRRIGATION] Pump on.
*WM: freeing allocated params!
[RAINFALL] Attempting to save rainfall data...
[RAINFALL] Tip count from memory: 0
[RAINFALL] File was written.
[IRRIGATION] Running routine...
[RAINFALL] Tip count from memory: 0
pm open,type:2 0

Settings in IDE

Module: NodeMcu, Wemos D1

Additional libraries:

Sketch

My sketch is about 1000 lines:

https://pastebin.com/Jn6eZq43

But this is my basic setup:

void setup(void)
{
  Serial.begin(115200);
  pinMode(WIFI_STATUS_LED, OUTPUT);
  pinMode(ERROR_LED, OUTPUT);
  pinMode(PUMP_RELAY, OUTPUT);
  digitalWrite(PUMP_RELAY, LOW);
  digitalWrite(WIFI_STATUS_LED, LOW);
  digitalWrite(ERROR_LED, LOW); // inverse for some reason...
  WiFiManager wifiManager;
  wifiManager.autoConnect("IrrigationStationWifiSetup", "XXXX");
  wifiManager.setDebugOutput(true);
  //wifiManager.setSTAStaticIPConfig(staticIP, gateway, subnet);
  if (!SPIFFS.begin()) {
    enableErrorLed();
    Serial.println("Failed to mount the file system!");
    while (1);
  }
  resetRtc();
  createErrorsArray();
  getConfig(config); // first thing to serial print see: [CONFIG] in output above
  deviceStarted = millis();
  serverDefs();
  //initWifi();
  initWifi();
  initRtc(); // must be called after wifi
  initDs();
  initBme();
  initRg();
  relayTest();
  runner.init();
  runner.addTask(t1);
  runner.addTask(t2);
  t1.enable();
  t2.enable();
  ota();
}

void initWifi() {
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  // start mdns
  if (!MDNS.begin("station")) {
    Serial.println("[WIFI] Error setting up MDNS responder!");
    while (1) {
      digitalWrite(WIFI_STATUS_LED, HIGH);
      delay(500);
      digitalWrite(WIFI_STATUS_LED, LOW);
      delay(500);
    }
  }
  Serial.println("[WIFI] mDNS responder started");
  // Start TCP (HTTP) server
  server.begin();
  Serial.println("[WIFI] TCP server started");
  // Add service to MDNS-SD
  MDNS.addService("http", "tcp", 80);
  digitalWrite(WIFI_STATUS_LED, HIGH); // signify connection started
}

Libraries:

#include <OneWire.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <RTClib.h>
#include <ArduinoJson.h>
#include <ACS712.h>
#include <ESP8266WebServer.h>
#include <FS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <WiFiManager.h>
#include <DNSServer.h>
Originally created by @afagard on GitHub (Sep 24, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/948 ### Basic Infos #### Hardware **WiFimanager Branch/Release:** - [ ] Master - [x] Development **Esp8266/Esp32:** - [x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** Lolin D1 mini pro **ESP Core Version: 2.4.0, staging** - [ ] 2.3.0 - [ ] 2.4.0 - [x] staging (master/dev) ### Description On first run, with clear memory, the device starts and I can go to the configuration portal to modify the wifi credentials and save it. On save, and over serial, the device immediately spits out: > *WM: WiFi save > *WM: Sent wifi save page > *WM: Connecting to new AP > *WM: Connecting as wifi client... > (few seconds later) > connected with XXXX, channel 1 > dhcp client start... > ip:10.0.0.236,mask:255.255.255.0,gw:10.0.0.1 > *WM: Connection result: > *WM: 3 > station: c0:ee:fb:de:08:61 leave, AID = 1 > rm 1 > bcn 0 > del if1 > pm open,type:2 0 > mode : sta(84:0d:8e:8f:4e:2e) And stops. Then, after about a minute and a half, my own setup begins and everything goes on normally. > pm open,type:2 0 > mode : sta(84:0d:8e:8f:4e:2e) > [CONFIG] There was an error opening config.json for reading. This is normal on first-run startup. > [CONFIG] Failed to read file. Using default configuration. This is normal on first-run startup. > [WIFI] mDNS responder started > [WIFI] TCP server started > [DS] Locating Dallas temperature sensors...[DS] Found 2 sensor(s). > [DS] Added temp sensor. > [DS] Added temp sensor. > [BME] Locating BME280... > [BME] Found sensor. > [IRRIGATION] Pump off. > [IRRIGATION] Pump on. > [IRRIGATION] Pump off. > [IRRIGATION] Pump on. > *WM: freeing allocated params! > [RAINFALL] Attempting to save rainfall data... > [RAINFALL] rainfall.txt does not exist. At startup this is expected. > [RAINFALL] File was written. > [IRRIGATION] Running routine... > [RAINFALL] Tip count from memory: 0 What exactly is happening during this timeperiod? Is this normal? Because as the serial prints suggest, the device has successfully connected after the credentials were correctly entered then the delay. Without wifimanager, and using hard-coded configuration variables, there is no delay. Please note: after initial configuration, if I restart the device everything happens within 10-15 seconds: > connected with 113OceanPines, channel 1 > dhcp client start... > ip:10.0.0.236,mask:255.255.255.0,gw:10.0.0.1 > *WM: Connection result: > *WM: 3 > *WM: IP Address: > *WM: 10.0.0.236 > [CONFIG] There was an error opening config.json for reading. This is normal on first-run startup. > [CONFIG] Failed to read file. Using default configuration. This is normal on first-run startup. > [WIFI] mDNS responder started > [WIFI] TCP server started > [DS] Locating Dallas temperature sensors...[DS] Found 2 sensor(s). > [DS] Added temp sensor. > [DS] Added temp sensor. > [BME] Locating BME280... > [BME] Found sensor. > [IRRIGATION] Pump off. > [IRRIGATION] Pump on. > [IRRIGATION] Pump off. > [IRRIGATION] Pump on. > *WM: freeing allocated params! > [RAINFALL] Attempting to save rainfall data... > [RAINFALL] Tip count from memory: 0 > [RAINFALL] File was written. > [IRRIGATION] Running routine... > [RAINFALL] Tip count from memory: 0 > pm open,type:2 0 ### Settings in IDE Module: NodeMcu, Wemos D1 Additional libraries: ### Sketch My sketch is about 1000 lines: https://pastebin.com/Jn6eZq43 But this is my basic setup: ```C++ void setup(void) { Serial.begin(115200); pinMode(WIFI_STATUS_LED, OUTPUT); pinMode(ERROR_LED, OUTPUT); pinMode(PUMP_RELAY, OUTPUT); digitalWrite(PUMP_RELAY, LOW); digitalWrite(WIFI_STATUS_LED, LOW); digitalWrite(ERROR_LED, LOW); // inverse for some reason... WiFiManager wifiManager; wifiManager.autoConnect("IrrigationStationWifiSetup", "XXXX"); wifiManager.setDebugOutput(true); //wifiManager.setSTAStaticIPConfig(staticIP, gateway, subnet); if (!SPIFFS.begin()) { enableErrorLed(); Serial.println("Failed to mount the file system!"); while (1); } resetRtc(); createErrorsArray(); getConfig(config); // first thing to serial print see: [CONFIG] in output above deviceStarted = millis(); serverDefs(); //initWifi(); initWifi(); initRtc(); // must be called after wifi initDs(); initBme(); initRg(); relayTest(); runner.init(); runner.addTask(t1); runner.addTask(t2); t1.enable(); t2.enable(); ota(); } void initWifi() { WiFi.persistent(false); WiFi.mode(WIFI_STA); // start mdns if (!MDNS.begin("station")) { Serial.println("[WIFI] Error setting up MDNS responder!"); while (1) { digitalWrite(WIFI_STATUS_LED, HIGH); delay(500); digitalWrite(WIFI_STATUS_LED, LOW); delay(500); } } Serial.println("[WIFI] mDNS responder started"); // Start TCP (HTTP) server server.begin(); Serial.println("[WIFI] TCP server started"); // Add service to MDNS-SD MDNS.addService("http", "tcp", 80); digitalWrite(WIFI_STATUS_LED, HIGH); // signify connection started } ``` Libraries: ``` #include <OneWire.h> #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #include <DallasTemperature.h> #include <ESP8266WiFi.h> #include <ESP8266mDNS.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> #include <RTClib.h> #include <ArduinoJson.h> #include <ACS712.h> #include <ESP8266WebServer.h> #include <FS.h> #include <WiFiUdp.h> #include <ArduinoOTA.h> #include <WiFiManager.h> #include <DNSServer.h> ```
Author
Owner

@ermaya commented on GitHub (Oct 5, 2019):

Have you read the first line of the AutoConnectWithFSParameters example?
Maybe it helps.
#include <FS.h> //this needs to be first, or it all crashes and burns...

<!-- gh-comment-id:538668907 --> @ermaya commented on GitHub (Oct 5, 2019): Have you read the first line of the AutoConnectWithFSParameters example? Maybe it helps. #include <FS.h> //this needs to be first, or it all crashes and burns...
Author
Owner

@afagard commented on GitHub (Oct 13, 2019):

Have you read the first line of the AutoConnectWithFSParameters example?
Maybe it helps.
#include <FS.h> //this needs to be first, or it all crashes and burns...

But it doesn't crash... Will try it out nevertheless.

<!-- gh-comment-id:541396689 --> @afagard commented on GitHub (Oct 13, 2019): > Have you read the first line of the AutoConnectWithFSParameters example? > Maybe it helps. > #include <FS.h> //this needs to be first, or it all crashes and burns... But it doesn't crash... Will try it out nevertheless.
Author
Owner

@tablatronix commented on GitHub (Oct 13, 2019):

I would guess this infinite loop ?
while (1);

<!-- gh-comment-id:541444385 --> @tablatronix commented on GitHub (Oct 13, 2019): I would guess this infinite loop ? while (1);
Author
Owner

@afagard commented on GitHub (Oct 13, 2019):

I would guess this infinite loop ?
while (1);

within the confines of the if it isn't an issue as those things are abs required for everything else to work. in any case, it doesn't crash or print anything to the serial (as you can see all these have nested serial prints) to show those conditionals are triggered.

<!-- gh-comment-id:541457557 --> @afagard commented on GitHub (Oct 13, 2019): > I would guess this infinite loop ? > while (1); within the confines of the if it isn't an issue as those things are abs required for everything else to work. in any case, it doesn't crash or print anything to the serial (as you can see all these have nested serial prints) to show those conditionals are triggered.
Author
Owner

@tablatronix commented on GitHub (Oct 13, 2019):

Those do not look like logs from development branch

<!-- gh-comment-id:541467899 --> @tablatronix commented on GitHub (Oct 13, 2019): Those do not look like logs from development branch
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#803
No description provided.