martin-ger / esp_mqtt

MQTT Broker/Bridge on the ESP8266
MIT License
293 stars 68 forks source link

Subscribing based on partial string match. #59

Closed jampez77 closed 4 years ago

jampez77 commented 4 years ago

I love this project as it's helping make sure that my Router isn't dropping the many device connected to it.

I'm using this as an MQTT bridge and would like to know if it's possible to subscribe to a topic by using a substring.

So for example I would like the relay all MQTT message from topics containing the word middleFloor or groundFloor

I know there is the substr method that would allow something similar but it's not ideal as I would need to know all the required string lengths before hand.

martin-ger commented 4 years ago

Sorry, this is not possible. According to the MQTT spec, you can use wildcards, but only for complete levels. If possible, try to arrange topics like this: /sensor/groundFloor/s1, /sensor/groundFloor/s2... See also here: https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/

jampez77 commented 4 years ago

Thank you! that link was a huge help! I've changed my topics and it's working as desired.