TinyMqtt icon indicating copy to clipboard operation
TinyMqtt copied to clipboard

Incomplete decoding of topic names

Open dg6nee opened this issue 2 years ago • 2 comments

I have a device with a MQTT broker and a local client (just as in the example code). On the device side I publish two topics with similar names, where the name of the second is included in the name of the first, as this: a) sensor/temperature (a floating point value, encoded as string, e.g. "19.8") b) sensor/temperature_raw (a raw decimal value, e.g. 19384)

When I query the value of "temperature_raw" from a remote machine (e.g. by using mosquitto_sub) it seems that the broker does not properly evaluate the topic name, as it returns the value of "temperature" instead.

This bug is 100% reproducible and can be easily worked around by renaming the topic, in my case it started to work as expected after I renamed the topic to "sensor/raw_temperature".

However, this may be problematic when using nested topics, for example "/actor/xxx" for a read-only value and "/actor/xxx/set" for writing.

dg6nee avatar Mar 17 '22 16:03 dg6nee

update: reason is the incomplete string compare in StringIndexer::strToIndex. The code should not only do a strncmp - it must also check the length of the strings to be equal!

Otherwise you will get wrong matches. Just an other example:

/blabla/sensor/window_open /blabla/sensor/wind

-> guess which one will be found if calling the function with /blabla/sensor/wind !

dg6nee avatar Aug 04 '22 11:08 dg6nee

see pull request #36

dg6nee avatar Aug 04 '22 14:08 dg6nee

Fixed with this commit

hsaturn avatar Oct 30 '22 20:10 hsaturn

Released in version 0.9.3

hsaturn avatar Oct 30 '22 20:10 hsaturn