Control devices on your Rasp Pi network with text messages
Red Alert
![© Lead Image © Valery Kachaev, 123RF.com © Lead Image © Valery Kachaev, 123RF.com](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/123rf_86620866_robot-sits-with-phone_valerykachaev_resized.png/726827-1-eng-US/123rf_86620866_Robot-sits-with-phone_ValeryKachaev_resized.png_medium.png)
© Lead Image © Valery Kachaev, 123RF.com
We show you how to control devices connected to Rasp Pi GPIO pins with text messages from an Android phone.
In places where Internet connections are not possible or too expensive, SMS text messaging can be a simple approach for monitoring and controlling your remote systems (Figure 1). Many of the mobile providers offer Internet of Things (IoT) packages for low data throughput, whereas you'd be looking at spending $1 to $5 per month for 1-5MB of data. From the hardware standpoint, many options come in either a Raspberry Pi HAT or a USB form factor (e.g., digital modem modules).
![](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/figure-1/726830-1-eng-US/Figure-1_large.png)
For prototyping, an Arduino phone and Node-RED [1] is a great way to jump-start your project.
Node-RED on Android
Node-RED is a graphical programming tool for IoT projects. Node-RED is installed in base Raspberry Pi images, but it can also be loaded on Linux, Windows, Mac OS, and Android systems. To load Node-RED on Android [2], you first need to load Termux [3], an Android terminal emulator app available at Google Play. After Termux is loaded, enter the following commands to install and run Node-RED:
apt update apt upgrade apt install coreutils nano nodejs npm i -g --unsafe-perm node-red node-red
Node-RED starts a graphical web interface (Figure 2) accessed by http://<phone_ip_address>:1880. Extra features can be added and removed from Node-RED by selecting Manage palette from the hamburger menu on the right (Figure 3). For this project, I needed terminux-api for texting support and bigtimer for scheduling.
![](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/figure-2/726833-1-eng-US/Figure-2_large.png)
![](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/figure-3/726836-1-eng-US/Figure-3_large.png)
For a basic setup (Figure 4), I used:
- 1 Android phone with Termux and Node-RED
- 1 Android phone for texting
- 1 Raspberry Pi running Node-RED
- 1 NO (normally open) PowerSwitch Tail II [4] connected to a light
![](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/figure-4/726839-1-eng-US/Figure-4_large.png)
Scanning for Text Messages
To create a simple text message project on the Android Node-RED system, I used the following components:
- A Big Timer node defines how often the SMS inbox is scanned.
- An SMS Inbox node reads in text messages. To get the last message; select a buffer limit of 1.
- A Get SMS Action function node is used with JavaScript to check for valid text messages (Listing 1).
- A tcp out node sends a TCP message to another Node-RED system. Remember to configure the Raspberry Pi's IP address and define a port number.
Listing 1
Get SMS Action Function
Figure 5 shows a basic logic setup to scan SMS periodically and pass the action by TCP. Without any configuration, the second Big Timer output node offers a cycle time of one scan per minute. The logic in Listing 1 interprets the latest text message and sends the required logic to the Raspberry Pi General Purpose I/O (GPIO) pins. The example logic uses the text message LIGHTS ON or LIGHTS OFF to control the output on GPIO pin 12.
![](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/figure-5/726842-1-eng-US/Figure-5_large.png)
The first time the code runs, you are prompted on the phone with Allow Termux: API to send and view SMS messages?. After you acknowledge this message, your Node-RED logic will run cleanly.
Reading TCP Inputs
Android phones cannot be connected directly to I/O devices, so I used TCP connections to pass commands between the Arduino phone and Raspberry Pi. Node-RED is preinstalled on most Raspberry Pi images, so no added installation is required.
On the Raspberry Pi Node-RED side (Figure 6), only a couple of nodes are required: a tcp in node, to read the incoming communications, and an rpi gpio out node, to set Raspberry Pi GPIO pins. The tcp in node should be configured as the same port (8888 in this case) as the tcp out node. Also for this example, the output payloads (in right pane, not shown) should be set to single and String.
![](/var/linux_magazin/storage/images/issues/2018/211/node-red-on-android/figure-6/726845-1-eng-US/Figure-6_large.png)
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.