Install InfluxDB instance

  • local database on Raspberry Pi

A remote database, which is used also, allows to monitor Trikarus network status. The installation of this second database is not described in this documentation.

https://www.influxdata.com/blog/getting-started-python-influxdb

sudo su

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
apt update

apt-get install influxdb

systemctl enable influxdb
systemctl start influxdb

#the service file can be found in
/lib/systemd/system/influxdb.service

chown -R influxdb:influxdb /etc/influxdb
chown -R influxdb:influxdb /var/lib/influxdb

service influxdb start

Create trikarus database

(info) A collectd database gets created automatically by collectd service. You only need to add database "trikarus", which is used by Python monitoring scripts for things like Filament sensing with KY-040 Rotary Encoder and much more.

#open InfluxDB shell
influx
CREATE USER trikaflux WITH PASSWORD 'password'
SHOW USERS
CREATE DATABASE trikarus
GRANT ALL ON "trikarus" TO "trikaflux"

Retention policies for databases collectd and trikarus

This is used to automatically cleanup old data from database.

CREATE USER "admin" WITH PASSWORD 'password' WITH ALL PRIVILEGES

CREATE RETENTION POLICY "collectd_policy_14d" ON "collectd" DURATION 14d REPLICATION 1 DEFAULT
SHOW RETENTION POLICIES ON "collectd"

CREATE USER trikaflux WITH PASSWORD 'password'
SHOW USERS
CREATE DATABASE trikarus
GRANT ALL ON "trikarus" TO "trikaflux"

CREATE RETENTION POLICY "trikarus_policy_14d" ON "trikarus" DURATION 14d REPLICATION 1 DEFAULT
SHOW RETENTION POLICIES ON "trikarus"

Purge old data

If you want to reset data you can send some API call for example.

use collectd
DROP SERIES FROM mpu6050_value

Or by API call

curl -cacert /etc/ssl/certs/site.de.ca.crt --cert /etc/ssl/certs/site.de.crt --key /etc/ssl/private/site.de.key https://site.de:8086/query --data-urlencode "db=collectd" --data-urlencode "q=DROP SERIES FROM mpu6050_value" --user admin:password| jq . | grep mpu6050

Troubleshooting

InfluxDB Service

InfluxDB Service

journalctl -f -u influxdb.service
tsdb.HandleRequest() error Post http://localhost:8086/query?db=trikarus&epoch=s: dial tcp [::1]:8086: connect: connection refused


Python scripts

Python scripts

May 17 00:08:21 hangdevice python3.7[6579]: influxdb.exceptions.InfluxDBServerError: {"error":"timeout"}
  • No labels
Write a comment…