Mapping/assigning topics

126 views
Skip to first unread message

Micke

unread,
Mar 13, 2016, 2:02:11 PM3/13/16
to MQTT
All new to MQTT and I have question it seams hard to find a answer to. Is there any support to map sensor topics to a more logic topic after installation?

Say you install a bunch of temperature sensors in a couple of buildings (and keep track of which sensor installed where). When publishing temperatures this will be done under the sensor ID (MAC/serial). But at the end I would like to be able to subscribe to "block7/house1/temp/flat123" all without having to compiling this string into the source code of the sensor. I read one post (somewhere else) solving this by having a application subscribing to all topics (numeric MAC/serial) and the re-publish the data with a new topic string. But I thought there might be a "built in" mechanism/approach for this, or?

/M

Nicholas J Humfrey

unread,
Mar 13, 2016, 3:05:17 PM3/13/16
to mq...@googlegroups.com
Hi Micke,

I guess it is possible that a MQTT Server implementation could have
support for re-mapping topics built-in but it isn't a feature of the
MQTT protocol itself.

I personally use Node-RED and my mapper node to perform this task:
https://github.com/njh/node-red-contrib-mapper

But it isn't complex and I am sure people will come back with lots of
other ways of doing it.


nick.
> --
> To learn more about MQTT please visit http://mqtt.org
> ---
> You received this message because you are subscribed to the Google
> Groups "MQTT" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mqtt+uns...@googlegroups.com.
> To post to this group, send email to mq...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mqtt.
> For more options, visit https://groups.google.com/d/optout.

Hans Jespersen

unread,
Mar 13, 2016, 4:39:10 PM3/13/16
to MQTT
I have seen this done three different ways, all of which use some logic outside the mqtt spec and your milage will vary based on the message broker you use.
1) as mentioned earlier, create a re-publisher that listens to a list of mqtt topics (or a wildcard) and then republishes to a different set of mqtt topics based on a lookup table. 
2) use mqtt topics for publishing of the sensor data and then use topic to queue bridging to map those topics into more logical queues on the message broker. Of course this only works if you use a multi-protocol message broker because mqtt does not support queues. Also your subscribers now have to use JMS or AMQP or some other non-mqtt API or wireline protocol that supports queues.
3) use a subscription manager application with administrative hooks into the mqtt broker to watch for mqtt subscriptions to "block7/house1/temp/flat123" and remap those subscription requests into subscriptions to "MAC/serial". This requires the mqtt broker to expose an admin API which (again) is not part of the mqtt spec. 

-hans

Laing, Michael

unread,
Mar 13, 2016, 5:11:07 PM3/13/16
to mq...@googlegroups.com
For 1, you could use https://github.com/jpmens/mqttwarn/

See the section on 'mqttpub', particularly.

ml

--
Reply all
Reply to author
Forward
0 new messages