MQTT RETAIN messages work a little strangely
-
MQTT RETAIN messages work a little strangely. The first ones always come and are recorded by the mosquito server, but all subsequent messages do not reach and are not recorded by the server .. The RETAIN flag is naturally set.
-
@Clone-Tv what exactly is your issue? Is it with the mosquitto MQTT broker, the MQTT mysensors gateway, or...?
-
Yes, I am using the mosquitto MQTT broker, but the problem is most likely with the mysensors MQTT gateway. On Mosquito, I am able to write a packet with the retained flag from the console, and it works.
-
@Clone-Tv Could you post your sketch, gateway log and which hardware you're using?
E.g. the default MQTT gateways don't set MY_MQTT_CLIENT_PUBLISH_RETAIN, so the stack behaves differently when set (https://github.com/mysensors/MySensors/blob/6c4b8055f729d1582b52068e3e858b77803a18b3/core/MyGatewayTransportMQTTClient.cpp#L129)
-
I do not use signed messages, so I used the Signed flag in the MySensors packet header to implement selective MQTT
retain
state.Gateway is ESP2866 - no specific code.
Code send from client:template<typename T> void reportMsg(const uint8_t & id, const mysensors_data_t & tag, const T & val, const bool retain) { MyMessage msg(id, tag); msg.setSigned(retain); send(msg.set(val), true); }
Lite patch
MyGatewayTransportMQTTClient.cpp
:bool gatewayTransportSend(MyMessage &message) { ... bool retain = message.getSigned(); message.setSigned(false); ....