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.
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
Most helpful comment
if you just send message before sleeping, let MQTT client work in loop for a little time: