Pubsubclient: Issues when using ESP's deep sleep

Created on 12 Dec 2019  Β·  2Comments  Β·  Source: knolleary/pubsubclient

Hi.

I've been using your library lately for an IoT project, and ran into some weird problems. It took me a while to figure it out, but here's the thing: if the ESP will go into deepSleep, you MUST use PubSubClient::disconnect before going to deepSleep, or published message may never arrive.

I don't have any clue about what's going on as I didn't dive into PubSubClient's code.

Most helpful comment

if you just send message before sleeping, let MQTT client work in loop for a little time:

unsigned long int new_millis = millis(); // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠΉ Ρ‚ΠΎΡ‡ΠΊΠΈ отсчСта Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ
  while(millis() - new_millis < 6000) {     
    mqtt.loop();
  }

All 2 comments

if you just send message before sleeping, let MQTT client work in loop for a little time:

unsigned long int new_millis = millis(); // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠΉ Ρ‚ΠΎΡ‡ΠΊΠΈ отсчСта Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ
  while(millis() - new_millis < 6000) {     
    mqtt.loop();
  }

if you just send message before sleeping, let MQTT client work in loop for a little time:

unsigned long int new_millis = millis(); // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠΉ Ρ‚ΠΎΡ‡ΠΊΠΈ отсчСта Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ
  while(millis() - new_millis < 6000) {     
    mqtt.loop();
  }

Though this might work, when using your Arduino on a battery, this is not a good solution as every ms counts

Was this page helpful?
0 / 5 - 0 ratings