ESP32 - DeepSleep loop or not? I'm trying to create a battery &amp; 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 &quot;error&quot; happens, code actually stop running, but does not enters deep sleep ( power-wise )
Is there a known issue with deepsleep and MQTT ?

No. There may be a specific problem with the specific library you are using, but the concept of there being an issue with MQTT in general is nonsense.

Most deepsleep example I see online, all code is outside loop()section - is it mandatory to be like that ?

No, that's just being structured and tidy with your code. Whether code is in loop or in functions that are called by loop makes no difference. It can be a lot easier to manage your code if you structure it in functions rather than dumping it all in loop.