iot, coding, raspberry pi, python, node.js, javascript, redis,

Environment Monitoring with Redis Streams, Raspberry Pi Pico W and MicroPython

Simon Prickett Simon Prickett 3 mins read
Environment Monitoring with Redis Streams, Raspberry Pi Pico W and MicroPython

The Raspberry Pi Pico W is an extremely capable microcontroller device from the Raspberry Pi Foundation. The W variant has on board support for wifi networking. This and the ability to run MicroPython makes it an excellent choice for projects that need to gather data from sensors and report it to a cloud server.

I decided to build an environment monitoring system using a couple of Pi Pico W devices, Redis and some server side logic. I used temperature, humidity and light sensors plus a fan to simulate an air conditioning unit.

This was the second project in my Things on Thursdays IoT live streaming series.

Enjoying this article? Please consider buying me a coffee on Ko-Fi.
Your support helps to fund future projects!

Starting with a box fresh Raspberry Pi Pico W, I demonstrated how to install MicroPython, connect to the device from Visual Studio Code and write Python code on it. I wrote code to connect to a wireless network, created a Redis database in the cloud and got started with streaming data to Redis.


In the second episode, I’ve soldered headers to the Pi Pico W and connected it to a Seeed Studio Grove shield. This made it easy to attach Grove compatible sensors. I replaced the code from episode 1 that sent a stream of numbers to Redis with code that sent temperature and humidity values from a sensor attached to the Pi. I also demonstrated how to read this data from a Redis stream using Node.js.


In Episode 3, I added a light sensor to the existing temperature/humidity sensor on the Pi Pico W and streamed data from that to Redis. I then looked at how to modify the Node.js code that reads from the stream to remember how far through it was so that if it crashed or got restarted it picks up from where it left off rather than at the start of the stream. I demonstrated how to use a Redis Sorted Set to model the 1:many relationship between sensor IDs and room IDs (one room can contain many sensors, one sensor can only live in one room) before finishing up by storing structured JSON documents in Redis representing the status of each room.


In Episode 4, I addressed the issue of how to limit the memory consumed by the Stream of incoming sensor data, fixed up some data type issues in the JSON documents and added a RediSearch index so that we can perform different sorts of query and aggregation over the dataset.


In the 5th and final episode, I introduced a second Raspberry Pi Pico W running an LCD display and a small fan. I showed how we can control it using a Redis List to turn the fan on when the room needs cooling down.



Main photograph by Ibrahim Boran on Pexels.

Simon Prickett
Written by Simon Prickett
Hugely Experienced Developer Relations Leader.