Weather Station Project


I wanted to be able to track my local climate over time, to analyze trends and also just for fun. I also wanted to learn more about small microcontroller projets, networking, and databases. After determining my requirements and spending a lot of time scrolling on Adafruit, I decided to create an ESP8266-based unit with a few small sensors.

At the time of writing, the project not yet complete, but beta testing has been going well.

An electronics breadboard connected to two small PCBs with several wires, a battery, and a white plastic device

Hardware

The heart of the system is an Adafruit Feather HUZZAH, which is a fantastic little computer. It has more than enough computing power for this type of work. The HUZZAH can run off a battery. It can also run from USB power, and it will automatically charge the battery when doing so. Most importantly for this project, it also has built-in WiFi. I find it very impressive for a sub-$20 board.

Attached to the board is a sensor that measures temperature and humidity, and another one which measures barometric pressure. There's also a small battery.

Soldering the headers onto the Feather was literally my first time ever soldering. It was a lot easier than I thought, and all of my connections seemed good enough on the first try! The barometric pressure board also needed some soldering.

Currently, it's all on a breadboard. I plan on creating a more finalized version soon, with a permanent board and a weatherproof case.

Software

Client

A screenshot showing some git commits with poor commit messages

The code running on this board—which I call the 'client'—is basically C. I used the Arudino IDE, which makes deploying code onto the board very easy.

The client code is very simple, it works like this: 1. Start up the sensors and get values from them 2. Start the WiFi hardware and connect to my server 3. If connected, build a JSON message and hash it along with a secret key, to make an authorization code 4. Send the message to the server 5. Turn off for 15 minutes

I used the ESP Deep Sleep method to 'turn off' the board.

Server

The server is a FreeBSD Jail running on one of my home's servers.

The server code is also quite simple. It's implemented in Python 3. It waits for the HTTP POST from the client. When that message is received, the code validates the message's authorization code. If that validation succeeds, the data it stored into a MySQL database.

The results of a SQL query, showing temp & humidity values, along with timestamps

In addition to MySQL and Python, the server is also running Grafana, which uses the MySQL database as a data source. A graph of temperature over time, showing values from the high 50's to the low 70's

Summary

This project was way outside my comfort zone. I've never used much of the technology involved, and I had to constantly search the web for answers.

I ran into a lot of confusing problems right from the start. It took me days to get the Arduino IDE to connect to my board. Reading output over serial was confusing and didn't always work.

I've never worked with breadboards before, and I found myself referring to pinouts and tech spec sheets constantly.

I fought with MySQL again and again. Formatting dates was finicky, and getting my HMAC code working took a few tries.

It has finally started to come together and I couldn't be happier.

What's next?

There's a lot left to do. * Final board soldering * Build or salvage a weatherproof case * Networking process changes to avoid replay attacks * Code cleanup * Low battery notification