Soft WDT reset with WiFiManager portal

I have a WDT reset issue that seems to be caused by combining the FastLED and WiFiManager libraries. The code I'm attaching is part of a larger project from which I have removed various modules to isolate the error. I understood that the code works correctly until I add the FastLED library (via PlatformIO). Even though the FastLED library is not explicitly included in the code and not used, it causes the error I report below.

EDIT: The hardware I'm using is a Wemos D1 mini (ESP8266).

*wm:resetSettings 
*wm:SETTINGS ERASED 
No saved WiFi credentials. Starting configuration portal...
*wm:StartAP with SSID:  EhiQlock
*wm:AP IP address: 192.168.4.1
Entered config mode
*wm:Starting Web Portal

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

Exception (4):
epc1=0x4020d6b7 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffd80 end: 3fffffd0 offset: 0160
3ffffee0:  40212d30 00000000 00001388 402108ca
3ffffef0:  3ffeecd0 3ffeecd0 3fff092c 402113af  
3fffff00:  3fffff2c 00000000 3fff092c 00000000
3fffff10:  3ffeecd0 3ffeecd0 3ffeebd0 4020a050
3fffff20:  00000000 0104a8c0 00000000 40212ccc
3fffff30:  00000000 40212ccc 0104a8c0 00000035  
3fffff40:  3ffeecd0 3ffeec60 3ffeebd0 00000000
3fffff50:  3ffeecd0 00000001 3ffeebd0 4020a3dd
3fffff60:  3ffeebd0 00000000 00000000 4020e5ec  
3fffff70:  3ffe89b7 fffffffc 3ffeebd0 402022dc
3fffff80:  4020abcc 3ffe89b5 3ffeee4c 3ffeefd8
3fffff90:  3ffe8867 00000000 3ffeee4c 4020b318  
3fffffa0:  3fffdad0 00000000 3ffeebd0 3ffeefd8
3fffffb0:  3fffdad0 00000000 3ffeefac 4020d810
3fffffc0:  feefeffe feefeffe 3fffdab0 40100e85
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v000571a0
~ld

As a new user I can't upload files so I try to paste here my code, there are three files, main.cpp, WiFiModule.cpp e WiFiModule.h.

main.cpp

#include <Arduino.h>

#include "WiFiModule.h"

// Parameters for WiFi module
const char* DEVICE_NAME = "EhiQlock";

/*
 *Functions declaration
 */
void configModeCallback(WiFiManager *myWiFiManager);

// Initialize WiFiManager
WiFiModule wifi(DEVICE_NAME);

void setup()
{
  delay(3000); // some microcontrollers reboot twice
  Serial.begin(115200);

  // Start Wi-Fi connection
  wifi.setup(configModeCallback);
  wifi.connect();
}

void loop()
{
  wifi.run();
  if (wifi.isConnected())
  {
    digitalWrite(LED_BUILTIN, LOW);
  }
  else
  {
    digitalWrite(LED_BUILTIN, HIGH);
  }
}

/*
 *Functions implementation
 */

/**
 * Gets called when WiFiManager enters configuration mode
 * @param myWiFiManager
 */
void configModeCallback(WiFiManager *myWiFiManager)
{
  Serial.println("Entered config mode");
}

WiFiModule.h

#ifndef WIFI_MODULE_H
#define WIFI_MODULE_H

#include <WiFiManager.h>

class WiFiModule
{
public:
    WiFiModule(const char* _deviceName);
    void setup(void (*configModeCallback)(WiFiManager *myWiFiManager));
    void connect();
    void reset();
    bool isConnected();
    void run();

private:
    WiFiManager wm;
    const char* deviceName;
    unsigned long lastConnectionAttempt;
};

#endif // WIFI_MODULE_H

WiFiModule.cpp

#include "WiFiModule.h"

/**
 * @brief Constructor for the WiFiModule class.
 *
 * Initializes the WiFi module with the provided device name.
 */
WiFiModule::WiFiModule(const char* _deviceName) : deviceName(_deviceName), lastConnectionAttempt(0) {}

/**
 * @brief Sets up the WiFi module for station mode and configures the portal.
 */
void WiFiModule::setup(void (*configModeCallback)(WiFiManager* myWiFiManager)) {
    wm.resetSettings();
    WiFi.mode(WIFI_STA);
    WiFi.setAutoReconnect(true);
    wm.setConfigPortalBlocking(true); // Ensure non-blocking mode
    wm.setClass("invert");          // Apply custom CSS class
    wm.setAPCallback(configModeCallback);
}

void WiFiModule::connect() {
    if (!wm.getWiFiIsSaved()) {
        Serial.println("No saved WiFi credentials. Starting configuration portal...");
        wm.startConfigPortal(deviceName);
        return;
    }

    if (WiFi.status() != WL_CONNECTED) {
        WiFi.begin();
        Serial.println("Connecting to WiFi...");
    }
}

/**
 * @brief Resets the WiFi module by clearing saved credentials and settings, then reconnects.
 */
void WiFiModule::reset() {
    Serial.println("Resetting WiFi module...");
    wm.resetSettings();
    connect();
}

/**
 * @brief Checks if the WiFi module is connected to a WiFi network.
 * @return True if connected, false otherwise.
 */
bool WiFiModule::isConnected() {
    return WiFi.status() == WL_CONNECTED;
}

/**
 * @brief Manages WiFi connection state and attempts reconnection if disconnected.
 *
 * This function should be called regularly in the main loop.
 */
void WiFiModule::run() {
    unsigned long currentMillis = millis();

    if (!isConnected() && (currentMillis - lastConnectionAttempt >= 30000)) { // 30-second interval
        Serial.println("Not connected. Attempting to reconnect...");
        connect();
        lastConnectionAttempt = currentMillis;
    }
}
1 Like

Try to add small delay() in your loop.

It didn't work, there is something wrong with the FastLED library.

This is very interesting - I have code that is running on existing hardware and have now encountered the same error after uploading the exact same code to a new device. The only different is that I allowed the IDE to update all boards and libraries.

Have done a little testing by loading the sample 'WiFiManager' code and it all works as expected. Then add the FastLED include top the code (nothing else just the include) - re upload, and the device constantly reboots.

> *wm:AutoConnect
> 
> *wm:No wifi saved, skipping
> 
> *wm:AutoConnect: FAILED for 105 ms
> 
> *wm:StartAP with SSID: ESP_C5FAB9
> 
> *wm:AP IP address: 192.168.4.1
> 
> *wm:Starting Web Portal
> 
> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
> 
> Soft WDT reset
> 
> Exception (4):
> 
> epc1=0x4020ab5d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
> 
> >>>stack>>>

I'm glad to hear you and I'm not the only one with this problem!
What IDE are you using?

Mainly the new one (2.3.4) but have reverted to older one (1.8.16) out of desperation as I still have that installed - and both have the same issue. Have even loaded the example WiFiManager Basic example, compiled and loaded - All OK. Add reference to FastLED.h and it will crash the ESP. At a total loss but cannot understand how I can find no other reference to others having the issue. Still trying all sorts to see where the issue is. Please let me know if you solve the issue.

Is this on ESP8266? Don't have one; could not reproduce on ESP32, with WiFiManager (by tzapu) 2.0.17 and FastLED 3.9.8

To track this down, you can make a local copy of the header. Put it at the top of the sketch

#include <FastLED.h>

Verify, then you can right-click on that and Go to Definition to open the file (it's read-only). Then use the meatball (three dots) menu on the right end of the tabs and choose New Tab. Call it MyLED.h Copy & paste the content.

Swap the header file used

#include "MyLED.h"

and close FastLED.h. On line 55, you'll need to change

#include "fl/force_inline.h"

to

#include <force_inline.h>

Upload again: does this still fail? If so, you can start commenting out stuff from the bottom up to see what makes the difference. You need to maintain the structure of the file, with the #ifdef blocks, especially the main overarching one. It's a big file, over 850 lines.

That's correct - ESP8266 and Libraries are as described.

Have completed this and get the same showing on the serial monitor:

*wm:AutoConnect 
*wm:No wifi saved, skipping 
*wm:AutoConnect: FAILED for  105 ms
*wm:StartAP with SSID:  ESP_C5FAB9
*wm:AP IP address: 192.168.4.1
*wm:Starting Web Portal 

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

Exception (4):
epc1=0x4000dd01 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

Will try to get some time later to start the commenting out like you have recommended.

Thanks for your assistance, much appreciated.

Just confirming that on a NodeMCU (ESP8266) project using FastLED, I get the same soft watchdog timer reset as soon as FastLED (version 3.4.0) is included.

Edit: I tried using the non-blocking API (WiFiManager/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino at master · tzapu/WiFiManager · GitHub), and that doesn't immediately soft watchdog reset, but it doesn't seem to serve the web portal.

Has anyone filed an issue on the FastLED or WiFiManager projects to track?

Following. I am working the same issue on an 8266 Node MCU board with WifiManager and the StripDisplay library. The StripDisplay library uses FastLED. Including StripDisplay.h causes the WifiManager to fail to serve it's HTTP pages. I was getting the Soft WDT reset but something I did made it quit doing that, but still doesn't work.

I am relieved that it is a shared problem, as I couldn't find any traces of a similar issue online. I conducted further tests and encountered the same problem even when using the Blynk library along with FastLED. Therefore, the issue is not specifically related to tzapu's WifiManager.

For anyone interested below is my sample code to reproduce the issue...


// #include <FastLED.h>  // Uncommenting only this to triggers the bug
#include <WiFiManager.h>

WiFiManager wm;

#define NUM_LEDS 5
#define DATA_PIN D4
// CRGB leds[NUM_LEDS];

void setup() { 
//  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); 
//  FastLED.addLeds<SWS2812, DATA_PIN>(leds, NUM_LEDS); 

  Serial.begin(115200);
  wm.resetSettings();

  bool res;
  res = wm.autoConnect(); 

  if(!res) {
      Serial.println("Failed to connect");
      // ESP.restart();
  } 
  else {   
      Serial.println("connected...yeey :)");
  }
}
void loop() {
//  leds[0] = CRGB::White; FastLED.show(); delay(30);
//  leds[0] = CRGB::Black; FastLED.show(); delay(30);
}

I decoded the exception message, here it is if someone can find useful information:

I think this is the problem we are encountering:

Let me know if one of the solutions proposed works for you.

@ehipi, that interrupt is a good thought, but I tried changing NUM_LEDS to 1, and I still receive the cycling soft WDT interrupt resets. If it was a function of the interrupt duration, would making the number of LEDs to be driven low enough prevent it?

Is there a way to explicitly disable that FastLED interrupt while setting up WiFi?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.