Simple temperature logger

D3js temperature chartGiven that it’s now winter I’ve had to begrudgingly turn the heating on. To soften the pain of seeing all that money going up in flames in the boiler, and try and settle some debates about when the best time to schedule the heating is, I’ve been using a Raspberry Pi and DHT22 temperature and humidity sensor to log measurements in my flat. As well as logging the temperature data I wanted to make it viewable online, so I can see exactly how cold it will be when I get home (not that I have anyway of turning on my heating remotely). This seemed like a nice small project to learn about the D3 javascript library that you hear so often about with regards to web data visualisations.

A Google around similar sorts of projects indicated logging values to a MySQL (or similar) database, and querying that using PHP to generate the data for visualisation with D3 would be the best approach. But given that I wanted to learn D3, trying to use MySQL and PHP for the first time as well seemed like a recipe for running into dead ends and getting stuck and bored and giving up rapidly. So as a first simple approach I’ve made a Python script running on a Raspberry Pi that logs temperature measurements (based on the Adafruit library), does some processing on them, and uploads CSV files to a server, I then load these data using D3 and plot various graphs. It’s pretty inefficient, in that the script is constantly editing and re-uploading the CSV files that contain the data, but as a first step it seems to work nicely enough.

All the code for logging temperatures, and generating the history graphs are available on GitHub. The webpage of the (non-live) temperature data is at: cutsquash.com/temperature.

Tooltip gif:

D3 tool tip

Also there are some fantastic resources available for learning D3, particularly useful were:

FacebookTwitterGoogle+PinterestTumblrRedditPocketShare


Leave a Reply

Your email address will not be published. Required fields are marked *