I’ve always wanted to get back to my technical roots and work on electronics projects, however, life somehow always seems to get in the way. The Nationwide/Worldwide lockdown has been in full swing for months now which means lately I’ve had a lot more time to work on various projects such as a podcast, and fooling around with solar power for my garden shed.
After I finished working on my solar project I needed something else to do and had the idea of building a weather station. I scoured the internet looking for examples and parts. To my surprise, there were lots of options available, from buying each individual component separately all the way up to completely built. I was looking for something in the middle, ultimately I settled on Sparkfun weatherbit. It has a temperature sensor, humidity sensor, soil temperature, moisture sensors, more traditional weather-related sensors like wind speed and direction sensors as well as a few other sensors such as an accelerometer.
All controlled by a microcontroller, the BBC Microbit. Now this in itself is awesome, however, there was no built-in method for exporting that data in realtime since the supported methods of communication are extremely limited, Bluetooth, serial, and writing to a micro SD card. I knew I wanted to do more than store the weather data on an SD card so I decided to use a Raspberry Pi Zero W and some programming to scrape the serial port and then ship that data to a database for realtime weather data. I also had the thought of possibly uploading that data to Weather Underground or perhaps even make a small website that would display the latest data to anyone that came across it.
I’ll briefly go over some of the highlights of the project.
ser = serial.Serial(serial_port, serial_rate, timeout=2)
The code above starts collecting the data over the serial port. In Linux I ran into a serial buffer issue hence the reset calls.
That bit of code is where the magic begins. It’s basically a forever While loop that scrapes the serial port. Again occasionally I hit the serial buffer issue so I have some error handling that resets the buffers, waits five seconds then starts the loop over. On each successful iteration of the While loop, the data is sent to Rabbitmq.
That short bit of code takes in the weather data and sends it to RabbitMq where it is stored until consumed buy a telegraf. Telegraf then stores the data in an Influxdb database where I can finally retrieve the data. I use Grafana to make a dashboard of current atmosphere data.
Overall this has been a fun and somewhat challenging project. But I highly recommend it especially if you’re trying to expose your children to programming and or electronics.