InfluxDB + Telegraf and multiple sensors within one application

Hello All,

i created a application in ttn console and have 10 Sensors inside this applicaiton.
Using telegraf and the mqtt plugin like describe here:
here

This is the plugin configuration:

[[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”

i am able to push the data sucessfully into the influxdb.

But i am facing two problems:

1.)
i would like to create a new measurement for every device inside my influxdb
At the moments all uplinks are saved in the one measurement mqtt_consumer.
Only the TAG Topic allows to distinguish between the sensors.
Do you have any idea how to adjust the plugin, so that every sensor will be saved in its own measurement. Or is there any best practice on how to work with multiple sensors and how to save data of them in influxdb ?

2.)
I also would like to insert metadata inside these measurements.
The payload decoder inside TTN allows me to describe variables calculated from the payload, but i also need to store information like rssi and SF.

Any help would be highly appreciated, also if you know any best practices how to manage best multiple sensors in one applicaiton.

Thank you a lot for your help!

What are using the collect the mqtt data? node-red or python etc?

I found node-red great for collecting the data from an application, but was limited with my skills on it to extract the whole payload on the metadata side. I also had trouble in setting fields and tags with influx, but again I think that is more related to my node-red/javascript short comings then node-red itself.

I was able to write a python3 script which was able to extract the entire payload, which I could then send the entire payload to an influx db with set measurement, field and tag keys from the device data.

This thread here might help you with extracting all the payload data.

Once you get it woking with a little hack-fu you can add an influx connection in the script to connect to your db and send the collected data over.

1 Like