Monitoring the climate is a standard project for the RaspberryPi. I bought two Raspberry Pi Zero, two BME680 Breakout, booted my old Raspberry Pi 3 and started hacking.
Testing the BME680 module
To start on working with the BME680 module I can highly recommend the BME680 python lib and the tutorial. Just follow the instructions from the tutorial to test your sensor.
Failstory - Install Elasticsearch on RaspberryPi
TLDR; Elasticsearch on Raspberry is not possible.
At first I tried to use ElasticSearch for aggregating the sensor data. I followed an old tutorial for the Pi. Unfortunately Elasticsearch v6 needs at least 8gb of RAM. Otherwise the Java Virtual Machine won’t start.
However if you want to send BME680 data to Elasticsearch you can use the following elasticsearch mapping:
Then you can parse BME680 data and send it to an elasticsearch endpoint with:
The data from Elasticsearch can be retreived with:
In the end, I stopped working on Elasticsearch because I don’t want to run my 25W NAS server 24/7 just to aggregate some temperatures. Therefore something more lightweight is needed that runs on a RaspberryPi.
Collecting Logs with InfluxDB on a RaspberryPI
I looked into Prometheus and InfluxDB for collecting the data. Both plattforms have their use cases. Finally, an awesome stackoverflow question, where the InfluxDB CEO and a Prometheus developer discussed their plattforms, lead to my decision to go with InfluxDB. Simply because Prometheus is float value only and I want to have multiple datatypes.
Install InfluxDB service on the data collector
Download and install the InfluxDB ARM package:
Modify influxdb.conf to enable admin GUI and restart the database.
Go to the admin GUI of the InfluxDB and create a new database with the name
Install the BME680 python package and InfluxDB client on the data sender
You need the bme680 python lib and the InfluxDB client. In my case the bme680 temperature readings are 3.5 degrees celsius to low, therefore I wrote a pull request to allow some offset calculation. Until the pull request is merged you should clone from my bme680 repo.
Test InfluxDB client and server
To quickly test your setup you can execute the following script on your data sender.
In the InfluxDB admin GUI you should be able to read your test values with
select * from test. The InfluxDB measurement variable can be compared with a standard relational DB table.
Send everything from the BME680 to InfluxDB
To send everything the BME680 has to your InfluxDB instance you can use my bme680_to_influxdb
script. Clone it with
git clone https://github.com/ayeks/bme680_to_influxdb, configure the parameters in
senddata.py and execute it with
python3 senddata.py. If you want to define a session, location and temperature offset use:
python3 senddata.py "dev" "livingroom" -3.5.
Often you want your Raspberry to execute the senddata script automatically after it started. Use the following to do so:
In the InfluxDB admin GUI you can send SQL-like queries. For example you can get all the measurements / tables that exist:
You can also retreive all available tags for a measurement:
SHOW TAG KEYS FROM "dev"
Be carefull when selecting everything because that can take a while to process when the database is big.
SELECT * FROM "dev"
Having sensor data in a timeseries database is just half the fun of having shiny grafana dashboards for that data. First you need a InfluxDB datasource in your Grafana. Have a look at my configuration.
I know, no authorization and isolation is bad. I will get into detail with that in the future.
After creating the datasource you can select it when you create a new graph. Simply copy my graph definitions as starting point for your own dashboard:
Currently, the complete dashboard looks like that:
Feel free to download the dashboard from my git repo and feel free to open any issues regarding the senddata.py and the Grafana dashboard.