I'm trying to create a battery & solarpowered ESP32 for future use with sensors. It connects to Wifi, MQTT, publishes some readings and status messages and go back to sleep. From time to time (can happen after few sleep cycles and sometimes after few hunderds cycles )I get 2 unexplained behaviours : 1) fail to connect to MQTT at boot, 2) fail to sleep.
Sometimes those behaviours happen simultaneously.
Is there a known issue with deepsleep
and MQTT (using PubSubClient
) ? Most deepsleep example I see online, all code is outside loop()
section - is it mandatory to be like that ?
I don't share code, since it is more a general question.
Guy
EDIT1
most of
callback
was commented out, remaining only printing incoming message.LED was attached to a GPIO, generating a blink on
loop()
- when sleep succeeds - it goes off, when it fails, it stays on. This test shows that when this "error" happens, code actually stop running, but does not enters deep sleep ( power-wise )
if (a+1 == 2) {
, not by commenting the line, because commenting the line would cause the compiler to generate different code ........ do the same with the sleep code – jsotola Jul 11 '20 at 18:37a+1
should create a logic state that wont enter theif
loop to voidpublish
? and the other part to theesp_deep_sleep_start();
? I dont understand why so... by the way- see edit 1/ – Guy . D Jul 11 '20 at 19:14//
to prevent the MQTT publish command from running, then the compiler will produce different code that may not have the sleep problem .... using an if statement makes sure that the compiler does not skip un-executed code ..... do the same kind of a test for the sleep code to see if it is affecting the MQTT code ...... do the tests separately – jsotola Jul 11 '20 at 19:40publish
workaround did not work, even not when I increased MQTT_MAX_PACKET_SIZE to 512 to be sure – Guy . D Jul 11 '20 at 19:47ESP.restart()
every 30 sec was added toloop()
– Guy . D Jul 12 '20 at 6:19