elioelkazzi
Hello,

I got a problem with PSM on linux (hardware tab), while starting PLC i got error that connection to PSM failed then its disabled.
The error is: no module named 'pymodbus'. I installed this module several times, using pip, pip3 and manually from git. Even in the terminal when i start python3.7, i can import pymodbus and i can print the version: 2.5.2 so it's already installed.
I rebooted my raspberry pi several times, with uninstalling the module and re-installing it but no results...
PS: My openPLC is installed in raspberry pi 4.

Any advices?

Thank you.
Reply 0 0
thiagoralves
Try reinstalling OpenPLC and running PSM with the original sample code that comes with it. Does that work? If so, then maybe it is something in your custom PSM code that is breaking functionality.
Reply 0 0
NWT.Stuff
@elioelkazzi Can you upload you're PSM Code.  I will test it in a working OPEN PLC Install. Regards Kevin
Reply 0 0
elioelkazzi
I tried to run the PSM with the virgin code, it's running normally. This is the log I get:
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued stop_pstorage() command


Then I tried to keep the same virgin code just with assigning IX4.0 instead of IX0.0 and I get this error:

OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
PSM: Starting PSM...
Traceback (most recent call last):
  File "./core/psm/main.py", line 27, in <module>
    import psm
  File "/home/pi/OpenPLC_v3/webserver/core/psm/psm.py", line 3, in <module>
    from pymodbus.server.sync import ModbusTcpServer
ModuleNotFoundError: No module named 'pymodbus'
PSM: Error while starting Python interpreter
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
PSM: Connection to psm failed
PSM: Error connecting to psm!
PSM: PSM is disabled
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found


My main issue is to add some IX and some QX to communicate via I2C with 2 or 3 esp32 (slaves) and get inputs from those esps and stock them then re-send updates to these slaves.

I appreciate your help,
Regards.
Reply 0 0
NWT.Stuff
@elioelkazzi not tried using open plc with esp32 slaves but it is an area of interest.  Can you post an architecture sketch of what you are trying to achieve along with PLC program and PSM code ? Regards Kevin.
Reply 0 0
thiagoralves
It is hard to debug without seeing your code. It appears to me that the first log did not have PSM enabled on the hardware tab (there is no “starting PSM” message)
Reply 0 0
NWT.Stuff
Always get ESP32 and ESP8266 mixed up ! I was actually referring to ESP8266 which I have started using recently, NodeMCU and this type of ESP8266 Relay Board
ESP8266 Relay.jpg 
I have not tried integrating into OpenPLC as a slave but assume I would follow these instructions and I am away https://www.openplcproject.com/runtime/esp8266/

@thiagoralves I have a couple of I have a couple of questions:-

1. Do I need to Enable the Ethernet/IP Server for this to work ? e.g. is the communication with TCP IP Sockets ?

2. Would you expect the ESP32 devices to work using a similar procedure to the ESP8266 Instructions ? 
Reply 0 0
elioelkazzi
Hello again,

The problem with adding slave devices like ESP8266 will communicate via WIFI, and i need to be communicating over wires only. So it is possible to communicate with slave devices like ESP8266 but via i2c? 
I think I found a problem with my code, i will update you with news 🙂
Thanks for your help again,
Regards.
Reply 0 0
NWT.Stuff
From my understanding using the PSM Module you can do anything that you can normally do in Stand Alone Python (as long as there is no conflict with libraries used).  The ESP32 and ESP8266 are cheap Wi-Fi modules so I am struggling to see the need to wire them.  There must be hardware available that doesn't have a wifi module in it at all (e.g. wired slaves) ? 

It's difficult to see what you are trying to achieve without having a vision of the application 🙂
Reply 0 0
elioelkazzi
Hello again,

It seems that i've got errors even without my code, i started psm on the virgin code + a blank program and its not launching... I tried to re-install the openPLC but same errors even without adding any code.. The problem with wifi that i'm using those esps with university's WIFI (problem with proxy, communication speed), so i need to find a solution to wire them.

Thank you.
Reply 0 0
NWT.Stuff
Regarding PSM Program do you have anything else installed on the RPI that could be conflicting.  Is it possible to install OpenPLC on a Fresh Raspbian Build (or maybe you are doing this) .  Which OS are you using ?

Regarding ESP Devices I think on some of them they can be configured as a Wireless Access Point.  Might get around your issue ? Also you can configure the RPI as an Access Point too. Might be handy for getting off the Uni Wifi 🙂

https://thepi.io/how-to-use-your-raspberry-pi-as-a-wireless-access-point/ 
Reply 0 0
elioelkazzi
I will follow this link, I think this might solve all my problems 😁😁
Thank you.
Reply 1 0
thiagoralves
I believe the problem you're facing with PSM might be related to having multiple versions of Python3 installed in your system. Do a quick
which python3
to check where your python3 alias is pointing to. Also check if there are multiple python binaries in /usr/bin with
ls -la /usr/bin/python*


What happens is that PSM starts python3 using the python3 alias on your system. If you have multiple python3 versions installed, it can be possible that pip3 is installing pymodbus in one version but psm is starting the version that does not have it installed.
Reply 0 0
NWT.Stuff
That makes sense @thiagoralves I always:-

1. Install a Fresh OS
2. Run in command line
sudo apt update
sudo apt full-upgrade

Before Installing OpenPLC.  So I have never had this problem 🙂
Reply 0 0
wch705
I believe the problem you're facing with PSM might be related to having multiple versions of Python3 installed in your system. Do a quick
which python3
to check where your python3 alias is pointing to. Also check if there are multiple python binaries in /usr/bin with
ls -la /usr/bin/python*


What happens is that PSM starts python3 using the python3 alias on your system. If you have multiple python3 versions installed, it can be possible that pip3 is installing pymodbus in one version but psm is starting the version that does not have it installed.


I am hitting the same bug on RPi 3

I tried multiple clean installation of OpenPLC and without luck.

Here is the distro info
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"


And it doesn't look like I have multiple python3 installed
pi@raspberrypi:~ $ which python3
/usr/bin/python3
pi@raspberrypi:~ $ ls -la /usr/bin/python*
lrwxrwxrwx 1 root root 7 Mar 5 2019 /usr/bin/python -> python2
lrwxrwxrwx 1 root root 9 Mar 5 2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 2984816 Oct 11 2019 /usr/bin/python2.7
lrwxrwxrwx 1 root root 9 Mar 26 2019 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 4275580 Jan 23 2021 /usr/bin/python3.7
lrwxrwxrwx 1 root root 36 Jan 23 2021 /usr/bin/python3.7-config -> arm-linux-gnueabihf-python3.7-config
-rwxr-xr-x 2 root root 4275580 Jan 23 2021 /usr/bin/python3.7m
lrwxrwxrwx 1 root root 37 Jan 23 2021 /usr/bin/python3.7m-config -> arm-linux-gnueabihf-python3.7m-config
lrwxrwxrwx 1 root root 16 Mar 26 2019 /usr/bin/python3-config -> python3.7-config
lrwxrwxrwx 1 root root 10 Mar 26 2019 /usr/bin/python3m -> python3.7m
lrwxrwxrwx 1 root root 17 Mar 26 2019 /usr/bin/python3m-config -> python3.7m-config

Reply 0 0
Reply