How to collect, monitor, read, and store pressure, temperature, humidity, visible, IR, and UV light data with a Raspberry Pi, an Adafruit BME280, Adafruit SI1145, collectd stats collector, and mosquitto MQTT.
I wanted a way to start collecting environmental stats, without any vendor-lock in, preferably cheap, and in a form that I can store and use the data points long term. Z-Wave (Zigbee, Xbee, these are the same) looks great, especially since IKEA started to offer smart lights based on completely Open Source protocols.
Until Z-Wave, though, I have a spare Raspberry Pi 3, so let’s see where I could get with these.
Initially I started with cheap sensors, like the DHT11, but those are way to inaccurate and their resolution is far from desirable: 1 °C without digits in case of the DHT11, so I bought better ones before moving on.
Unfortunately the accuracy of the BME280 temperature readings can be a bit messy as well, for which I’ll only read every 10 minute and lower the read rate - the board the sensor is mounted on has a tendecy to overheat a little and these seem to be working countermeasures against that scenario1.
something to multiplex the 3.3V, GND, SDA, and SCL (1, 6, 3, 4) pins on the Raspberry with for the 2 sensors OR simply connect them parallel. I’ve found RasPiO proto board in the Cambridge Makespace5, but this is for the original Pi and is out of production, so you’ll need something like a TriBorg6 which triplicates the GPIO pins.
Note: --no-install-recommends will save you, for example, installing java. We won’t need recommends.
Normally collectd use RRDTool to save data; this is a time series data format that compresses the old data after a while. Because I want to be able to use the data later on, in this case, I decided to go for CSV files which are easy to parse - or to feed to some machine learning.
MQTT is a lightweigh messasing protocol: it has a server, a hub, which collects all the incoming data; publishers pushing the data, and subcribers, reading topics. It’s used widely in the “Internet of Things area” - though I seriously dislike the phrase -, and it’s a good protocol to get started with. There are a few decent MQTT dashboard apps for Android, so it’s easy to read the data as well with it.
Keep in mind that this will load your MQTT server without authentication and authorization on port 1883, so don’t ever do this on an internet facing device.
The # is to subscribe to everything; replace it with i2c to monitor our plugin only.
These are needed to build the sensor libraries and to interface with collectd.
Just run these in the pi user home directory.
I’m using a branch which is not yet merged into the main code, thanks to frank-f: this contains code with lets you set the mode for the BME280, which, in theory, helps with mitigatin the self-heating problems often mentioned with this board9.
directories, the one under DataDir in the collectd configuration.