TinyMqtt
TinyMqtt copied to clipboard
Incomplete decoding of topic names
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.
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 !
see pull request #36
Fixed with this commit
Released in version 0.9.3