glauche.de - Michael's Blog

Example domain paragraphs

I saw a lot of posts about sending mqtt messages from an esp32/esp8266 with deep sleep between the sending cycles. This works fairly well as long as you keep a some time for the message to transmit before the deep sleep cycle. However, when you want to receive messages things get more interesting. If you just sent the callback on the esp32 to receive messages during the wake up time the messages almost never got through. This was a bit puzzeling for me at first, as reliability was one of the main reasons wh

My first thoughts were that the messages got lost because the esp went to sleep without proper disconnecting and the mosquitto server was trying to send with no response. So I did try sending them in QoS 1 instead (and trying to implement a more graceful shutdown before sleep on the esp side), but the effects were exactly the same.

But then I thought back about queues and topics, and that MQTT topics won’t work like queues. That was exactly the point. MQTT Topics are not retained on default. That means the mosquitto server is only sending the message to the subscribed clients when a message arrives. If the client is sleeping/unsubscribed the message will be lost.