Pages

Minimalistic Raspberry Pi-based Temperature Monitor

    A while ago I stumbled upon Tomas Holderness's Temperature Server. Beautiful usage of a number of off-the-shelf technologies: Node.js, Highcharts, SQLite. I fixed some minor issues, customized it to my taste, set it to sample the temperature every 30 seconds and let it run and run... As it accumulated data it took my smartphone longer and longer to load the page. Not only that, the charts are really usable on a bigger screen.

    I ended up with a frame with 2 pages, one that shows the graphs, the other the current temperature. The current temperature page is for the impatient, it loads in a snap.

    The implementation is under 100 lines of Python. Basically it is based on overriding the GET request handler with a custom one that reads the temperature, prepares and sends back the page. Initially I had the page written every half a minute to disk (huh, flash) by a separate process and the web server was the out the box one. Worrying about limited flash write cycles I ended up with this solution that doesn't touch the disk and queries the temperature on demand.

    Freebies: the page auto-refreshes every 30 seconds and provides alerts when the temperature is outside a desired range (added because the initial purpose was to monitor the temperature in our baby room).

    Code below. Just change the configuration as required (port and sensor output file) and fire the server.

    PS The original 2-piece implementation based on a separate program that writes the web page to disk and a web server suffered from race conditions (server may have read an incompletely written page and the auto-refresh would fall apart). This solution is more robust.


      No comments:

      Post a Comment