Raspberry Pi Weather Station: Software

This is the software part of a project I built while volunteering with a research group at a physics lab. I was tasked with using two Raspberry Pi’s to monitor temperature, pressure, and humidity in various places throughout two rooms. To see the hardware portion of the project, click here.


  • Distributed network of up to 16 sensors, using two Raspberry Pi’s
  • Pi’s forward data to a host computer via Redis database server using a pub/sub paradigm
  • Data is stored in CSV files for easy user access
  • Uses python as server backend to pre-process and calculate stats on the data
  • Data can be dynamically loaded to a graph and table by buttons using Javascript

Live Dem


Here’s my stack in 4 steps:

Step 1: read sensors on Pi

This is easy enough in Python. First you send a byte to the multiplexer to select a channel, then just read the sensor with the BME280 Python module.

Step 2: publish data to redis server

Redis is a database server with easy to use Python bindings. Redis supports a paradigm called “pub/sub” where the Pi’s publish their data to different channels and the server subscribes to them. For a project like this you have to make sure to catch all the connection related exceptions and to automatically reconnect if something fails.

Step 3: process data for display on page

The host computer stores the data in CSV files as they are really easy to work with in Python and people can access the data easily. When a web user selects a set of data they wish to view, a request is sent to the server to run a python script which processes the latest data and stats to be displayed. This is accomplished using CGI (Common Gateway Interface), a protocol which tells the server to execute the script rather than serving it.

Step 4: load the data into the page for display

Using JQuery I was able to pull a csv file from the server into an array and push it to the graph for displaying. This all happens dynamically and the user doesn’t need to reload the page to see different sets of data. The graphing is all done using a really nice looking Javascript library called Highcharts.

This was a pretty simple setup that works for getting ambient data from two Pi’s to a web app.

Things I would consider if I redid the project:

  • Reduce overhead by just using straight TCP to send the data to the host computer
  • Use SQL rather than .csv files and just have a function to generate a .csv file given a date range

That’s the software side of things. Here is how the hardware came together.

Leave a Reply

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