paho.mqtt.embedded-c
paho.mqtt.embedded-c copied to clipboard
isTopicMatched() does not behave correctly for filter that terminates with wildcard /#
This can be observed for example with Google IoT Core, which requires the client to subscribe to the topic /devices/{device-id}/commands/# (see https://cloud.google.com/iot/docs/how-tos/commands#receiving_a_command).
When a message is now sent to the device - but on the topic /devices/{device-id}/commands (without wildcard or any subtopic), the function isTopicMatched() does not correctly identify the match.
A quick and dirty solution:
https://github.com/eclipse/paho.mqtt.embedded-c/blob/29ab2aa29c5e47794284376d7f8386cfd54c3eed/MQTTClient-C/src/MQTTClient.c#L175 =>
return (curn == curn_end) && ((*curf == '\0') || ((curf[0] == '/') && (curf[1] == '#') && (curf[2] == '\0')));
(I think this has been raised before: https://github.com/eclipse/paho.mqtt.embedded-c/issues/117)
OASIS spec 3.1.1 section 4.7.1.2 has the following non-normative comment: “sport/#” also matches the singular “sport”, since # includes the parent level. This is not occurring. Since that is non-normative, and AFAIK Mosquitto and probably many other implementations also do the same, I suggest you also subscribe to '/devices/123-45/commands' if that is what you need. Perhaps you can also publish to '/devices/123-45/commands/cmdname', it's been a while since I played with GCP.
Mosquitto version 1.6.10 running on libmosquitto 1.6.10:
$ mosquitto_sub -t /devices/123-45/commands/# -h mqtt.lab -v &
$ mosquitto_pub -t /devices/123-45/commands/thiscmd -h mqtt.lab -m "This message"
/devices/123-45/commands/thiscmd This message
$ mosquitto_pub -t /devices/123-45/commands -h mqtt.lab -m "This message"
$
Thanks for the quick reply and the reference to the standard.