HobbyingWork

Monitoring heat & humidity with a RaspberryPi & Hosted Graphite

We’re having cooling issues in our Comms Room at work – contraptions of temporary a/c units have been put together, but it makes me nervous. As a kid I worked hiring out air con units and know their limits, they can get you out of trouble quickly but they also give a false sense of security. Whilst we argue over permanent a/c & venting options Christmas approached and I was to be on Annual Leave from 2 weeks before til the New Year.

As a big fan of the RaspberryPi – i’ve managed to get a few installed at work doing various small jobs well – I knew a cheap solution wouldn’t be a stretch to give me some peace of mind and equally alert the facilities staff if things started getting warm. £15 later an AM2302 arrived, hats off to AdaFruit great bit of kit and it comes with some python code ready to go.

The sensor comes with three wires, I soldered them onto jumper cables and isolated everything neatly with some electrical tape and shrink-wrap, finally threading the cables through the RaspberryPi case. I followed this guide to test that all was working as expected and that I had wired everything up ok (I like confirmations). And first time, it spat out:

Temp=25.4°c Humidity=37.6%

Digging through the Hosted Graphite documentation I found an example of sending plain-text metrics using Python. I also found some code where someone was sending the same hardware’s data out to InfluxDB. I forked it and with some help from a developer at work turned it into this. Thanks Steven!

Finally, I set the resulting python file to be triggered by CRON every 5 minutes, within a few minutes metrics were visible to Graphite. I put together a quick Grafana dashboard and set some alerting.

Whilst this let me sleep a little better over the holidays it is by no means a reliable form of monitoring for use in production environments. The sample rate is probably a little too long to alert us if a fire broke out, it’s powered by a UPS but it’s then just connected to the same network it is monitoring – really it should be on a mobile connection, 2g would do fine. We also get the odd mad reading as you can see on the humidity (green) line.

Next stages will be to add another sensor or two in different locations, plus possibly a flood sensor or 5 for our basement. Don’t ask… I’m also looking to pull the internal switch temperatures via SSH and will equally throw it all at Graphite.