hsaturn / TinyMqtt

ESP 8266 / 32 / WROOM Small footprint Mqtt Broker and Client
GNU General Public License v3.0
183 stars 40 forks source link

Incomplete decoding of topic names #30

Closed dg6nee closed 1 year ago

dg6nee commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

see pull request #36

hsaturn commented 1 year ago

Fixed with this commit

hsaturn commented 1 year ago

Released in version 0.9.3