now, how to get the data into the system?
Is it possible to add MQTT brigdes for TTN subscriptions on the server?
In my scenario I am sending a “Hello World” string to TTN which can be converted back from hex to a text with the “Payload Format” function that has to be placed into the individual TTN front end. My function just decodes the decrypted hex payload to an ASCII object called text
:
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var decoded = {};
decoded.text = String.fromCharCode.apply(null, bytes);
return decoded;
}
Now via the TTN MQTT API with, e.g.
> mosquitto_sub -h eu.thethings.network -t '+/devices/+/up' -u 'thiaspdmtest' -P 'access-key-base64' -v
I get the entire package data from the LoRa uplink:
thiaspdmtest/devices/thias_m0_lora/up {"app_id":"thiaspdmtest","dev_id":"thias_m0_lora","hardware_serial":"003EAA5AA396B119","port":1,"counter":174,"payload_raw":"SGVsbG8sIHdvcmxkIVRoaXMgaXMgUG90c2RhbSE=","payload_fields":{"text":"Hello, world!This is Potsdam!"},"metadata":{"time":"2017-10-17T11:41:19.508166057Z","frequency":867.7,"modulation":"LORA","data_rate":"SF7BW125","coding_rate":"4/5","gateways":[{"gtw_id":"eui-b827ebfffe9ee1ab","timestamp":1667050292,"time":"2017-10-17T11:41:19.375299Z","channel":6,"rssi":-78,"snr":9.2,"rf_chain":0,"latitude":52.0,"longitude":13.0,"altitude":100}],"latitude":52.0,"longitude":13.0,"location_source":"registry"}}
The interesting part is the payload_fields, which contain the actual information. Changing the topic to -t '+/devices/+/up/text'
only the text field is going to be received:
thiaspdmtest/devices/thias_m0_lora/up/text "Hello, world!This is Potsdam!"
mosquitto_sub also allows to subscribe to multiple topics at the same time. In order to get the several variables covered a bridge has to be configured for every topic and of course we’d need a topic remapping. I found some more useful hints here [1].
Is that something we can start with?
[1] Mosquitto MQTT Bridge-Usage and Configuration