I want to set up a simple home sensor network, one that will initially monitor room temperatures, humidity and some utility usage. If it works I may try and add other things to it, but I want to focus on getting the basics working and trying to keep it as simple as I can, otherwise I'll never start.
This series isn't really meant as a tutorial, there are better and more detailed ones available out there, but it might still be interesting or useful to others, so I'll share my progress, including failures, and as much code as I dare. This page contains an overview of what I want to do, how and some of the why, as well as links to (once written) the specific articles describing each part, so it will be updated as I progress.
The outline is:
- The Plan (you are here)
- Basic server setup, and development process
- Saving weather data to local database
- Install an MQTT broker and write a script that writes all suitable incoming messages into a DB
- Build and install temperature sensors around the house
- Build and install a sensor for reading the ongoing gas usage
- Add a website visualising the data to the server, so I can see the current, and historic, data easily on a smart phone
- Additional sensors for other things…maybe, someday
I have an old Raspberry Pi1 that should suffice as the server that will collect all the data, and probably also end up displaying it via a webpage. The sensors will be ESP8266 or similar wireless microcontrollers, hooked up to the different sensors and scattered around the house. They could communicate via some kind of API, but I'm going to go with the light MQTT protocol, that even very simple devices should be able to support. It's the standard for Internet of Things (IoT) devices, and if I add more sensors that are less powerful, they should also be able to support this.
In terms of technology decisions; for any code I'll be relying on Python. First it's the language I know best, second it has a huge ecosystem of reliable libraries to use that cover all my use cases, and lastly it's not a very performance critical environment (I think).
Database wise SQLite3 will be sufficient. As I'm not using multiple machines or users, having the database on one server and one user connecting is enough. Size wise it should scale to anything I'm likely to need. The only thing that might get trickier in the long run in query performance if the data volume gets very large on such a lowly device as an old Raspberry Pi, but I'll wait until I run into that problem before worrying about it.
Lastly I'll be using Ansible to set up and manage the server. While this will add some complexity into the setup, I think it'll be worth it for the repeatability and stability it provides. Even if I'm not managing multiple servers, using in combination with Vagrant I'll be able to test and repeat the installations and scripts before deploying them on the Pi. That's much easier to iterate on than the slow Pi hardware and SD card. It also means once I have a functioning setup on a VM, I can just run the Ansible playbook against the Pi and things should2 just work 'first time'. If anything happens to the Pi, or breaks, the recovery plan is as simple as flashing a image onto the disk, and then running the playbook against this fresh image.
As this is a hobby project, it's also a good chance to learn something new, and I think improving my Ansible skills will be a useful one that can be re-used in other areas. If I wasn't using Ansible, I'd be carefully recording, or perhaps scripting, the series of steps I have to follow to install all the services and applications anyway, so turning those series of instructions into a YAML file that Ansible can run for me doesn't seem to be a lot more effort, and it'll force me to be very precise in what I'm doing, and not allow me to forget to document any important steps along the way.