wireless networking, free software, solar power

Remarks on Enabling The Things Network for InfluxDB

Posted on | May 22, 2018 | 1 Comment

Two weeks ago i had the pleasure of teaching LoRa, LoRaWan, The Things Network (TTN) at the Joint ICTP-IAEA School on LoRa Enabled Radiation and Environmental Monitoring Sensors.
The only thing unfortunate was the timing that had me miss David G. Simmons’ teaching just a few days later.

While i was showing Node-RED as a tool to get data from The Things Network to an InfluxDB, David presented Enabling The Things Network for InfluxDB.

So, naturally, i had to try that too – configuring Telegraf like so:

servers = ["tcp://eu.thethings.network:1883"]
qos = 0
connection_timeout = "30s"
topics = [ "+/devices/+/up" ]
client_id = ""
username = “username"
password = “password"
data_format = "json"

David writes:

A restart of Telegraf and suddenly a ton of data was streaming from their sensors! Of course, you’ll have to use real values for your own username and password.

In fact it is not quite that easy:

1/ Your personal username and password on The Things Network does not give you access to MQTT topics – instead, you will use

the application-ID as username,
and its access key as password.

2/ With that in place, in fact you get a lot of data, but in fact these were all just metadata from the TTN handler, but not the actual sensor data – why?

1526984334188284335 32498 influxus 51456000 867.1 12 3 55.6858 12.5521 0 -63 9.8 2153236443 1 pitlab-ds18b20/devices/itu-pitlab-seb-thingsuno-6/up
1526984339157003551 29102 influxus 51456000 868.3 -26 1 55.65956 12.59067 1 -99 7.8 1694919843 1 pitlab-ds18b20/devices/itu-pitlab-seb-thingsuno-7/up
1526984345832526531 1024 influxus 51456000 868.1 -26 0 55.65956 12.59067 1 -91 9.5 1701652715 30 0 55.65961 12.591463 1 -106 3.75 1703598403 1 pitlab-ds18b20/devices/itu-pitlab-seb-thingsuno-5/up

The MQTT consumer plugin
expects messages in the Telegraf Input Data Formats, such as JSON.
That is however not what a TTN node is sending – unless i specifically tell it to.

Recommended practice is to have a sensor node send as little payload as possible, because airtime and battery power are both precious resources. So, the node should not send redundant unnecessary info (such as a field name) in JSON objects. Instead, it will send just bytes.

If we want Telegraf to read our MQTT topics and understand the actual sensor readings, we have several ways of making that work, and it s actually quite easy:

1/ We can add a Paylaod Converter on TTN to create a json object – note that the handler is the right place to do this, because from here on, additional data do not hurt our network or power budgets anymore.

2/ Alternatively, we could script this in the Influx side.


One Response to “Remarks on Enabling The Things Network for InfluxDB”

  1. Walter
    March 27th, 2019 @ 4:10 pm

    if you are using a device that send data in Cayenne Low Power Payload (LLP) format , then on the TTN console you can configure your application to decode the data. It is configured at “Payload formats” tabs, after that, TTN decode data in raw payload and add proper fields to json structure.

Leave a Reply