RustProof Labs: blogging for education (logo)
My book Mastering PostGIS and OpenStreetMap is available!

Introducing the PiWS (Pi Weather Station)

By Ryan Lambert -- Published May 13, 2018

The PiWS, short for The Pi Weather Station, is an open source, affordable weather station designed for everyone. This is not a traditional, commercial weather station that provides you a fixed set of sensors and collect data without providing you a way to keep your own data.

Instead, The PiWS is designed around open source hardware and software, provides you with a choice of sensors, and encourages long-term retention of your sensor data.

Picture of an early version of the 3D printed PiWS enclosure, translucent green in color.

What does it do?

The PiWS collects data from a variety of analog and digital sensors to collect data from your local environment. When we talk about "environment", that could be indoor, outdoor, garden... or in the attic, basement, garage, or that one room upstairs that always seems cold.

The data from the sensors is collected in a PostgreSQL database on the Raspberry Pi, allowing you to store the data long term, analyze trends, or just satisfy your curiosity!

Why the PiWS?

The idea for the PiWS started around the time I started building TrackYourGarden (TYG) in 2015; it's another part of my desire to understand everything possible about our local micro-climate. I said at that time:

"It's hard to answer the questions of "When can I plant plant X?" living at 6,000 feet. We have a fairly short growing season; it has snowed on Mother's day two years in a row now, and it's not unusual to have at least one light snowfall around Halloween.... so naturally I figured the best thing to do was to gather some data (surprise!)"

Getting your PiWS

Full instructions to building, customizing and configuring your PiWS from scratch are coming soon.

Email support@rustprooflabs.com to pre-order your PiWS from RustProof Labs. The standard PiWS station starts at $600 for a limited time.

TrackYourGarden

The PiWS includes an optional service to submit sensor data directly to the TrackYourGarden Sensor API. This integration provides robust reporting and reliable backups for your PiWS data. If you grow a garden, large or small, this is the ideal way to see how your plants respond to different environments.

The following chart shows a basic 3-day trend of data from one of our PiWS in our home garden. Notice the pop-up information when you hover over the data points on the chart.

Big picture

The PiWS is a collection of open source hardware and software that you can customize to meet your needs. The following video provides a walk through of how the PiWS comes together.

The PiWS = Raspberry Pi + PostgreSQL + Open Source software + affordable hardware and sensors

Hardware

The PiWS requires three main groups of hardware.

The following video and text explains the hardware and overall setup of the PiWS.

Raspberry Pi

The Raspberry Pi's role is to collect the sensor observations from the Arduino board and store/transmit them for long-term storage and use. The Raspberry Pi can be either a quad-core Raspberry Pi 3B+ all the way down to a very affordable, single-core Raspberry Pi Zero W. At RustProof Labs we are only using the models with WiFi to make it easier to get the data out.

Arduino Uno

The Arduino Uno is the basis of the Sensor Control Board (SCB) of the PiWS. This is the bridge between the Pi and the sensors themselves. The Arduino board connects to the Pi via USB to provide power and to transmit sensor data.

Sensors

The sensors of the PiWS are the heart of the system. Below are the main sensors we selected for initial inclusion.

Enclosure

The file(s) for 3D printing the official PiWS enclosures will be added to the GitHub repository soon. At the time of writing we are working on finalizing the design for the SCB and polishing the design for the Raspberry Pi enclosure (seen at the top).

Software

The PiWS is open source; the source code is available on GitHub.

The Arduino Uno runs firmware (C++) to collect data from the sensors, prepare the data in JSON format, and sends the data via the serial bus. This code is under the arduino folder in the project repo.

Data storage is handled by a PostgreSQL named piws.
The remainder of the PiWS software is on the Pi in the form of Python services.

Deployment

The PiWS software, services and default security are deployed using Ansible to provide this in an automated and repeatable fashion. We are working on finalizing deployment instructions. They will be provided in the form of a new blog post and instructions included in the GitHub repository.

In the mean time, take a look at the first functional PiWS! Getting rid of those alligator clips was a nice improvement.

#opensource weather station in the works! First prototype with air and soil #sensors, collecting data in #postgresql #database on #raspberrypi Photo from a couple weeks ago, now testing Bluetooth connection for sensors! 👍

A post shared by Track Your Garden (@trackyourgarden) on

Data from the PiWS

My favorite part of the PiWS is being able to query the data directly from the sensors. With sensor data being collected in PostgreSQL it is easy to query the data directly, export it to CSV and load it into Excel, or even pull it into Python or R for more complex analysis.

The point is, its your data; you can easily access and analyze it however you choose!

Connect to the PiWS database

I like to use psql to connect to the PostgreSQL database running on the PiWS. If you're following along, replace the IP address in the following command with your PiWS' IP address.

$ psql -U piws -h 192.168.101.101 -d piws

Enter your password when prompted.

Password for user piws: 
psql (9.6.7)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

Raw observations

The following query allows you to view the raw sensor observations coming in from the Arduino. These readings come in roughly every 5 seconds. The data comes through as JSON and the Python service that collects this data ingests the readings as they come in and stores them in the sensor_values column.

piws=> SELECT c.datum, t.timeofday, o.sensor_values
    FROM piws.observation o
    INNER JOIN public.calendar c ON o.calendar_id = c.calendar_id
    INNER JOIN public.time t ON o.time_id = t.time_id
    ORDER BY o.observation_id DESC
    LIMIT 1;
┌─[ RECORD 1 ]──┬───────────────────────────────────────────────────────┐
│ datum         │ 2018-05-13                                            │
│ timeofday     │ 07:17:34                                              │
│ sensor_values │ {"dht11_h": 44.0, "dht11_t": 22.0, "ds18b20_t": 9.94} │
└───────────────┴───────────────────────────────────────────────────────┘

In this case there are two (2) sensors providing three (3) total readings. The DHT-11 sensor has a value for humidity (dht11_h) and temperature in Celsius (dht11_t) while the DS18B20 provides a single temperature reading, also in Celsius. In the case of the above reading, the DHT-11 is providing readings indoors (22°C = 72°F) while the DS18B20 is outside in our garden (9.94°C = 50°F).

Minute aggregations

The raw data seen above is not ideal for storage or querying purposes due to the volume of data and the overhead of storing data in JSON format. These performance issues become very obvious when running on low-power hardware, such as the Raspberry Pi Zero W.

To solve this, raw data is automatically aggregated to once-per-minute observations and stored in the piws.observation_minute table. The results of the following query show that each row has the name and value for only one sensor, instead of all the observations jammed in using JSON.

piws=> SELECT c.datum, t.timeofday, o.sensor_name, sensor_value
    FROM piws.observation_minute o
    INNER JOIN public.calendar c ON o.calendar_id = c.calendar_id
    INNER JOIN public.time t ON o.time_id = t.time_id
    ORDER BY c.datum DESC, t.timeofday DESC
    LIMIT 1;
┌─[ RECORD 1 ]─┬────────────┐
│ datum        │ 2018-05-13 │
│ timeofday    │ 07:33:00   │
│ sensor_name  │ ds18b20_t  │
│ sensor_value │ 10.000000  │
└──────────────┴────────────┘

Summary

The PiWS is a collection of open source hardware and software to make it easier to collect accurate, local data about your environment. This post provides a very quick overview of what the PiWS is and why RustProof Labs created and supports this open source project. As the project grows and matures, this page will be updated with information, resources and other links.

You can follow @TrackYourGarden on Instagram and @RustProofLabs on Twitter.

By Ryan Lambert
Published May 13, 2018
Last Updated May 13, 2018