-
Notifications
You must be signed in to change notification settings - Fork 184
mqtt
Fabian Affolter edited this page Apr 27, 2014
·
4 revisions
The mqtt
service fires off a publish on a topic, creating a new connection to the configured broker for each message.
Consider the following configuration snippets:
[config:mqtt]
host = 'localhost'
port = 1883
qos = 0
retain = False
username = "jane"
password = "secret"
targets = {
'o1' : [ 'out/food' ],
'o2' : [ 'out/fruit/{fruit}' ]
}
[in/a1]
targets = mqtt:o1, mqtt:o2
format = u'Since when does a {fruit} cost {price}?'
The topicmap
specifies we should subscribe to in/a1
and republish to two MQTT targets.
The second target (mqtt:o2
) has a topic branch with a variable in it which is to be
interpolated ({fruit}
).
These are the results for appropriate publishes:
$ mosquitto_pub -t 'in/a1' -m '{"fruit":"pineapple", "price": 131, "tst" : "1391779336"}'
in/a1 {"fruit":"pineapple", "price": 131, "tst" : "1391779336"}
out/food Since when does a pineapple cost 131?
out/fruit/pineapple Since when does a pineapple cost 131?
$ mosquitto_pub -t 'in/a1' -m 'temperature: 12'
in/a1 temperature: 12
out/food temperature: 12
out/fruit/{fruit} temperature: 12
In the first case, the JSON payload was decoded and the fruit variable could be interpolated into the topic name of the outgoing publish, whereas the latter shows the outgoing topic branch without interpolated values, because they simply didn't exist in the original incoming payload.