Redis in-memory storage
Arduino Redis Library
The Arduino ESP8266 family of modules can send sensor data to a Redis server. To install the latest Redis version, use the Arduino Library Manager (Figure 3) and the DHT temperature sensor library.
Infrared flame sensors measure IR light generated by a flame, which makes them great for indoor projects; however, for outdoor projects, you will need to add some shielding against ambient light. The flame scanner has both an analog (A0) and a digital (D0) connection. The analog A0 pin returns the flame intensity, where 1024=no flame and 0=hot flame. The digital D0 connection returns a 1 for no flame and 0 for a flame.
For Arduino code (Listing 2), three values are published to a remote Redis server: roomtemp
, flamestatus
, and flameintensity
.
Listing 2
Redis_flame.ino
The redis-cli psubscribe
command can verify that the Arduino values are being received at the Redis server. For example, Listing 3 shows how to subscribe to the roomtemp
value.
Listing 3
Subscribing to a Value
Node-RED and Redis
Node-RED [4] is a visual programming environment that lets you create applications by dragging and dropping nodes onto a code flow window. Logic flows are then created by connecting the different nodes together.
Node-RED has been preinstalled on Raspbian Jesse since the November 2015 release, but Node-RED can be installed on Windows, macOS, and other Linux distros, as well, and you can find instructions online [5] for installing and running Node-RED on your specific system.
To install the Redis components, select the Manage palette option from the hamburger menu on the right (Figure 4), then search for redis and install node-red-contrib-redis. If you haven't already installed the dashboard library, then search for and install node-red-dashboard.
For my Node-RED flame scanner example, I'll look at subscribing to the three items (Figure 5) and show them on a web dashboard. The logic will require the following nodes: three redis in
, two chart
, and one text
.
To configure the redis in
node, double-click on the node to get the edit dialog (Figure 6), so you can configure the Redis server and define the topic to which to subscribe. For this project, I have three topics: roomtemp, flameintensity, and flamestatus. Finally, the method needs to be set to SUBSCRIBE.
Next, edit the chart
(Figure 7) and text
nodes. The key here is to create and define the dashboard group. Time spans, labels, colors, and sizing are also configured in this dialog box.
After the logic is complete, hit the Deploy button on the right side of the menubar to run the logic. The Node-RED dashboard user interface is accessed at http://<ipaddress>:1880/ui. Figure 8 shows my Node-RED dashboard with the flame scanner.
Weather Station Webcam
A Raspberry Pi can make an excellent weather station node. In addition to sensors (e.g., temperature and humidity), you can include webcams images (Figure 9).
For my test, I used low-cost USB webcams, but you can find some excellent Pi cameras, too. Images are generated with the fswebcam
command-line tool, which you can install with:
sudo apt-get install fswebcam
The Python script in Listing 4 calls fswebcam
and uploads an image to a Redis server. The webcam image is passed to the Redis server as a large binary variable using the SET method.
Listing 4
image_2_redis.py
For my weather station example, the Python code periodically reads the temperature and humidity sensors and then takes a picture. This data was SET into a Redis server as temp1
, humdity1
, and webcam1
.
I loaded the Redis server on the same hardware as my PHP/Apache web server, which allowed single-line testing with the redis-cli
tool. Once I was happy with the results, I moved the command-line syntax directly into my PHP script.
To pull the image data from Redis, I issue a redis-cli
command to GET raw webcam1
binary data and write it to a JPEG file. Listing 5 is the complete PHP example, and Figure 10 shows a sample weather station web page.
Listing 5
redis1.php
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.