Example Using InfluxDB: Difference between revisions

From lechacal
Jump to navigation Jump to search
(6 intermediate revisions by the same user not shown)
Line 11: Line 11:
We will assume here a setup having:
We will assume here a setup having:
* Server Side. The unit running the influxdb service and waiting for input data.
* Server Side. The unit running the influxdb service and waiting for input data.
* Raspbberypi Side. The unit hosting the RPICT and forwarding data to the server above.
* Raspbberypi Side. The unit connected to the RPICT and forwarding data to the server above.
 
We have covered the case where the Raspberrypi is both the Influxdb/Grafana server and also connected to the RPICT in this guide below.
[[Install an InfluxDB Grafana stack on a Raspberrypi]]


==Installation==
==Installation==
Line 25: Line 28:
From a terminal on the influxdb hosting server issue the command below:
From a terminal on the influxdb hosting server issue the command below:


  $ curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"
  $ curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE db01"


If you want to install influDB on the Raspberrypi itself just follow this guide.<br>
Replace the db01 in the above with whatever you please.
[[Install an InfluxDB Grafana stack on a Raspberrypi]]


===Raspberrypi side===
===Raspberrypi side===
Line 61: Line 63:
  screen -r
  screen -r


Then press ctrl ^C.
Press ctrl ^C to kill the program.<br>
Press Ctrl ^A then D to let it run and detach from the screen session.
 
===Run the Gateway script at boot time===
 
Edit the rc.local file.
 
sudo nano /etc/rc.local
 
Then just before the exit 0 line add the following line:
screen -d -m /usr/local/bin/lcl-gateway.py
 
Once the Raspberrypi rebooted you can access the session using
sudo screen -r

Revision as of 10:24, 11 March 2020


This is a basic example to forward RPICT data to an InfluxDB database. Note this only covers a skeleton to start building your own application.

Prerequisites

The RPICT series board must output using format=3 (default) for this to work.

Document edited using influxdb version 1.2 and python-influxdb version 4.0.

We will assume here a setup having:

  • Server Side. The unit running the influxdb service and waiting for input data.
  • Raspbberypi Side. The unit connected to the RPICT and forwarding data to the server above.

We have covered the case where the Raspberrypi is both the Influxdb/Grafana server and also connected to the RPICT in this guide below. Install an InfluxDB Grafana stack on a Raspberrypi

Installation

Server side hosting InfluxDB

Install InfluxDB as recommended. This link provides compiled executables.

Github link is here.

We will call this server hostname myserver for our example below.

For our example we need to create a database within influxdb. From a terminal on the influxdb hosting server issue the command below:

$ curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE db01"

Replace the db01 in the above with whatever you please.

Raspberrypi side

We are proposing a basic script template which can be installed as below.

sudo apt-get install python-requests
wget lechacal.com/RPICT/tools/lcl-gateway.py.zip
unzip lcl-gateway.py.zip
wget lechacal.com/RPICT/tools/gateway.conf
sudo mv lcl-gateway.py /usr/local/bin/
sudo mv gateway.conf /etc/

Edit the gateway.conf file to reflect your own setting. Content will be self explanatory.

sudo nano /etc/gateway.conf

Insert the RPICT and run

lcl-gateway.py -d

Run the Gateway script in background

You might need to keep the previous gateway program running in the background.

Install Screen.

sudo apt-get install screen

Then run

screen -d -m lcl-gateway.py

To stop it just run screen (provided you are only running one screen at a time).

screen -r

Press ctrl ^C to kill the program.
Press Ctrl ^A then D to let it run and detach from the screen session.

Run the Gateway script at boot time

Edit the rc.local file.

sudo nano /etc/rc.local

Then just before the exit 0 line add the following line:

screen -d -m /usr/local/bin/lcl-gateway.py

Once the Raspberrypi rebooted you can access the session using

sudo screen -r