Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck at 'Scheduling reconnect for 0.5 seconds from now' #85

Open
unexpectedness opened this issue May 15, 2024 · 0 comments
Open

Stuck at 'Scheduling reconnect for 0.5 seconds from now' #85

unexpectedness opened this issue May 15, 2024 · 0 comments

Comments

@unexpectedness
Copy link

unexpectedness commented May 15, 2024

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

ESP32

What do ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant