Pyro – Networking made simple
One for All

© Lead Image © FernandoCortes, 123RF.com
Pyro allows multiple hardware devices to interact as if they are all on a local machine by hiding the networking.
Several of my projects have required multiple Raspberry Pis working in tandem to accomplish an ultimate goal, such as driving multiple independent displays or integrating a device with a dedicated controlling computer. Sometimes the setup had unique hardware (e.g., sensors); other times distance made it easier to use a remote system and WiFi rather than a lot of cabling. Although you can choose from many approaches to distributed technology, here, I'll focus on the Python remote objects (Pyro) library.
My most recent project that fell in this category was a set of scoreboards for my church's Vacation Bible School. I integrated four large LCD TVs into the set design (Figure 1) and dedicated a Raspberry Pi to each one. Also, I wanted the ability to update each team's score in real time from a centralized console. To accomplish this, I wrote the code for the scoreboards and their controller in Python and communicated between the different screens with Pyro [1].

Each Pi runs a Raspbian Lite distro and a custom Python script. After flashing the SD card with Raspbian, the only special configuration was to connect to the WiFi network and install the Pyro library. Python is installed by default with Raspbian, and the PyGame library, also a default, provided the graphics. PyGame can drive the Pi framebuffer directly, so the graphical desktop isn't needed.
Elements of a Pyro System
To begin, I'll look at the three parts of a Pyro system and the network individually. Usually, all parts run on separate hardware, but that's not a requirement; they will happily coexist on a single computer for testing, or if it best fits your application. Figure 2 shows how a Pyro network is laid out.
Network
For Pyro to work, physical devices must be able to talk across the network. As long as everything is on the same router (either wired or WiFi), you should be in good shape. To check for basic connectivity between devices, use ip a
and ping
(see the "Checking Network Connectivity" box for more details). If everything is running on a single computer, you're also in good shape.
Checking Network Connectivity
First you'll need to know the IP address of the device on which your daemon will run. You might already know this information if you've logged in over SSH, but, if not, open a terminal on the "remote" system and type ip a
. Then look through the output for inet followed by an IP address. Note that entry 0 is usually localhost, so you're looking for an address that doesn't start with
127.0 ….
Once you have the IP address, go back to your "controller" computer and open a terminal there. You should be able to type
ping <IP address from above>
and start seeing replies. If not, make sure that both computers are on the same network or router. For larger networks, you might also need to adjust your subnet mask.
A mask of 255.255.255.0 requires the first three numbers of the address to be the same. You can change the mask to 255.255.0.0 and require only the first two numbers to be the same. Make this change, reboot both systems, and try your ping again.
Daemons
In Linux, daemons are processes that run in the background to take care of services like printing, checking email, serving web pages, and myriad other tasks. Pyro uses the term "daemon" to describe its workers. A Pyro daemon provides data (class properties) and things it can do (class methods) on the Pyro network. The Python that you write in each daemon makes the provided task happen. Pseudocode looks something like:
@Pyro4.expose def ringBell(): bellPin = 17 GPIO.out ( bellPin , True ) time.wait ( 1 ) GPIO.out ( bellPin , False ) Return "Bell rang for 1 second"
If this looks familiar, you're right! The code to implement your task works just like any other Python code you might write to accomplish a task. The only difference is the decorator on the first line, which lets Python know that it is a Pyro function accessible to the outside world. More on that later.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
News
-
New Linux Ultrabook from TUXEDO Computers
TUXEDO Computers has released a new 15" Ultrabook running Linux.
-
GNOME 43 To Bring Some Exciting New Features
GNOME 43 is getting close to the first alpha development release and it promises to add one particular feature that should be exciting to several users.
-
KaOS 2022.06 Now Available With KDE Plasma 5.25
The newest iteration of KaOS Linux not only adds the latest KDE Plasma desktop but sets LibreOffice as the default.
-
Manjaro 21.3.0 Is Now Available
Manjaro “Ruah” has been released and includes the latest Calamares installer, GNOME 42, and much more.
-
SpiralLinux is a New Linux Distribution Focused on Simplicity
A new Linux distribution, from the creator of GeckoLinux, is a Debian-based operating system with a focus on simplicity and ease of use.
-
HP Dev One Linux Laptop is Now Available for Pre-Order
The System76/HP collaboration Dev One laptop, geared toward developers, is now available for pre-order.
-
NixOS 22.5 Is Now Available
The latest release of NixOS with a much-improved package manager and a user-friendly graphical installer.
-
System76 Teams up with HP to Create the Dev One Laptop
HP and System76 have come together to develop a new laptop, powered by Pop!_OS and aimed toward developers.
-
Titan Linux is a New KDE Linux Based on Debian Stable
Titan Linux is a new Debian-based Linux distribution that features the KDE Plasma desktop with a focus on usability and performance.
-
Danielle Foré Has an Update for elementary OS 7
Now that Ubuntu 22.04 has been released, the team behind elementary OS is preparing for the upcoming 7.0 release.