From e1143f6586740cd869b6fcb8fadfbc93172d0817 Mon Sep 17 00:00:00 2001 From: gustaf71 Date: Tue, 25 Mar 2025 19:09:35 +0100 Subject: [PATCH 1/3] Update debian, install wiringPi Remove pigpio api, change wiringpi version Remove pigpio api, add wiringPi api Remove pigpio api, add wiringPi api --- Dockerfile | 19 +++++++++++- background_installer.sh | 22 ++------------ .../core/hardware_layers/raspberrypi.cpp | 29 +++++++++---------- webserver/scripts/compile_program.sh | 6 ++-- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5ef5c4d..bfd8180 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:bullseye-20240722 +FROM debian:stable COPY . /workdir @@ -8,6 +8,23 @@ RUN mkdir /docker_persistent VOLUME /docker_persistent +# get git, wget, dpkg-dev and gettext +RUN apt update && apt install -y \ + git \ + wget \ + dpkg-dev \ + gettext + +# clone WiringPi +RUN git clone https://github.com/WiringPi/WiringPi.git /api + +# change the directory +WORKDIR /api + +# build wiringPi and install it +RUN ./build debian \ + && apt install -y ./debian-template/wiringpi_3.14_arm64.deb + RUN ./install.sh docker \ && touch /docker_persistent/mbconfig.cfg \ && touch /docker_persistent/persistent.file \ diff --git a/background_installer.sh b/background_installer.sh index 9db0d1a..dae1784 100755 --- a/background_installer.sh +++ b/background_installer.sh @@ -1,7 +1,7 @@ #!/bin/bash OPENPLC_DIR="$PWD" SWAP_FILE="$OPENPLC_DIR/swapfile" -WIRINGPI_VERSION="3.4" +WIRINGPI_VERSION="3.14" # Support RPi 1..5, CM5, CM5(L), Pi500, GCLK (Generic Clock) for RPi5 is not supported. VENV_DIR="$OPENPLC_DIR/.venv" function print_help_and_exit { @@ -73,24 +73,6 @@ function install_wiringpi { ) || fail "Failed to install wiringpi." } -function install_pigpio { - echo "[PIGPIO]" - echo "Trying distribution package..." - sudo apt-get install -y pigpio && return 0 - - echo "Falling back to direct download..." - local URL="https://github.com/joan2937/pigpio/archive/master.zip" - ( - set -e - wget -c "$URL" - unzip master.zip - cd pigpio-master - make - sudo make install - rm -f master.zip - ) -} - function install_wiringop { echo "[WIRINGOP]" local URL="https://github.com/orangepi-xunlong/wiringOP/archive/master.zip" @@ -369,7 +351,7 @@ elif [ "$1" == "docker" ]; then elif [ "$1" == "rpi" ]; then echo "Installing OpenPLC on Raspberry Pi" linux_install_deps sudo - install_pigpio + install_wiringpi install_py_deps install_all_libs sudo install_systemd_service sudo diff --git a/webserver/core/hardware_layers/raspberrypi.cpp b/webserver/core/hardware_layers/raspberrypi.cpp index 2c25eab..73c8fb2 100755 --- a/webserver/core/hardware_layers/raspberrypi.cpp +++ b/webserver/core/hardware_layers/raspberrypi.cpp @@ -28,7 +28,8 @@ #include #include #include -#include +#include +#include #include #include "ladder.h" @@ -39,7 +40,7 @@ #define MAX_INPUT 14 #define MAX_OUTPUT 11 -#define MAX_ANALOG_OUT 1 +#define MAX_ANALOG_OUT 1 /********************I/O PINS CONFIGURATION********************* * A good source for RaspberryPi I/O pins information is: @@ -50,15 +51,15 @@ ****************************************************************/ //inBufferPinMask: pin mask for each input, which //means what pin is mapped to that OpenPLC input -int inBufferPinMask[MAX_INPUT] = { 2, 3, 4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26 }; +int inBufferPinMask[MAX_INPUT] = { 8, 9, 7, 0, 2, 3, 12, 13, 14, 21, 22, 23, 24, 25 }; //outBufferPinMask: pin mask for each output, which //means what pin is mapped to that OpenPLC output -int outBufferPinMask[MAX_OUTPUT] = { 14, 15, 23, 24, 25, 8, 7, 12, 16, 20, 21 }; +int outBufferPinMask[MAX_OUTPUT] = { 15, 16, 4, 5, 6, 10, 11, 26, 27, 28, 29 }; //analogOutBufferPinMask: pin mask for the analog PWM //output of the RaspberryPi -int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 }; +int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 1 }; //----------------------------------------------------------------------------- // This function is called by the main OpenPLC routine when it is initializing. @@ -66,30 +67,29 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 }; //----------------------------------------------------------------------------- void initializeHardware() { - gpioInitialise(); + wiringPiSetup(); //piHiPri(99); //set pins as input for (int i = 0; i < MAX_INPUT; i++) { - gpioSetMode(inBufferPinMask[i], PI_INPUT); + pinMode(inBufferPinMask[i], INPUT); if (i != 0 && i != 1) //pull down can't be enabled on the first two pins { - gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_DOWN); //pull down enabled + pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled } } //set pins as output for (int i = 0; i < MAX_OUTPUT; i++) { - gpioSetMode(outBufferPinMask[i], PI_OUTPUT); + pinMode(outBufferPinMask[i], OUTPUT); } //set PWM pins as output for (int i = 0; i < MAX_ANALOG_OUT; i++) { - gpioSetMode(analogOutBufferPinMask[i], PI_ALT5); - gpioSetPWMrange(analogOutBufferPinMask[i], 1024); + pinMode(analogOutBufferPinMask[i], PWM_OUTPUT); } } @@ -99,7 +99,6 @@ void initializeHardware() //----------------------------------------------------------------------------- void finalizeHardware() { - gpioTerminate(); } //----------------------------------------------------------------------------- @@ -114,7 +113,7 @@ void updateBuffersIn() //INPUT for (int i = 0; i < MAX_INPUT; i++) { - if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = gpioRead(inBufferPinMask[i]); + if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]); } pthread_mutex_unlock(&bufferLock); //unlock mutex @@ -132,13 +131,13 @@ void updateBuffersOut() //OUTPUT for (int i = 0; i < MAX_OUTPUT; i++) { - if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]); + if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]); } //ANALOG OUT (PWM) for (int i = 0; i < MAX_ANALOG_OUT; i++) { - if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64)); + if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64)); } pthread_mutex_unlock(&bufferLock); //unlock mutex diff --git a/webserver/scripts/compile_program.sh b/webserver/scripts/compile_program.sh index c5f8379..63fc7fa 100755 --- a/webserver/scripts/compile_program.sh +++ b/webserver/scripts/compile_program.sh @@ -143,9 +143,9 @@ elif [ "$OPENPLC_PLATFORM" = "rpi" ]; then ./glue_generator echo "Compiling main program..." if [ "$OPENPLC_DRIVER" = "sequent" ]; then - g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w - else - g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w + g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w + else + g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files" From 8a61881fbc911cc6104abc200abbddf322c7812b Mon Sep 17 00:00:00 2001 From: gustaf71 Date: Wed, 26 Mar 2025 02:52:57 +0100 Subject: [PATCH 2/3] deleted: .DS_Store, this file is part of macOS modified: Dockerfile, update the file for wiringPi --- .DS_Store | Bin 6148 -> 0 bytes Dockerfile | 36 ++++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7a8c886abcc9d0ad1b82428cc043c8506611441b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T32AO(;SS3hF7~Rj_I4k9Y}HU%-eSRBA$t24hy5v^j)A?&<^SgZMno z>~5vD^(ta_VCLJMo!Ky7!fpltSa;O70jdCCpb{2LG)simNf)G`JVit%_K5v7e)2=^ zFT`rc-(-N^T?s~zKmZ}kzQ1?>DGcJIR{LOuwPI<#Y?O_PapT_e)J?o(6nDMh70u2$ z5B=%b^Dlxy+N*9J^COiW{I@8IaH_Ygit{6$j9@S78|p>PVXIGCwv><*)lM|bF@3=>iq zfDbX+A&kk+e6?@CUiD6vwc0H#y3-Uz+f;P(@Nll^XIb5kMH4AYN}DTQZlbMbKr^uN z45;(dsH{8_ngGp!W?-HHIv*@lLPudPQ5+p;L<@jOzmY<4OuYoeaqN6aE Sh#nOEBOqwdMl diff --git a/Dockerfile b/Dockerfile index bfd8180..60b0371 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ -FROM debian:stable +FROM debian:stable-20241111 COPY . /workdir WORKDIR /workdir -RUN mkdir /docker_persistent +RUN mkdir /persistent -VOLUME /docker_persistent +VOLUME /persistent # get git, wget, dpkg-dev and gettext RUN apt update && apt install -y \ @@ -25,23 +25,27 @@ WORKDIR /api RUN ./build debian \ && apt install -y ./debian-template/wiringpi_3.14_arm64.deb +# change the directory +WORKDIR /workdir + +# setup docker RUN ./install.sh docker \ - && touch /docker_persistent/mbconfig.cfg \ - && touch /docker_persistent/persistent.file \ - && mkdir /docker_persistent/st_files \ - && cp /workdir/webserver/openplc.db /docker_persistent/openplc.db \ + && touch /persistent/mbconfig.cfg \ + && touch /persistent/persistent.file \ + && mkdir /persistent/st_files \ + && cp /workdir/webserver/openplc.db /persistent/openplc.db \ && mv /workdir/webserver/openplc.db /workdir/webserver/openplc_default.db \ - && cp /workdir/webserver/dnp3.cfg /docker_persistent/dnp3.cfg \ + && cp /workdir/webserver/dnp3.cfg /persistent/dnp3.cfg \ && mv /workdir/webserver/dnp3.cfg /workdir/webserver/dnp3_default.cfg \ - && cp -r /workdir/webserver/st_files/ /docker_persistent/st_files/ \ + && cp -r /workdir/webserver/st_files/ /persistent/st_files/ \ && mv /workdir/webserver/st_files /workdir/webserver/st_files_default \ - && cp /workdir/webserver/active_program /docker_persistent/active_program \ + && cp /workdir/webserver/active_program /persistent/active_program \ && mv /workdir/webserver/active_program /workdir/webserver/active_program_default \ - && ln -s /docker_persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg \ - && ln -s /docker_persistent/persistent.file /workdir/webserver/persistent.file \ - && ln -s /docker_persistent/openplc.db /workdir/webserver/openplc.db \ - && ln -s /docker_persistent/dnp3.cfg /workdir/webserver/dnp3.cfg \ - && ln -s /docker_persistent/st_files /workdir/webserver/st_files \ - && ln -s /docker_persistent/active_program /workdir/webserver/active_program + && ln -s /persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg \ + && ln -s /persistent/persistent.file /workdir/webserver/persistent.file \ + && ln -s /persistent/openplc.db /workdir/webserver/openplc.db \ + && ln -s /persistent/dnp3.cfg /workdir/webserver/dnp3.cfg \ + && ln -s /persistent/st_files /workdir/webserver/st_files \ + && ln -s /persistent/active_program /workdir/webserver/active_program ENTRYPOINT ["./start_openplc.sh"] From ecd5b5d0c8206faf8e5db180feb652881ceee91a Mon Sep 17 00:00:00 2001 From: gustaf71 Date: Sat, 29 Mar 2025 17:48:44 +0100 Subject: [PATCH 3/3] modified: Dockerfile, removed the change from Dockerfile --- Dockerfile | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 60b0371..a6d8cb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,51 +1,31 @@ -FROM debian:stable-20241111 +FROM debian:bullseye-20240722 COPY . /workdir WORKDIR /workdir -RUN mkdir /persistent +RUN mkdir /docker_persistent -VOLUME /persistent - -# get git, wget, dpkg-dev and gettext -RUN apt update && apt install -y \ - git \ - wget \ - dpkg-dev \ - gettext - -# clone WiringPi -RUN git clone https://github.com/WiringPi/WiringPi.git /api - -# change the directory -WORKDIR /api - -# build wiringPi and install it -RUN ./build debian \ - && apt install -y ./debian-template/wiringpi_3.14_arm64.deb - -# change the directory -WORKDIR /workdir +VOLUME /docker_persistent # setup docker RUN ./install.sh docker \ - && touch /persistent/mbconfig.cfg \ - && touch /persistent/persistent.file \ - && mkdir /persistent/st_files \ - && cp /workdir/webserver/openplc.db /persistent/openplc.db \ + && touch /docker_persistent/mbconfig.cfg \ + && touch /docker_persistent/persistent.file \ + && mkdir /docker_persistent/st_files \ + && cp /workdir/webserver/openplc.db /docker_persistent/openplc.db \ && mv /workdir/webserver/openplc.db /workdir/webserver/openplc_default.db \ - && cp /workdir/webserver/dnp3.cfg /persistent/dnp3.cfg \ + && cp /workdir/webserver/dnp3.cfg /docker_persistent/dnp3.cfg \ && mv /workdir/webserver/dnp3.cfg /workdir/webserver/dnp3_default.cfg \ - && cp -r /workdir/webserver/st_files/ /persistent/st_files/ \ + && cp -r /workdir/webserver/st_files/ /docker_persistent/st_files/ \ && mv /workdir/webserver/st_files /workdir/webserver/st_files_default \ - && cp /workdir/webserver/active_program /persistent/active_program \ + && cp /workdir/webserver/active_program /docker_persistent/active_program \ && mv /workdir/webserver/active_program /workdir/webserver/active_program_default \ - && ln -s /persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg \ - && ln -s /persistent/persistent.file /workdir/webserver/persistent.file \ - && ln -s /persistent/openplc.db /workdir/webserver/openplc.db \ - && ln -s /persistent/dnp3.cfg /workdir/webserver/dnp3.cfg \ - && ln -s /persistent/st_files /workdir/webserver/st_files \ - && ln -s /persistent/active_program /workdir/webserver/active_program + && ln -s /docker_persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg \ + && ln -s /docker_persistent/persistent.file /workdir/webserver/persistent.file \ + && ln -s /docker_persistent/openplc.db /workdir/webserver/openplc.db \ + && ln -s /docker_persistent/dnp3.cfg /workdir/webserver/dnp3.cfg \ + && ln -s /docker_persistent/st_files /workdir/webserver/st_files \ + && ln -s /docker_persistent/active_program /workdir/webserver/active_program ENTRYPOINT ["./start_openplc.sh"]