Pyro – Networking made simple
One for All
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
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
-
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.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs