More explicit single level MQTT topics with PahoMTT?

Viewed 57

I'm using the message_callback_add()-method of PahoMQTT to filter the messages by topic and would like to be a bit more specific.

Example topic to get the color of a banana:
fruits/banana/color, syntax: fruits/+/+.

I'd like to listen only to the fruits banana and apple. Currently I filter it manually, but I'd prefer to have a syntax like: fruits/<banana|pear>/+.

Does something like that exist? I only know about wildcard (#) and single level (+) placeholders.

1 Answers

Nope

MQTT wildcards only match whole topic levels and you can not pass optional matches. The Paho library uses the same rules that the broker would use to match topics.

You will need to do topic matching in the message callback.

Related