qbee

Hi,
I have automated an OpenPLC install on a Raspberry Pi and also build a CI/CD pipeline for it. While doing that I learned a lot and here I want to share some of my findings and concepts. Thanks a lot to Thiago who helped me with some crucial information.

- if you use the "Hello_World.st" example on a RPI you have to change the pin to handle the button properly. Please use %IX0.2, %IX0.0 has an internal pull-up resistor which prevents this from working

- the webserver also starts the PLC program and runtime. Check the "Start OpenPLC in RUN Mode" in settings and then it will always start your defined program immediately after start-up.

- there is a shell script called

compile_program.sh
in 
~/OpenPLC_v3/webserver/scripts
Call this from folder "webserver" like this
~/OpenPLC_v3/webserver/scripts/compile_program.sh blank_program.st
This will recompile your PLC program. Use "systemctl stop openplc" and "systemctl start openplc" to make the newly compiled program active. 

- be aware that if you compile manually the only way to get your new program to auto-start or start through "systemctl start openplc" is to call it the same name as the one that you have defined in your programs section. For example you also call it blank_program and change the .st file accordingly. 
Screenshot 2021-09-29 at 14.28.57.png 

- I wanted to get maximum flexibility in being able to automate OpenPLC. I solved this by configuring one OpenPLC instance. I selected the hardware platform, autostart, the program and my user settings and passwords. Then I saved this. All data is now available in a mysql-lite database. This is basically the file 
~/OpenPLC_v3/webserver/openplc.db
In my automation I overwrite the existing file on the newly installed device with this one and thus create identical pre-configured OpenPLC devices.

- As a next step in the automation I use the compile command in a script. Anytime I play out a new .st file I run this script. It stops the OpenPLC webserver, compiles the new .st file and then starts the server again. This causes OpenPLC to reload the new version of the .st script and run it. Please see the script below:
#!/usr/bin/env bash 
cd /home/pi/OpenPLC_v3/webserver
systemctl stop openplc
/home/pi/OpenPLC_v3/webserver/scripts/compile_program.sh blank_program.st
systemctl start openplc
exit 0

I hope this gives you some ideas for building cool projects. I have made a blog post called "Raspberry Pi as PLC with OpenPLC" which is about automatically installing OpenPLC on a fleet of Raspberry Pis and accessing these through a VPN.

The second post is called "Automated PLC deployment with CI/CD" which is about rolling out new PLC program files on any number of devices as well as building a continuous integration / continuous delivery pipeline utilizing Github, Github Runners and qbee. In addition, I have pointed out some options about templating the *.st files. But I am not that deep into PLCs to understand if this is a valid use case.

Reply 2 0
Reply