Deploying OpenPLC
This document provides a step-by-step guide for setting up and running the OpenPLC runtime on ALPON X4 in a containerized environment.
This guide provides step-by-step instructions to run the OpenPLC runtime on the ALPON X4 micro-edge computer using Sixfab Connect. It covers containerizing the OpenPLC application, building the necessary environment, and deploying it efficiently. By following these steps, users can enable OpenPLC to interact with industrial devices and control systems with ease.
OpenPLC supports multiple industrial protocols such as Modbus, DNP3, and IEC 60870-5-104, making it suitable for a wide range of automation applications. ALPON X4, with its reliable LTE connectivity and edge computing capabilities, ensures seamless operation in industrial environments.
File Structure
Your OpenPLC containerized application has the following file structure:
Overview of Each File/Directory
Directory | Explanation |
---|---|
hardware_layers | Contains hardware-specific files for OpenPLC to interact with external devices. |
.donotdelete | Ensures this directory is preserved during builds. |
init.d/entrypoint.sh | The entry script for initializing the OpenPLC runtime environment inside the container. |
Dockerfile | Instructions to build the OpenPLC container. |
Step 1: Creating the Dockerfile
The Dockerfile defines the container environment for running OpenPLC. Here’s an example Dockerfile configuration to guide you, simply you can use this Dockerfile:
FROM bitnami/minideb:latest
#labeling
LABEL maintainer="[email protected]" \
version="V1.0.0" \
description="Open-PLC - IEC 61131-3 compatible open source PLC"
#version
ENV IOEXPERT_OPENPLC 1.0.0
#copy init.d files
COPY "./init.d/*" /etc/init.d/
#init atitude, install ssh, give user "root" a password
RUN apt-get update -y && apt-get install -y wget gnupg
RUN wget https://archive.raspbian.org/raspbian.public.key
RUN apt-key add raspbian.public.key && rm raspbian.public.key
RUN echo 'deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi' | tee -a /etc/apt/sources.list
RUN wget http://archive.raspberrypi.org/debian/raspberrypi.gpg.key
RUN apt-key add raspberrypi.gpg.key && rm raspberrypi.gpg.key
RUN echo 'deb http://archive.raspberrypi.org/debian/ buster main ui' >> /etc/apt/sources.list.d/raspi.list
RUN apt-get update -y
RUN apt-get install -y openssh-server
RUN echo 'root:root' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN mkdir /var/run/sshd
#install required packages and tools
RUN apt-get install -y git \
autotools-dev \
autoconf \
automake \
cmake \
bison \
flex \
build-essential \
python3 \
python3-pip \
wget \
libtool \
pkg-config \
binutils \
git \
sudo
#install wiringpi
RUN wget https://github.com/WiringPi/WiringPi/releases/download/3.10/wiringpi_3.10_arm64.deb -O /tmp/wiringpi_3.10_arm64.deb
RUN dpkg -i /tmp/wiringpi_3.10_arm64.deb
RUN rm /tmp/wiringpi_3.10_arm64.deb
#install required python software
RUN python3 -m pip install --upgrade pip --break-system-packages \
&& pip install --upgrade setuptools --break-system-packages
#clone OpenPLC source from git repo
RUN git clone https://github.com/thiagoralves/OpenPLC_v3.git
#copy customized hardware layers
COPY "./hardware_layers/*" "./OpenPLC_v3/webserver/core/hardware_layers/"
#compile and install OpenPLC
RUN cd OpenPLC_v3 \
&& ./install.sh docker
#SSH port 22, default OpenPLC port 8080 and Modbus TCP 502
EXPOSE 22 8080 502
#set the entrypoint
ENTRYPOINT ["/etc/init.d/entrypoint.sh"]
#set STOPSGINAL
STOPSIGNAL SIGTERM
Step 2: Creating the Entrypoint
The entrypoint.sh defines starts the OpenPLC runtime on container automatically.
#!/bin/bash +e
# catch signals as PID 1 in a container
# SIGNAL-handler
term_handler() {
echo "terminating ssh ..."
sudo /etc/init.d/ssh stop
exit 143; # 128 + 15 -- SIGTERM
}
# on callback, stop all started processes in term_handler
trap 'kill ${!}; term_handler' SIGINT SIGKILL SIGTERM SIGQUIT SIGTSTP SIGSTOP SIGHUP
echo "starting ssh ..."
sudo /etc/init.d/ssh start
echo "starting openPLC ..."
cd /OpenPLC_v3
sudo ./start_openplc.sh
# wait forever not to exit the container
while true
do
tail -f /dev/null & wait ${!}
done
exit 0
Step 3: Build and Push the Container to Sixfab Registry
After setting up the Dockerfile, use Docker’s build command to create the container image.
To deploy the container on ALPON X4, the image must be built on your personal computer for the ARM64 architecture.
docker buildx build --platform linux/arm64 -t openplc-container .
Push to Sixfab Registry:
- Log in to the Sixfab Connect platform, navigate to the Sixfab Registry page
- Click on + Add Container and follow the prompts to push container to Sixfab registry.
Manage and Deploy Applications
Visit the Manage & Deploy Applications page for all the necessary details on pushing your container image to the Sixfab Registry.
Step 4: Deployment
Once the container image is uploaded to the Sixfab Connect registry, deploy it as follows:
-
Go to the Application section of your asset on Sixfab Connect.
-
Click the + Deploy button to configure and deploy the container.
-
In the Deploy Container window, use the following settings:
-
Container Name: Enter the application name (e.g., "openplc-application").
-
Image: Select the OpenPLC container image and tag pushed to the Sixfab Registry.
-
Ports: Click "+ Add More" in the Ports section and add the following ports:
From To 30880 8080 30502 502 30522 22
-
Volumes: Click "+ Add More" in the Volumes section and configure the following volumes:
Read/Write Local Path Target Path Read/Write /dev/gpiomem /dev/gpiomem
-
Enable the Privileged option to grant the container elevated access.
-
Click the "+ Deploy" button to deploy.
-
Conclusion
Following these steps, you can successfully containerize and deploy the OpenPLC application on Sixfab Connect, enabling it to interact with hardware-specific layers. If issues arise, double-check the Dockerfile, verify registry credentials, and ensure necessary device access is granted in your Sixfab Connect settings.
Updated 3 days ago