Getting TTN Data into InfluxDB the Easy Way

A presentation at The Things Conference in January 2020 in Amsterdam, Netherlands by David G. Simmons

Slide 1

Slide 1

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

Slide 2

Slide 2

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

Slide 3

Slide 3

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

Slide 4

Slide 4

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

Slide 5

Slide 5

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.

Slide 6

Slide 6

@davidgsIoT

Slide 7

Slide 7

@davidgsIoT

Slide 8

Slide 8

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

Slide 9

Slide 9

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

Slide 10

Slide 10

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

Slide 11

Slide 11

@davidgsIoT We will create a telegraf configuration from here.

Slide 12

Slide 12

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

Slide 13

Slide 13

@davidgsIoT

Slide 14

Slide 14

@davidgsIoT

Slide 15

Slide 15

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

Slide 16

Slide 16

@davidgsIoT

Slide 17

Slide 17

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

Slide 18

Slide 18

@davidgsIoT

Slide 19

Slide 19

@davidgsIoT

Slide 20

Slide 20

Data flowing in! @davidgsIoT

Slide 21

Slide 21

Get a better configuration Click on the name @davidgsIoT

Slide 22

Slide 22

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

Slide 23

Slide 23

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

Slide 24

Slide 24

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

Slide 25

Slide 25

Get your access Key Also your application name @davidgsIoT

Slide 26

Slide 26

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

Slide 27

Slide 27

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

Slide 28

Slide 28

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

Slide 29

Slide 29

Save it as a Dashboard! @davidgsIoT

Slide 30

Slide 30

Questions? @davidgsIoT