Integrating The Things Network with InfluxDB David G. Simmons Senior Developer Advocate, InfluxData

Agenda ✦ Sign up for InfluxCloud2 ✦ Configure to accept metrics ✦ Configure Telegraf ✦ Collect local stats ✦ Connect to The Things Network ✦ Build a Dashboard @davidgsIoT

Sign up! https://cloud2.influxdata.com/signup @davidgsIoT

@davidgsIoT You will have to verify your email address in order to complete your signup!

Choose a Cloud ✦ AWS ✦ US-West ✦ EU-central (Germany) ✦ GCP ✦ Azure coming soon! @davidgsIoT We will be using AWS, so choose one of the AWS regions for your account.

@davidgsIoT

@davidgsIoT

@davidgsIoT Choose a plan. I recommend the Free account for now. You can always upgrade later Take note of the restrictions.

Load Data ✦ We’re going to configure an instance of Telegraf to collect some system metrics on the host ✦ There are other options ✦ We will customize later! @davidgsIoT

@davidgsIoT Next we’re going to load some data!

@davidgsIoT We will create a telegraf configuration from here.

@davidgsIoT For now, we will just monitor the system.

@davidgsIoT

@davidgsIoT

We Need Telegraf! ✦ This assumes you already have it running ✦ If you do, you can simply copy/paste and go! ✦ If not we will get it running next! ✦ You should have Docker running already @davidgsIoT

@davidgsIoT

Run Docker davidgs@Davidgs ~ % docker pull telegraf davidgs@Davidgs ~ % mkdir telegraf davidgs@Davidgs ~ % cd telegraf davidgs@Davidgs telegraf % docker run —rm telegraf telegraf config > telegraf.conf davidgs@Davidgs telegraf % docker run -privileged -e “INFLUX_TOKEN=TOKEN” telegraf <paste> @davidgsIoT Get your Token from the Browser screen Get your Telegraf command from your browser screen

@davidgsIoT

@davidgsIoT

Data flowing in! @davidgsIoT

Get a better configuration Click on the name @davidgsIoT

Download your new Config! This is where we customize it! @davidgsIoT

Time for some LoRaWan Data ✦ You’ll need your The Things Network info handy! ✦ Decode a packet ✦ Send it to MQTT ✦ Read it from MQTT ✦ Put it into InfluxDB @davidgsIoT

Decode Your Payload function Decoder(bytes, port) { var decoded = {}; var co2Int = (bytes[0] << 8) | bytes[1]; // CO2 is a single byte var cInt = (bytes[2] << 8) | bytes[3]; // temperature ºC is 2 bytes var rem =(bytes[4] << 8) | bytes[5]; // humidity % is 2 bytes var pre = (bytes[6]) + ((bytes[7]) << 8) + ((bytes[8]) << 16) + ((bytes[9]) << 24) ; // pressure is a 4-byte value var alt = (bytes[10]) + ((bytes[11] << 8)) +(bytes[12] << 16) + (bytes[13] << 24); // Altitude is 4 bytes // Decode integer to float decoded.co2 = co2Int; decoded.temp_c = cInt / 100; decoded.humidity = rem / 100; decoded.pressure = pre / 100; decoded.altitude = alt / 100; } return decoded; @davidgsIoT

Get your access Key Also your application name @davidgsIoT

Edit your Telegraf.conf [[inputs.mqtt_consumer]] servers = [“tcp://uswest.thethings.network:1883”] qos = 0 connection_timeout = “30s” topics = [ “+/devices/+/up” ] client_id = “ttn2” username = “APPLICATION NAME” password = “ACCESS KEY” data_format = “json” @davidgsIoT

Restart telegraf davidgs@Davidgs telegrafPreso % docker run —rm —name=telegraf -e “INFLUX_TOKEN=TOKEN” -v pwd/ telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf -e Sets the environment variable to your token -v pwd/telegraf.conf:/etc/telegraf/telegraf.conf:ro Mounts your new config in your Docker container @davidgsIoT

Browse your data You should see lots of meta-data along with your payloads @davidgsIoT

Save it as a Dashboard! @davidgsIoT

Questions? @davidgsIoT