Menu

It's Alive!

What's alive? This blog, this Sourceforge project, and my weather net!

weatherPi

I've been tinkering around the edges of this for ages, and finally pulled all the different parts together to get the sensor part working. As I've been pulling this all together, the tought occurred to me that I should blog the steps I've taken, both technological and idealogical, to come up with this little project and bring it to some sort of useful life. So where we have the the weatherPi blog.

In this post, I just want to outline what is currently working. I'll go back and fill in how I got here, and what tools I used to get here, in the next few days. Then I can get onto where to go next.

As of this moment, I have these parts:

  1. A weather sensor. At this point, this is a Raspberry Pi ZeroW with a Bosch Sensortec BME280 module attached via I2C, lying on a shrub in my back yard. It will get a case, and a better location -- more about that later -- and hopefully a better power supply in the future. For now it's happily doing it's job.
  2. A weather recorder. This consists of an Apache Cassandra database, and a tiny web service that allows sensors to record samples they have taken, as well as a web service to query the list of sensors, and samples for a sensor. This is currently running on an ASUS TinkerBoard and TinkerOS 2.10, because Cassandra won't run on a 32-bit system, nor will it run at all reasonably in 1GB RAM. I plan on upgrading this to 3, yes count'em THREE, Raspberry Pi 4s, as soon as there is a stable 64 bit OS build for the Pi 4. I very strongly prefer Raspbian and will probably just wait for that; I'm not in a hurry to throw Pi 4s into the mix since this is working.

So far, the code archives here have to little blobs of code. On is the actual sensor code. It's trivially simple; it initializes the BME280 using a driver I found in PyPI, then loops once per minute scanning the environment from the chip and POSTing to the the web service. This is a whopping 29 lines of Python code, demonstrating how brilliant Python and the PyPI library is at making little tools like this.

On the server side, we have a Python Flask application that recevies samples via a POST, in JSON. The sample is unpacked into a Cassandra object model, which updates the database. There is more logging in the code that does this than actual code; now that it's all working, I'll go back and trim some of the logging. The Cassandra writes are enough wear and tear on the flash, we don't need to double them with paranoid debugging log messages. :)

Missing yet is the virtualenv setup for the Flask application. I'll get that added ASAP.

Next Steps

The next obvious setp is... a web UI. I've done "web UIs" before, but way back in the multi-page, PHP days. When you get done gagging or laughing, come on back.

Regained your composure? Good. Yes, this will be a single-page reactive app. The primary display with be a time-based graph of the past some interval of time showing how the weather has been lately. Of course it will. I'm still learning how to do one of these apps that updates a graph in real time, so if you have any suggestions, I'd like to hear them. If it can be hosted on a Pi with Nginx, so much the better. Ideally I'd like to host the app files on my bastion host, which is a Pi Zero W and runs Nginx to do web services redirects, with redirects to access the read-side of the weather data. (No, I'm not dumb enough to open the sample writing interface to the world.)

After that, I thought I'd add a sensor based on Arduino, to show the zealots just how much harder it is, code-wise. Then document the differences in cost and power budget. I have an Adafruit Feather M0 WiFi lying here, that already has a BME280 attached, so that's just some code away. Well, except for that whole printing floating point numbers thing in Arduino. :)

Then I can move on to powering the sensors with the sun. I have most of what I need, but the battery I have will only power the M0 for 2 hours, so I need about 8 times as much battery, or to learn how to put the M0 and the WiFi radio into low power sleep. Stay tuned.

Posted by Wes Peters 2019-08-04 Labels: RaspberryPi Python Tinker Board Cassandra Flask

Log in to post a comment.