Wednesday, 29 June 2016

Metpi #3: software

For the software side of the Metpi, I wanted to do two things:
- Log the data with the other pis from the Radpi system.
- Publish the data to the Weather Underground platform.
I've therefore split the work into two programs: one reads the data and makes it available to the Radpi server, the other sends the results to the Wu server.

Reading the sensor data is easiest done in python. I don't know python, but it's easily done with a few lines of code. The following reads the sensor data, displays it on the led screen of the Sensor Hat, and makes it available to the Radpi server (see Radpi setup to build the pi for that purpose):

Note that the Sense Hat design has a major flaw: some of the sensors are very close to the pi's CPU and therefore are affected by it. It is mainly noticeable for the temperature, but humidity should also be affected. This is why the script contains a few adjustments based on values provided by another station nearby. As the effect of the CPU heat on the temperature sensor will be proportional to how busy/hot the pi is, we take all temperature sensors' readings, and substract a proportion of the difference with the pi's CPU temperature.

The script is scheduled to run every minute in crontab. I simply added another target to the Radpi central server to collect that data and store it in a table with temperature, humidity, and pressure fields. I also added the graph on the home temperature page.

The other script, in PHP this time since everything else is, reads the file created by the python script, and sends the information to the Wu server:

The dew point is approximated* but that should be sufficiently accurate. All units are converted to imperial on the fly as that's what Wu requires. The script is scheduled to run every 5 minutes in crontab.