ESP8266MQTTMesh
ESP8266MQTTMesh copied to clipboard
Stuck at 'Scheduling reconnect for 0.5 seconds from now'
Versions:
- ESP8266MQTTMesh version: 1.0.4
- AsyncMQTTClient version: 0.8.1
- ESPAsyncTCP version: 1.1.3
- ESP8266 Core version: 4.2.1
Using platformio via vscode on macos. Device: Wemos D1 mini naked (nothing connected to the GPIO ports).
I used to use @simone1999's fork with no problem until today as I needed to flash some additional MQTT mesh nodes, and encountered the following problem:
- Wifi scanning works fine.
- The designated AP is found ('Matched')
- Then the program outputs 'Scheduling reconnect for 0.5 seconds from now' and nothing else happens.
Using the following code on an empty project:
#include <Arduino.h>
#include <Ticker.h>
Ticker schedule;
void toto() { Serial.println("toto");
schedule.once(1.0, toto); }
void setup() {
Serial.begin(74880);
delay(1000);
schedule.once(1.0, toto);
}
void loop() {}
I was able to reproduce the issue: "toto" gets printed only once. Substituting once
with once_scheduled
fixed the problem and "toto" gets printed every second (indeed you are not supposed to do IO in Ticker's callbacks unless you use once_scheduled which will run them in loop()
context.
From Ticker.h:
// callback will be called at following loop() after ticker fires
void once_scheduled(float seconds, callback_function_t callback)
Substituting every call to schedule.once
with schedule.once_scheduled
in ESP8266MQTTMesh.cpp, I was able to finish connecting to the AP and connect to the MQTT broker.
Original lines:
schedule.once(delay, connect_static, this);
schedule.once<void (*)(ESP8266MQTTMesh*), ESP8266MQTTMesh*>(0.001, erase_sector, this);
schedule.once<void (*)(ESP8266MQTTMesh*), ESP8266MQTTMesh*>(0.0, erase_sector, this);
schedule.once<void (*)(ESP8266MQTTMesh*), ESP8266MQTTMesh*> (5000, checkConnectionEstablished_static, this);
Fixed with:
schedule.once_scheduled(delay, [&](){ connect_static(this); });
schedule.once_scheduled(0.001, [&]() { erase_sector(this); });
schedule.once_scheduled(0.0, [&]() { erase_sector(this); });
schedule.once_scheduled(5000, [&](){ checkConnectionEstablished_static(this); });
I was about to file a PR, but realized the ESP32 version of Ticker.h doesn't come with once_sheduled (or Schedule.cpp for that matter).
References:
ESP8266
- https://github.com/esp8266/Arduino/blob/685f2c97ff4b3c76b437a43be86d1dfdf6cb33e3/libraries/Ticker/src/Ticker.h#L123
- https://github.com/esp8266/Arduino/blob/685f2c97ff4b3c76b437a43be86d1dfdf6cb33e3/cores/esp8266/Schedule.cpp#L84
ESP32
- https://github.com/espressif/arduino-esp32/blob/6adeca446b31bec0763b25d94bad1279c94fb6b9/libraries/Ticker/src/Ticker.h#L74
What do ?