{"id":17967716,"url":"https://github.com/simonprickett/raspberry-pi-pico-redis","last_synced_at":"2025-03-25T08:31:25.322Z","repository":{"id":88191110,"uuid":"533937504","full_name":"simonprickett/raspberry-pi-pico-redis","owner":"simonprickett","description":"Experiments with Redis on the Raspberry Pi Pico","archived":false,"fork":false,"pushed_at":"2023-01-26T19:11:24.000Z","size":64,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-19T23:52:48.679Z","etag":null,"topics":["javascript","micropython","nodejs","raspberry-pi-pico-w","redis","streaming-data"],"latest_commit_sha":null,"homepage":"https://simonprickett.dev/things-on-thursdays-livestreams/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonprickett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-07T20:49:07.000Z","updated_at":"2024-11-06T02:55:03.000Z","dependencies_parsed_at":"2023-05-09T21:31:31.449Z","dependency_job_id":null,"html_url":"https://github.com/simonprickett/raspberry-pi-pico-redis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonprickett%2Fraspberry-pi-pico-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonprickett%2Fraspberry-pi-pico-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonprickett%2Fraspberry-pi-pico-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonprickett%2Fraspberry-pi-pico-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonprickett","download_url":"https://codeload.github.com/simonprickett/raspberry-pi-pico-redis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245426274,"owners_count":20613321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","micropython","nodejs","raspberry-pi-pico-w","redis","streaming-data"],"created_at":"2024-10-29T14:09:18.098Z","updated_at":"2025-03-25T08:31:25.313Z","avatar_url":"https://github.com/simonprickett.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Experiments with Raspberry Pi Pico W and Redis\n\n## Introduction\n\nThis repository contains [MicroPython](https://micropython.org/) and [Node.js](https://nodejs.org/en/) code to support my series of livestream videos where I build out a system that sends data from sensors into Redis for processing.  I'll add more to this README as the project progresses!\n\n## Videos\n\n* [Episode 1](https://www.youtube.com/watch?v=8Q3jK5CAfNQ), introducing the Pi Pico, installing MicroPython, creating a Redis Stack instance in the cloud and sending data to it with Redis Streams.  Visualizing data with RedisInsight.\n* [Episode 2](https://www.youtube.com/watch?v=TQlsvxD6zRM), adding headers and a Grove shield to the Raspberry Pi Pico W, modifying the MicroPython code to read temperature and humidity values from a sensor and send them to Redis, reading those values from Redis using a Node.js application.\n* [Episode 3](https://www.youtube.com/watch?v=0vw_vhouca8), added a light sensor, looked at how to modify the Node stream reading code so that it remembers where it was in the Stream when restarted and demonstrated how to use a Sorted Set to model 1:many relationships.  We ended by storing sensor data per room in JSON documents in Redis.\n* [Episode 4](https://www.youtube.com/watch?v=MuaJzyUHmx0), dealt with the issue of trimming the incoming data Stream, added last modified timestamps and sorted out some data type mismatches then added a RediSearch index and demonstrated some queries over the data stored in JSON documents.\n* [Episode 5](https://www.youtube.com/watch?v=ypQ4bjiKeRo): the final episode for this project.  Added a second Raspberry Pi Pico W with a fan and display attached, used a Redis List to sent it commands to use the fan to lower the room temperature after the temperature has exceeded a threshold for a certain time.\n\n## Getting Started\n\nTo use this repository you will need:\n\n* [Raspberry Pi Pico W](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html).  This project uses two of these.\n* [Headers](https://shop.pimoroni.com/products/pico-header-pack?variant=32374935715923) for each Raspberry Pi Pico W - you'll need to solder these onto the devices in order to be able to attach the Grove shield.\n* Your wifi credentials (SSID and password).\n* [MicroPython runtime for Pico W](https://www.raspberrypi.com/documentation/microcontrollers/micropython.html) (install this on the Pico W using the drag and drop method).\n* [Node.js](https://nodejs.org/en/download/).\n* [A cloud Redis Stack instance](https://redis.com/try-free/) (free).  Alternatively, you'll need to be able to run Redis Stack somewhere on your local network that both your development machine and a Raspberry Pi Pico W can reach it via an IPv4 address or hostname.  It's easiest to just do this with Redis Cloud :)\n* The code in this repository.\n* You can use the [Thonny IDE](https://thonny.org/) to edit the code and load it on the Pi Pico W, personally I prefer [VSCode](https://code.visualstudio.com/) with [this extension](https://marketplace.visualstudio.com/items?itemName=paulober.pico-w-go) to manage the Pico W.  This also allows you to use a single IDE to work with both the MicroPython and Node.js codebases.\n* If you want to use the exact sensor kit and Grove shield that I am using, you'll need the [Grove Starter Kit for Raspberry Pi Pico](https://www.seeedstudio.com/Grove-Starter-Kit-for-Raspberry-Pi-Pico-p-4851.html) from Seeed Studio.  This project uses two Grove shields, one for each Raspberry Pi Pico W device.\n\n### Create the Initial Data Fixtures\n\nThis project relies on some data setup tasks that need to be completed before running the Node.js code.  Follow the instructions in [create_initial_data_fixtures.md](create_initial_data_fixtures.md) before starting the code.\n\n### MicroPython\n\nThe MicroPython code requires some secrets management... don't commit secrets (passwords etc) to source control, instead create a file `secrets.py` in the `micropython/temp-humidity-light-sensor` and `micropython/fan-controller` folders... it should look like this:\n\n```python\nWIFI_SSID = \"wifi network name here\"\nWIFI_PASSWORD = \"wifi password here\"\nREDIS_HOST = \"hostname.of.your.redis.server\"\nREDIS_PORT = 6379 (or whatever port you have Redis running on)\nREDIS_PASSWORD = \"redis password here\"\n```\n\nThe Redis client used in this project is in the file `picoredis.py`.  It is [PicoRedis](https://github.com/SpotlightKid/picoredis) by [Christopher Arndt](https://chrisarndt.de/) and is MIT licensed.\n\nWatch the first video to see how to get the code for the temperature / humidity / light sensor up and running on the device, and how to create a Redis Stack instance in the cloud.  In the second video, you'll learn how to add a temperature/humidity sensor to the device and send data from it to a Redis Stream.  Setup and code for the fan controller component is covered in the 5th video.\n\nI'm using Seed Studio's [examples from their wiki](https://wiki.seeedstudio.com/Grove_Shield_for_Pi_Pico_V1.0/) for the code that talks to the various Grove sensors in their kit.\n\n### Node.js\n\nThe Node.js code also uses the same secrets, but gets their values from a `.env` file  Create a file that looks like this and save it in the `node` folder as `.env`:\n\n```\nREDIS_HOST = \"hostname.of.your.redis.server\"\nREDIS_PORT = 6379 (or whatever port you have Redis running on)\nREDIS_PASSWORD = \"redis password here\"\n```\n\nOptionally, if you're using a user name and password to connect to Redis, you can also set:\n\n```\nREDIS_USER = \"your.redis.user.name\"\n```\n\nTo set up and run the Node.js Stream consumer code you'll first need to install the dependencies (this code uses the [Node-Redis](https://github.com/redis/node-redis) client and [dotenv](https://www.npmjs.com/package/dotenv) package) and finally start it:\n\n```bash\ncd node\nnpm install\nnpm run consumer\n```\n\nThe code connects to Redis, and reads data from the stream that the MicroPython code is writing to.  See the [second](https://www.youtube.com/watch?v=TQlsvxD6zRM) and [third](https://www.youtube.com/watch?v=0vw_vhouca8) videos for more details.  It also instructs the fan component to turn on the fan when a room is above a certain temperature for a while.  This is covered in the [fifth video](https://www.youtube.com/watch?v=ypQ4bjiKeRo) and uses a Redis List.\n\nTo trim the Stream periodically, deleting entries that are more than an hour old, run the trimmer component like this:\n\n```bash\ncd node\nnpm install\nnpm run trimmer\n```\n\nThe code connects to Redis, and uses the `XTRIM` command to remove stream entries that are over an hour old.  Note that to do this is uses the `MINID` trimming strategy which became available in Redis 6.2. See the [fourth](https://www.youtube.com/watch?v=MuaJzyUHmx0) video for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonprickett%2Fraspberry-pi-pico-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonprickett%2Fraspberry-pi-pico-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonprickett%2Fraspberry-pi-pico-redis/lists"}