diff --git a/atom.xml b/atom.xml index 3293f52bc5..ff37e8c7cb 100644 --- a/atom.xml +++ b/atom.xml @@ -4,7 +4,7 @@
To check what your devices are sending, subscribe to the topic +/devices/+/up
with a command-line tool like mosquitto_sub
. The <Region>
is the postfix of the Handler entry in your Application overview. <AppID>
is the Application ID and <AppKey>
is your access key.
``bash
-$ mosquitto_sub -v -h
-The payload contains details about the device itself and the sensor data. The sensor data is stored in `payload_fields`. Depending on the device configuration it may contain a single value or multiple values.
+$ mosquitto_sub -v -h <Region>.thethings.network -t '+/devices/+/up' -u '<AppID>' -P '<AppKey>'
+{
+ "app_id": "ha-demo",
+ "dev_id": "device01",
+ "hardware_serial": "AJDJENDNHRBFBBT",
+ "port": 1,
+ [...]
+
+
-## <a class='title-link' name='the-relay' href='#the-relay'></a> The relay
+The payload contains details about the device itself and the sensor data. The sensor data is stored in payload_fields
. Depending on the device configuration it may contain a single value or multiple values.
-To be able to work locally with the MQTT data that is received from the devices connected to TTN, we need to transfer it to the local broker. With this simple script below all messages from a given device are re-published on your local MQTT broker after they are received. Modify the script with your details as outlined in the previous section.
+ The relay
-```python
-"""Relay MQTT messages from The Things Network to a local MQTT broker."""
-import paho.mqtt.client as mqtt
-import paho.mqtt.publish as publish
+To be able to work locally with the MQTT data that is received from the devices connected to TTN, we need to transfer it to the local broker. With this simple script below all messages from a given device are re-published on your local MQTT broker after they are received. Modify the script with your details as outlined in the previous section.
-DEVICE_NAME = '<DeviceID>'
+"""Relay MQTT messages from The Things Network to a local MQTT broker."""
+import paho.mqtt.client as mqtt
+import paho.mqtt.publish as publish
-TTN_BROKER = '<Region>.thethings.network'
-TTN_USERNAME = '<AppID>'
-TTN_PASSWORD = '<AppKey>'
-TTN_TOPIC = '+/devices/{}/up'.format(DEVICE_NAME)
+DEVICE_NAME = '<DeviceID>'
-LOCAL_BROKER = '192.168.0.2'
-LOCAL_TOPIC = 'home/ttn/garden_temp'
+TTN_BROKER = '<Region>.thethings.network'
+TTN_USERNAME = '<AppID>'
+TTN_PASSWORD = '<AppKey>'
+TTN_TOPIC = '+/devices/{}/up'.format(DEVICE_NAME)
+
+LOCAL_BROKER = '192.168.0.2'
+LOCAL_TOPIC = 'home/ttn/garden_temp'
-def on_connect(client, userdata, flags, rc):
- """Subscribe to topic after connection to broker is made."""
- print("Connected with result code", str(rc))
- client.subscribe(TTN_TOPIC)
+def on_connect(client, userdata, flags, rc):
+ """Subscribe to topic after connection to broker is made."""
+ print("Connected with result code", str(rc))
+ client.subscribe(TTN_TOPIC)
-def on_message(client, userdata, msg):
- """Relay message to a different broker."""
- publish.single(
- LOCAL_TOPIC, payload=msg.payload, qos=0, retain=False,
- hostname=LOCAL_BROKER, port=1883, client_id='ttn-local',
- keepalive=60, will=None, auth=None, tls=None, protocol=mqtt.MQTTv311)
+def on_message(client, userdata, msg):
+ """Relay message to a different broker."""
+ publish.single(
+ LOCAL_TOPIC, payload=msg.payload, qos=0, retain=False,
+ hostname=LOCAL_BROKER, port=1883, client_id='ttn-local',
+ keepalive=60, will=None, auth=None, tls=None, protocol=mqtt.MQTTv311)
-client = mqtt.Client()
-client.username_pw_set(TTN_USERNAME, password=TTN_PASSWORD)
-client.on_connect = on_connect
-client.on_message = on_message
-client.connect(TTN_BROKER, 1883, 60)
+client = mqtt.Client()
+client.username_pw_set(TTN_USERNAME, password=TTN_PASSWORD)
+client.on_connect = on_connect
+client.on_message = on_message
+client.connect(TTN_BROKER, 1883, 60)
-client.loop_forever()
+client.loop_forever()
diff --git a/blog/2017/11/10/ttn-with-mqtt/index.html b/blog/2017/11/10/ttn-with-mqtt/index.html
index 6c651cb898..03515f2c2f 100644
--- a/blog/2017/11/10/ttn-with-mqtt/index.html
+++ b/blog/2017/11/10/ttn-with-mqtt/index.html
@@ -74,7 +74,7 @@