Quick disclaimer upfront: I’m pretty new to all of this, so please excuse inaccuracies and lacking knowledge.
I’m running an Mosquitto MQTT Broker on a raspberry pi zero which also has a MQTT client running node red. The other client is an esp32 (running PubSubClient ) which sooner or later will be run on a battery and needs to conserve power. Therefore, it spends a lot of time in deepsleep, waking up based on different parameters, connecting to wifi and MQTT broker, subscribing, sending and receiving MQTT payloads, terminating connections and going back to sleep. Due to deepsleep, all payloads in topics the esp32 is subscribing to are sent with the retain flag set. All of this works splenditly besides of one detail regarding the client subscribtions: As @discobot may say it: The retain flag works too well.
The ESP32 gets the same (retained) payloads (one per topic ofc) from the broker over and over again, once after each wakeup. I guess this is due to the fact it resubscribes every time. I’ve tried different QOS (although PubSub doesn’t support QOS3 subsribtions, due to ram limitations i believe) settings but nothing has helped so far. I even disabled clean sessions (on the client side at connection), but it still happens, probably due to the resubsribtion still happening. I’d like to keep those, if possible, since in case of a server reset I might lose them and don’t see how I can check if the client is still subscribed.
Is there a way to prevent Mosquitto MQTT Broker to resend those messages after each subsribtion? Since the client has the same clientID, I guess it could know that it already got it.
Thank you for your help in advance and have a great day!