I want to collect data from a strain guage / load cell connected to a Raspberry Pi and populate an Influxdb database installed in a container on a QNAP NAS. I have a python script that collects the output from the load cell but not sure how to populate the db with these results. For example should I set up an MQTT broker (such as Mosquito) and subscribe Telegraf? Or use a UNIX socket listenter? Where should Telegraf be installed and run; on the Pi or NAS?
How do I configure Telegraf to then load data into the NAS based influxdb?
Thanks very much
My prefered approach for passing data around the network is to use MQTT and Telegraf has an input plugin which will allow you to consume the MQTT messages and send them straight in to InfluxDB.
Here’s my suggestion:
- Add MQTT support to your Python script which collects the output from the load cell. I use Paho. https://pypi.org/project/paho-mqtt/ While you’re at it, you might like to make the output of the script a structure format such as JSON - this will make it easier to consume later.
- Run an MQTT broker on the same Pi. The overhead is minimal. Mosquitto is a great choice.
- Run Telegraf on the Pi too. This is personal preference really, but I think life will be a little bit easier for you dealing with Raspbian than containers on the QNAP. You can download the ARM binaries for Telegraf here: https://portal.influxdata.com/downloads/ I know they work fine on a Pi, I expect the will work on the QNAP.
- Configure Telegraf to use the MQTT input plugin: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/mqtt_consumer If you change your script to output JSON (or something JSON like) this will be a bit easier for you. You can set the
- Configure Telegraf to use the InfluxDB output plugin relevent to the version of InfluxDB you’re running on the NAS. e.g. if you’re running 1.X use: https://github.com/influxdata/telegraf/tree/master/plugins/outputs/influxdb if you’re running 2.x use https://github.com/influxdata/telegraf/tree/master/plugins/outputs/influxdb_v2
The Telegraf project has a lot of examples that should get you going.
You might also like to consider hosting your data in the Cloud 2 product (you can sign up for a free account) and then have Telegraf upload direct to the cloud. Personal preference again, but I quite like having one less thing to manage on my network.
Hope that points you in the right direction, let me know if you get stuck.
Thank you so much for this incredibly comprehensive and helpful reply. I really appreciate you taking the time and offering your insights.