|Detect no retained message on subscribe [message #1787503]
||Sun, 27 May 2018 14:18
| Peter Wensing
Registered: May 2018
When I subscribe to a topic (Paho Java client), I want to initialize a hardware device from a retained MQTT message, if there is one on that topic.|
Otherwise, I want to initialize it to a default value.
But I don't want to first initialize it to the default value and let it be changed, if the retained message arrives, because then my lights might be switched off an on again unnecessarily (which I want to avoid).
If there is a retained message, my provided callback method will be called and I can retrieve and use the message. In this case, everything is fine.
But if there is no retained message, the callback just won't be called and I seemingly can never be absolutely sure, whether there is no retained message or it just has not been processed yet.
The callback seems to always happen only, after the subscribe() method has returned.
So even the successful completion of that method without the callback being called, does not mean, that there is no retained message.
Currently, I use a timeout to decide, whether a retained message exists, but in my humble opinion there should be a better way.
I tried a number of things to find out, if there is such a way, but I couldn't find one.
Powered by FUDForum
. Page generated in 0.01680 seconds