As part of my job as the Principal Developer Advocate at Redis, I’ve been producing a live stream series in which I take a look at how Redis or related concepts can be used with a variety of Internet of Things devices. These streams go out most weeks on Thursdays on the Redis YouTube and Twitch channels – check out our team’s schedule for links to future events.
So far, I’ve mostly focussed on work with the Raspberry Pi family of devices as that’s what I have on hand. I’ve been working on different projects across multiple streams and wanted to bring them all together in one place here so that you can follow along. I’ve tried to describe each project and link to the source code I produced where relevant. I’ve been coding in Python, MicroPython (for the Raspberry Pi Pico) and Node.js.
This is an ongoing work in progress, so please check back here for updates! I’m also always interested in ideas for topics to cover - if I have or can get hold of the hardware, I’ll certainly try out your suggestions. Get in touch with me if you want to share ideas, or even appear as a guest to work on something together. My only real criteria are that we should be using Redis or talking about data structures that Redis implements.
Here’s the videos and links to the relevant GitHub repositories and articles. Enjoy!
Series Introduction
In the first video I introduce the Things on Thursdays concept and the first project – building a Bloom Filter using LEDs on a Raspberry Pi, and talking to it using redis-cli and the Redis wire protocol. Coding in Python, I build a simple fake Redis server that implements some of the Redis Set data type commands.
Resources:
- Visual Bloom Filter article.
- Source code for the original Visual Bloom Filter.
- Redis wire protocol.
- Redis Set commands.
Redis Compatible Visual Bloom Filter Project
Episode 1
In this episode, I walk through my pre-existing Visual Bloom Filter project that uses a Raspberry Pi and a Pimoroni Unicorn Hat LED matrix. The code is in Python.
Resources:
Episode 2
In this second episode, I combine the fake Redis server that I made in the “Series Introduction” stream with the Visual Bloom Filter project, creating a Visual Bloom Filter than can be used from any Redis client. I demonstrate usage with the redis-cli and Node Redis client for Node.js.
Resources:
- Source code for this project on GitHub
- Node Redis (Node.js client for Redis)
Redis Streams, Raspberry Pi Pico and MicroPython Project
Episode 1
Starting with a box fresh Raspberry Pi Pico W, I show you how to install MicroPython, connect to the device from Visual Studio Code and write Python code on it. I demonstrate how to connect to a wireless network, create a Redis database in the cloud and get started with streaming data to Redis.
Resources:
- Raspberry Pi Pico W
- MicroPython.
- The Pico-W-Go extension for Visual Studio Code.
- Free Redis database in the cloud.
- RedisInsight, a free GUI for managing and visualizing data in Redis.
- Source code for this project on GitHub.
Episode 2
In Episode 2, I’ve soldered headers to the Pi Pico W and connected it to a Seeed Studio Grove shield. This makes it easy to attach Grove compatible sensors. I replace the code from episode 1 that sent a stream of numbers to Redis with code that sends temperature and humidity values from a sensor attached to the Pi. I also demonstrate how to read this data from a Redis stream using Node.js.
Resources:
- Headers for Raspberry Pi Pico.
- Seeed Studio Grove Starter Kit for Raspberry Pi Pico.
- Source code for this project on GitHub.
Episode 3
In Episode 3, I add a light sensor to the existing temperature/humidity sensor on the Pi Pico W and stream data from that to Redis. I then look at how to modify the Node.js code that reads from the stream to remember how far through it was so that if it crashes or gets restarted it picks up from where it left off rather than at the start of the stream. I demonstrate 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.
Resources:
Episode 4
In Episode 4, I address the issue of how to limit the memory consumed by the Stream of incoming sensor data, fix up some data type issues in the JSON documents and add a RediSearch index so that we can perform different sorts of query and aggregation over the dataset.
Resources:
- The Redis XTRIM command.
- Storing, Querying and Indexing JSON at Speed - a course about RediSearch and JSON at Redis University.
- Source code for this project on GitHub.
Episode 5
In the 5th and final episode, I introduce a second Raspberry Pi Pico W running an LCD display and a small fan. I show how we can control it using a Redis List to turn the fan on when the room needs cooling down.
Resources:
- Redis Lists Explained - a fun YouTube explainer video.
- Redis Streams - a course about the Redis Streams data type at Redis University.
- Source code for this project on GitHub.
CheerLights with Redis Streams, MQTT and Python
In this project, I show how to show and track the current CheerLights color on a Pimoroni Unicorn Hat connected to a Raspberry Pi. I subscribe to a topic on the CheerLights MQTT server, put the latest color into a Redis Stream and consume it on the Pi.
Resources:
- CheerLights blog about this project
- Redis Streams - a course about the Redis Streams data type at Redis University.
- Source code for this project on GitHub.
Synchronized Counting with Redis Keyspace Notifications and a 7 Segment Display
Episode 1
This is a two week project in which I demonstrate how to count things using Redis, then synchronize multiple devices to display the current count. In the first week, I look at doing this for a web interface with Node.js and Express:
Resources:
- Source code for this project on Github
- TM1637 7 segment display - Arduino example
- Redis Keyspace Notifications
Episode 2
In the second part of this two week project, I implement an additional counter and display using arcade buttons, a TM1637 7 digit display and a Raspberry Pi 3.
Resources:
- Source code for this project on Github
- TM1637 7 segment display - Arduino example
- gpiozero library used for the arcade buttons
Wifi Setup with Raspberry Pi Pico W
One of the problems associated with making and distributing IoT devices to consumers is dealing with having the consumer connect the device to their own wifi network. This is especially problematic for headless devices that don’t have displays or input mechanisms. In this video, I look at how to use Pimoroni’s Phew! templating system and a captive access portal to provision wifi credentials to a Raspberry Pi Pico W. The code is in MicroPython.
Resources:
- Source code for this project on GitHub
- Pimoroni Phew! templating engine and webserver
- Captive Portal / Access point article from Kev McAleer
Node-RED with Redis
Episode 1
Node-RED is a low code graphical programming environment, often used to describe event driven IoT systems. In this first episode, I show how to build a flow that uses Redis Pub/Sub to model requests for room service at a hotel. The code is in JavaScript.
Resources:
Episode 2
In this episode, I show Node-RED running on a Raspberry Pi, move my Redis instance to the cloud, move connection secrets out of the Node-RED flow into an environment variable and attach an illuminated arcade button to the flow. The code is in JavaScript.
Resources:
- Source code for this project on GitHub
- Node-RED
- Node-RED extension for Redis
- 24mm Illuminated arcade button, blue - UK supplier (USA click here)
- Arcade button quick wires - UK supplier (USA click here)
More Redis Streams!
Episode 1
In this first of two episodes for a new project, I demonstrate how Redis Streams Consumer Groups work. We also look at how to determine the lag for a given consumer group using features added in Redis 7.
Resources:
- Source code for this project on GitHub
- RU202: Redis Streams, a free course at Redis University
Episode 2
In this second of two episodes of his weekly series, I’ll show you how to display a Redis Streams consumer group lag using MicroPython, a Raspberry Pi Pico W and some LEDs…
- Source code for this project on GitHub
- MicroPython/Redis/Pi Pico W boilerplate source code
- Source code for testing the LEDs
Plane Spotting with Redis and Node.js
Episode 1
It’s the start of another Redis IoT project! In this episode I demonstrate how to figure out what planes are passing by using a software defined radio USB stick, Redis and Node.js. I cover receiving data from the radio, decoding it, and storing it in Redis Hashes.
Episode 2
In the second episode, I start adding detail to the data obtained from the radio by calling the FlightAware API. I show how to use Redis as a queue to schedule calls to the API and how to use caching to prevent repeated calls that could cost money!
- Source code for this project on GitHub
- FlightAware API - note this is a paid API
Episode 3
It’s time to add a search index over our flight data in Redis. In this episode, I show how to use the search capabilities of Redis Stack to query the flight data in different ways - we’ll use this in the next episode to write a notifier component.
Episode 4
Writing the notifier component… I look at writing a RediSearch aggregate query to find the most recently updated widebody aircraft flight passing by, then use Redis Pub/Sub to notify front ends of its details. In the next episode I’ll build out some front ends to display this data.
Episode 5
In this episode I finally use the big mechanical flip dot bus display that sits behind me on stream, and build a flight notification component with it. I demonstrate the use of Redis Pub/Sub and show code in Node.js running on a Raspberry Pi 3.
Episode 6
This is the final episode for this project. I use a Pimoroni Badger 2040W and MicroPython to build a second flight display that consumes a Redis Stream.
What’s Next?
This is an ongoing series of projects, don’t forget to check out the Redis Developer Relations streaming schedule to see when the next episode will be. I’ll update this page shortly after each episode airs.
Main image: “Person using Appliance” by Alexander Dummer on Pexels.