Wildcard for multiple segments in the middle of topic?

18 views
Skip to first unread message

Vedran Alajbegovic

unread,
May 4, 2019, 11:12:15 AM5/4/19
to MQTT
Hello,

Is it possible to have multi level wildcard within topic? Simply to avoit multiple messages.

For example

house/entrance/light/color

house/floor1/room1/light/color


So that i can send message house/#/light/color and set color to both entrance light and all roums light.

Or even better option, like this:

house/floor1/room1/light/color
house/floor1/room2/light/color
house/floor1/room3/light/color 

To use topic like: house/floor1/room[1,3]/light/color to set same color in room 1 and room 3

Is there any workaround for that?

What would be the best practice? Is there a way to avoid sending multiple messages to a broker?

Ezequiel Colombo

unread,
May 4, 2019, 12:39:11 PM5/4/19
to MQTT
Hi Vedran,

As per [MQTT-3.3.2-2] "The Topic Name in the PUBLISH Packet MUST NOT contain wildcard characters."
Wildcards are only applicable to SUBSCRIBE .. not PUBLISH. I think your case should be handled at application level but you'll need to PUBLISH specific messages to each topic.

If you wanna simplify your app code maybe you can have each floor clients subscribe also to something like house/light/color and then you can publish one single message to cover them all. 

For example have room1 at floor1 subscribe to:

- Room1 at floor 1 specific light color: house/floor1/room1/light/color
- All rooms light color at floor 1: house/floor1/light/color
- Room1 in all floors light color: house/room1/light/color
- Entire house light color: house/light/color

That approach will increment the number of SUBSCRIBE's but reduce the number of PUBLISH and app complexity.


Regards
ezequiel

Vedran Alajbegovic

unread,
May 4, 2019, 12:43:31 PM5/4/19
to MQTT
thx
Reply all
Reply to author
Forward
0 new messages