Enabling The Things Network for InfluxDB

Originally published at: Enabling The Things Network for InfluxDB | InfluxData

[caption id=“attachment_215425” align=“alignleft” width=“150”] Photo by Anete Lūsiņa on Unsplash[/caption]

I’ve been on the road a bit lately. Ok, so a lot. I spent a week at KubeCon EU demoing InfluxDB and IoT at the EclipseIoT booth, and then I spent a week presenting at the ICTP Workshop on monitoring Radiation data via LoRa networks. I’m sure that all sounds ridiculously exciting to you. It was more exhausting than anything. As a side note, I managed to walk a total of 25 miles over 2 days during those trips which is personally pretty amazing.

While I was instructing at the ICTP workshop—and let me say that it was both an honor and a privilege to be around the incredibly smart attendees under the auspices of the United Nations—I was asked if it was possible to connect The Things Network, which the workshop was using to collect sensor data, to InfluxDB. I figured it would be, and that it wouldn’t be that hard, but I was a little shocked at how simple it really was! Here’s the rundown.

First, I installed InlfuxDB, Telegraf, etc. on a server in the ICTP Lab. Next, I had to configure the Telegraf instance to read from the TTN (The Things Network) server. Luckily it is a simple MQTT broker, so all I had to do was edit the telegraf.conf file and add the following section:

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

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.

I wish that this was a longer blog post, but it’s hard to stretch this out much more given how easy it was to integrate TTN with InfluxDB. The really neat thing about the Telegraf MQTT plugin is that it automatically ‘flattened’ the JSON payload from the TTN MQTT broker and imported the resultant data into InfluxDB with no additional effort on my part.

If you’re using TTN, and you want an easy way to analyze and visualize your data, try pulling it into InfluxDB! It’s super easy, super fast, and gives you access to data analysis and dashboarding very quickly. Talk about Time to Awesome™!!

I have this set up as in your reference above in Telegraf, but I can’t seem to get the data into Grafana…

I can see the traffic from MQTT on my client flowing, and I have other sensor data working fine from other sources… but NOT from TTN…

any ideas on how to track issue this down??

Here is the JSON data from TTN

rsf_otaa/devices/ls-113/up

{
  "app_id" : "rsf_otaa",
  "dev_id" : "ls_112_rsf",
  "hardware_serial" : "000DB53001633683",
  "port" : 3,
  "counter" : 6414,
  "confirmed" : true,
  "payload_raw" : "AgmyF8AAAA==",
  "payload_fields" : {
    "hum" : 60.8,
    "ppm" : 0,
    "temp" : 76.676
  },
  "metadata" : {
    "time" : "2018-09-13T04:05:45.997704443Z",
    "frequency" : 904.1,
    "modulation" : "LORA",
    "data_rate" : "SF7BW125",
    "airtime" : 56576000,
    "coding_rate" : "4/5",
    "gateways" : [ {
      "gtw_id" : "rsf92067usa",
      "gtw_trusted" : true,
      "timestamp" : 1992302563,
      "time" : "2018-09-13T04:05:46Z",
      "channel" : 1,
      "rssi" : -65,
      "snr" : 9,
      "rf_chain" : 0,
      "latitude" : 35.98473,
      "longitude" : -111.179,
      "altitude" : 96,
      "location_source" : "registry"
    } ]
  }
}

Have you verified that this data is getting into InfluxDB? I’d use either the CLI to check that it is, or get Chronograf set up to verify the data is in the DB first.

dg

I used Simulate Uplink from TTN Console to send JSON data values, but in telegraf doesn’t appers nothing.
Do you have any suggestions?

Hi @Redans_Redans,

Not much to go on here, but are you sure that data is being sent on that MQTT broker? If you connect an MQTT client to it, do you see data being posted to the broker?

dg

Hi,
I did the following test, I send some data values from my mqtt client:
mosquitto_pub -h eu.thethings.network -t ‘app/devices/first_id/down’ -u ‘app’ -P ‘ttn-account-v2.key…’ -m ‘{“payload_fields”:{“led”:true,“temp”:456,“press”:123}}’

In TTN Console appers new values, see screen shot, but in telegraf nothing changed.