TinyMqtt icon indicating copy to clipboard operation
TinyMqtt copied to clipboard

multiple retained messages for the same topic

Open real-bombinho opened this issue 1 year ago • 9 comments

TinyMqtt.cpp, line 965:

auto old = retained.find(topic);

does not work as expected. Consequentially I get multiple retained messages for the same topic.

Arduino 2.1.0

Also Retain seems to store the whole Publish message instead of just the message string, which is quite a bit of overkill (memory consuming) at long topics. In accordance to HiveMQ (https://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages/) it should just be the QOS and the message string itself. Would it not be better to just store a reference to the topic? Then duplicates would be far less likely to occur by design and the load on the memory would be lesser. Also the handling of empty messages (delete/ignore) would be much easier.

To replicate the issue, initialise MqttBroker with a value >1 for retained values and send multiple retained messages to the same topic. Connect a client and subscribe to the topic. Now you should see all retained messages popping up, instead of just one.

I have traced the error to the aforementioned line and a debug output there reveals that [topic] is never found. Using a quoted string as argument on the other side does return a found result.

real-bombinho avatar May 09 '23 05:05 real-bombinho