Skip to content

Simple script for reading data from Arduino's serial line and sending them to InfluxDB

License

Notifications You must be signed in to change notification settings

ppetr/arduino-influxdb

Repository files navigation

Script to collect data from Arduino into InfluxDB

Disclaimer: This is not an official Google product.

Build Status

Purpose

This script reads data from a serial device, typically Arduino, in InfluxDB's line protocol format and forwards it into an Influx database.

Usage

Write an Arduino program that sends data in InfluxDB's format on the serial line without timestamps (which are generally unavailable on Arduino). For example:

plant,pin=A15 moisture=140,temperature=27.4,humidity=67.3

Prepare an Influx database where you want to store the data. Then run:

python3 collect.py -d /dev/ttyUSB0 -H localhost:8086 -D plants -T location=foo

This reads data from /dev/ttyUSB0 and writes them to the database plants running on localhost:8086 (the default value for -H). It also adds tag location=foo to each sample, in addition to the above pin=A15 sent by Arduino.

For detailed information about command line arguments run

python3 collect.py --help

Running with Telegraf

If the Influx database runs on a different machine, it might be helpful to run Telegraf locally. This has the advantage that Telegraf can buffer messages in the case the connection to the database fails, and also allows to collect monitoring data about the machine, which is generally a good thing for long-running systems.

Keep in mind that Telegraph only allows posting data to a single database, the one configured in Section [[outputs.influxdb]]. It ignores the database name passed to it by collect.py (or any other script).

Requirements

On Debian the first two can be installed using

sudo apt-get install python3-retrying python3-serial

Contributions and future plans

Contributions welcome, please see Code of Conduct and Contributing. Currently I'd like to add:

  • Pytype annotations.
  • Thorough, proper testing.
  • systemd daemon configuration example.
  • Packaging for Debian/Ubuntu.

About

Simple script for reading data from Arduino's serial line and sending them to InfluxDB

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages