
Developing an Edge Control Application with Docker on the EG5120
|
|
Time to read 5 min
|
|
Time to read 5 min
This hands-on tutorial provides a step-by-step guide for developers on how to create a simple edge control application using Python and Docker on the Robustel EG5120. We will build a complete "sense-decide-act" loop that reads a physical input and triggers a physical output on the gateway. This guide demonstrates the power of a modern, open platform, showing how standard IT tools can be used to build and deploy reliable industrial edge control solutions with unprecedented speed and flexibility.
Developing for an open, Debian-based edge gateway like the EG5120 is almost identical to developing for a standard Linux server, radically lowering the barrier to entry.
Docker is the key to portability and reliability, allowing you to package your Python application and its dependencies into a container that runs perfectly on the edge device.
The EG5120's industrial I/O (like DI/DO) can be easily controlled from within a Docker container using standard Linux libraries, enabling true physical edge control.
This container-based workflow is the foundation for a modern, scalable DevOps practice for the industrial edge.
You've read the theory. You understand the architecture. Now it's time to write some code. It's time to build your first real edge control application. For many developers new to the industrial space, this can feel intimidating. Do you need to learn proprietary programming languages or complex embedded toolchains?
Let's be clear: with a modern, open-platform edge gateway, the answer is a resounding no. You can use the tools you already know and love.
This guide will walk you through the entire developer workflow. We'll write a simple Python application, package it into a Docker container, and deploy it to a Robustel EG5120 to perform a real-world control task.
Our edge control application will be simple but complete:
This creates a simple remote switch. You could connect a physical button to DI0 and an alarm light to DO0.
First, let's write our control script. The 'aha!' moment for many developers is seeing that controlling the EG5120's industrial I/O is as simple as reading and writing to files in the Linux file system, thanks to the standard GPIO Sysfs interface.
Create a file named app.py
:
Python
import time import os # Define the GPIO pins for DI0 and DO0 on the EG5120 DI0_PIN = 460 DO0_PIN = 464 DO0_PATH = f"/sys/class/gpio/gpio{DO0_PIN}/value" def setup_gpio(): # Export GPIOs if not already exported if not os.path.exists(f"/sys/class/gpio/gpio{DI0_PIN}"): with open("/sys/class/gpio/export", "w") as f: f.write(str(DI0_PIN)) if not os.path.exists(f"/sys/class/gpio/gpio{DO0_PIN}"): with open("/sys/class/gpio/export", "w") as f: f.write(str(DO0_PIN)) # Set directions with open(f"/sys/class/gpio/gpio{DI0_PIN}/direction", "w") as f: f.write("in") with open(f"/sys/class/gpio/gpio{DO0_PIN}/direction", "w") as f: f.write("out") def main(): print("Starting Edge Control Application...") setup_gpio() try: while True: with open(f"/sys/class/gpio/gpio{DI0_PIN}/value", "r") as f: di_state = int(f.read().strip()) if di_state == 1: print("DI0 is HIGH, turning DO0 ON") with open(DO0_PATH, "w") as f: f.write("1") else: print("DI0 is LOW, turning DO0 OFF") with open(DO0_PATH, "w") as f: f.write("0") time.sleep(0.5) # Poll every 500ms except KeyboardInterrupt: print("Stopping application.") # Clean up by turning the output off with open(DO0_PATH, "w") as f: f.write("0") if __name__ == "__main__": main()
Now, we'll create a simple recipe to package this script. Create a file named Dockerfile
in the same directory:
Dockerfile
# Use a lightweight Python base image FROM python:3.9-slim # Set the working directory inside the container WORKDIR /app # Copy the Python script into the container COPY app.py . # Command to run when the container starts CMD ["python", "app.py"]
From your terminal in the same directory, build the image and push it to a container registry like Docker Hub. (Replace your-username
with your Docker Hub username).
Bash
# Build the image docker build -t your-username/edge-control-app:v1 . # Push the image to the registry docker push your-username/edge-control-app:v1
Now for the final step. SSH into your EG5120.
docker pull your-username/edge-control-app:v1
--privileged
flag is important as it gives the container access to the hardware GPIO pins. docker run --privileged -d --name my-control-app your-username/edge-control-app:v1
That's it! Your container is now running in the background. Your edge control application is live. You can view its logs with docker logs my-control-app
. When you apply a voltage to the DI0 terminal, the DO0 terminal will switch on. You have built a complete, containerized, real-time control loop.
This tutorial demonstrates the revolutionary simplicity of modern industrial development. What once required complex, proprietary embedded toolchains can now be accomplished with standard, open-source IT tools that millions of developers already know.
By choosing an open platform like the Robustel EG5120 that embraces Linux and Docker, you are not just buying hardware. You are unlocking the full creative potential of your software team to build powerful, scalable, and reliable edge control solutions faster than ever before.
Further Reading:
The Software Stack for Edge Control: OS, Containers, and Runtimes
A 4-Step Blueprint for Your First Edge Control Project
Calculating the ROI of an Edge Control System: A Guide for Managers
A1: By default, Docker containers are sandboxed and cannot access the host device's hardware for security reasons. The --privileged
flag grants the container extended permissions, specifically allowing it to access the /sys/class/gpio
directory to directly monitor and control the gateway's physical DI/DO pins.
A1: By default, Docker containers are sandboxed and cannot access the host device's hardware for security reasons. The --privileged
flag grants the container extended permissions, specifically allowing it to access the /sys/class/gpio
directory to directly monitor and control the gateway's physical DI/DO pins.
A3: Yes. Similar to the GPIO pins, you can map the host's serial device (e.g., /dev/ttyAP0
) into the container when you run it. This gives your containerized application direct access to communicate with any connected Modbus or other serial-based industrial equipment.