pascal_sautot
I followed an example found here  to use openplc within a container.
This example allows starting the server and directly run a program. The thing is that the run program is the default not the one I installed to boostrap the server.

The docker file ends up with a run.sh which deals with the internal structure of the webserver.
What it does is
  • add a st file in webserver/st_files 
  • add a line in the data base which corresponds to this file 
  • compile the added program
  • add the mbconfig.cfg file 
  • add a line to define a slave device 

#!/bin/bash
CFGFILE="mbconfig.cfg"

#check volume is mounted with expected files 
if [ ! -f /home/openplc/volume/$PROG_FILE ]; then
    echo "Structured text file missing!"
    exit 1
fi

if [ ! -f /home/openplc/volume/mbconfig.cfg ]; then
    echo "Config file missing!"
    exit 1
fi

#don't know what this can be used for
sed -e s/DEVICE_NAME/$DEVICE_NAME/ -e s/DEVICE_IP/$DEVICE_IP/ -e s/DEVICE_CMD_REG/$DEVICE_CMD_REG/ -e s/DEVICE_STATUS_REG/$DEVICE_STATUS_REG/ /home/openplc/volume/mbconfig.cfg > /home/openplc/volume/tmp && mv /home/openplc/volume/tmp /home/openplc/volume/mbconfig.cfg
echo "DONE" >> /home/openplc/volume/log

## define the program to execute 
# add new 
SQL_ADD_SCRIPT_PROG="INSERT INTO Programs (Name, Description, File, Date_upload) VALUES ($PROG_NAME,$PROG_DESC,$PROG_FILE, strftime('%s', 'now'));"

cp /home/openplc/volume/ script.st  /home/openplc/OpenPLC_v3/webserver/st_files
sqlite3 /home/openplc/OpenPLC_v3/webserver/openplc.db "$SQL_ADD_SCRIPT_PROG"

#compile and define active program : this should end up with an executable named openplc in webserver/core
rm /home/openplc/OpenPLC_v3/webserver/core/openplc
cd /home/openplc/OpenPLC_v3/webserver/
./scripts/ compile_program.sh  $PROG_FILE

if [ ! -f /home/openplc/OpenPLC_v3/webserver/core/openplc ]; then
    echo "Executable generated from $PROG_FILE file missing! Compilation must have failed"
    exit 1
fi

## define slave device
SQL_ADD_DEVICE="INSERT INTO Slave_dev (dev_name, dev_type, slave_id, ip_address, ip_port, di_start, di_size, coil_start, coil_size, ir_start, ir_size, hr_read_start, hr_read_size, hr_write_start, hr_write_size) VALUES ($DEVICE_NAME,'TCP',0,$DEVICE_IP,'502','0','0','0','0',$DEVICE_STATUS_REG,'1','0','0',$DEVICE_CMD_REG,'1');"

cp /home/openplc/volume/mbconfig.cfg /home/openplc/OpenPLC_v3/webserver
sqlite3 /home/openplc/OpenPLC_v3/webserver/openplc.db "$SQL_ADD_DEVICE"

## start in run mode
SQL_AUTO_START="UPDATE Settings SET Value = 'true' WHERE Key = 'Start_run_mode';"

sqlite3 /home/openplc/OpenPLC_v3/webserver/openplc.db "$SQL_AUTO_START"

sudo /home/openplc/OpenPLC_v3/ start_openplc.sh


The shell final command starts the web server which crashes with the following log:

/home/openplc/OpenPLC_v3/start_openplc.sh: line 2: cd: webserver: No such file or directory
Traceback (most recent call last):
File "webserver.py", line 2329, in <module>
openplc_runtime.project_name = str(row[1])
TypeError: 'NoneType' object has no attribute '__getitem__'


This error is due to a query which return None while obviously it should return something

wonder if you can help  on what I have missed
thiagoralves
I'll try to analyze this further when I have some more time, but just some quick tips, the error is caused because the web server couldn't find the program it was looking for on the database. I think it all has to do with the file OpenPLC_v3/webserver/active_program. This file holds what program was last executed and then the web server goes and tries to find that on the database. Perhaps if you just add the filename of the .st on the active_program file it might work
Reply 0 0
smart734
I recommend to check start_openplc.sh and write on line two whole command cd /home/openplc/OpenPLC_v3/webserver .
Reply 0 0
eduardo.viana
Hello everyone, hope is all good,
Gentleman I´ve installed openPLC runtime for Docker in my raspberry PI and its is working pretty fine. So, my issue is a more conceptual query as below follows:
Using the comand line below it provides me a docker volume to copy the compiled *.st files in there:
 
       docker run --name plc -d -p 8080:8080 -p 502:502 -v /PATH/TO/SCRIPT:/home/openplc/scripts openplc-docker
 
I wonder where inside Docker volume the PSM folder is located.
 
        C:\cygwin64\home\Windows10\OpenPLC_v3\webserver\core\psm [ *** this is what I´ve got when run in regular windows installation***]
 
I´ve learned to navigate inside the PSMdirectory thru the command: docker exec plc ls /workdir/webserver/core/psm
Would be this the path on Docker to copy the libraries? 
 
Plase provide me your kindly assistance.
My best wishes!
Eduardo Viana
Reply 0 0
eduardo.viana
Good monrning team,
When I am running openPLC from docker, on PSM, I am getting the message:
    
    File "/workdir/webserver/./core/psm/main.py", line 11, in <module>
    import psm
    File "/workdir/webserver/core/psm/psm.py", line 3, in <module>
    from pymodbus.server.sync import ModbusTcpServer
 
Is there anything that I can do in order make this issue sorted?
Many thanks one more time
Eduardo Viana
Reply 0 0
thiagoralves
Check if pymodbus is installed on python 3 inside your docker volume:
python3 -m pip install pymodbus==2.5.3
 
Reply 0 0
eduardo.viana
That´s awsome Thiago.....many thanks for this valuable reply, I noticed it was really not installed.
It worked pretty much and now openPLC + PSM are running good inside my container.

Just to keep the information for further people assistance . You´ve gotta go inside the container to carry on the installation:
docker exec -it [container ID] bash
And install all you need (npm, nodejs, pymodbus & so on)

Eduardo Viana
Reply 0 0
eduardo.viana
Hi Thiago
Have started another installation from scratch in 64bits OS raspbian. Everything went good until I got the following message in my openplc dashboard:
-----------------------
Compiling main program...
persistent_storage.cpp:156:5: error: ambiguating new declaration of ‘int readPersistentStorage()’
156 | int readPersistentStorage()
| ^~~~~~~~~~~~~~~~~~~~~
In file included from persistent_storage.cpp:31:
ladder.h:169:6: note: old declaration ‘void readPersistentStorage()’
169 | void readPersistentStorage();
| ^~~~~~~~~~~~~~~~~~~~~
Error compiling C files
 
I didnt understand what is going on.
May you please provide me your kindly assistance one more time.
Thanks 
Eduardo
Reply 0 0
thiagoralves
My bad. That’s a commit I pushed yesterday. Will push the fix soon
Reply 0 0
thiagoralves
Fixed!
Reply 0 0
eduardo.viana
Hi Thiago,
I´ve git clone again and it worked pretty fine. 
My goal was to have open PLC running in both OS raspbian platform 32 & 64 bits always inside a docker container.
Have used the command: "  docker build -t openplc:v3 . " and everything is up and running.
Thanks, one more time...
Eduardo
Reply 1 0
Atlas192
Hi,
i also wanted to rebuild by docker container.
the building process is sucessfull when i run docker build -t openplc:v3 .

however if i run the container i got this issue:
[203128%2F8813685%2Fmceclip0]


Reply 0 0
Reply