Python plugin: Modbus RTU / ASCII / TCP/IP Topic is solved

Python and python framework

Moderator: leecollings

PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by PieterS »

simat wrote: Tuesday 15 August 2023 9:44 Like this ?

Its type 243 - Domoticz.Device(Name="Import Wh", Unit=2,Type=243,Subtype=29,Used=0).Create()
Yes, indeed!
But since my last question in this thread I changed my hardware. Went over to a ESP8266 and ESPeasy. Because it is a bit difficult to store a Raspberry in that area. Maybe on a later moment. Thanks for now.
Synology with Domoticz build (V2024.7) in Docker
bonebuster
Posts: 13
Joined: Saturday 25 November 2017 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by bonebuster »

Hi

since complete re-install

with Pi4B, bullseye, python 3.9.2, pymodbus 3.6.2, pymodbusTCP 0.2.1, domoticz 2023.2 modbus-domoticz plugin last version, i have this issue :
(ModbusREAD) failed to load 'plugin.py', Python Path used was '/home/pi4/domoticz/plugins/modbus-read/:/usr/lib/python39.zip:/usr/lib/python3.9:/usr/lib/python3.9/lib-dynload:/usr/local/lib/python3.9/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.9/dist-packages'.
2023-12-14 16:34:04.186 Error: Conso_saison: Traceback (most recent call last):
2023-12-14 16:34:04.186 Error: Conso_saison: File "/home/pi4/domoticz/plugins/modbus-read/plugin.py", line 177, in <module>
2023-12-14 16:34:04.186 Error: Conso_saison: from pymodbus.client.sync import ModbusSerialClient # RTU
2023-12-14 16:34:04.186 Error: Conso_saison: ModuleNotFoundError: No module named 'pymodbus.client.sync'
Anyone to help-me ?
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

Same problem here. Found no solution yet. Has anybody seen @DomoticX around on the forum. Mybe he can provide a solution?
User avatar
waltervl
Posts: 5374
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by waltervl »

Copitano wrote: Thursday 07 March 2024 15:03 Same problem here. Found no solution yet. Has anybody seen @DomoticX around on the forum. Mybe he can provide a solution?
USER STATISTICS DomoticX
Joined:Sunday 07 January 2018 21:19
Last active:Sunday 30 August 2020 21:26

So do not expect a solution from him/her....

Did you check the wiki on this error? https://www.domoticz.com/wiki/Using_Pyt ... ules_Fails
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by FlyingDomotic »

It seems that pymodbus changed.

Instead of pymodbus.client.sync, try pymodbus.client.serial in the plugin.
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

by FlyingDomotic » Friday 08 March 2024 0:36

It seems that pymodbus changed.

Instead of pymodbus.client.sync, try pymodbus.client.serial in the plugin.
Tried your suggestion. At first I got another error, but after also replacing 'pymodbus.client.sync' in the TCP part bij 'pymodbus.client.tcp' at least I got an device. Still got an error like this:

Code: Select all

2024-03-20 15:45:27.099 Error: Modbus RTU read: Modbus error decoding or received no data (RTU/ASCII/RTU over TCP)!, check your settings!
2024-03-20 15:45:27.105 Error: Modbus RTU read: Modbus error decoding or received no data!, check your settings!
I gues it's because there is no real device on this test Pi. Now I think I have to edit also the write part of the plugin the same way.
EDIT1: Yes, it worked the same way for the write function :D
Attachments
Schermafbeelding 2024-03-20 161931.jpg
Schermafbeelding 2024-03-20 161931.jpg (31.97 KiB) Viewed 2083 times
Schermafbeelding 2024-03-20 155746.jpg
Schermafbeelding 2024-03-20 155746.jpg (35.47 KiB) Viewed 2083 times
Schermafbeelding 2024-03-20 160037.jpg
Schermafbeelding 2024-03-20 160037.jpg (23.83 KiB) Viewed 2083 times
Last edited by Copitano on Wednesday 20 March 2024 17:24, edited 1 time in total.
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

FlyingDomotic wrote: Thursday 07 March 2024 23:36 It seems that pymodbus changed.

Instead of pymodbus.client.sync, try pymodbus.client.serial in the plugin.
See above :oops: :lol:
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

Tested the Python plugin: Modbus RTU / ASCII / TCP/IP with de edited plugin.py scripts.
Unfortunately I cheered too early. Although the devices are now displayed properly, no data enters the devices after connecting the CH341-UART converter. As far as I can tell, I don't see anything crazy with dmesg. What am I missing?

Code: Select all

pi@raspberrypi4BSEM:~ $ sudo dmesg | grep -i usb
[    0.139822] usbcore: registered new interface driver usbfs
[    0.139881] usbcore: registered new interface driver hub
[    0.139949] usbcore: registered new device driver usb
[    0.140329] usb_phy_generic phy: supply vcc not found, using dummy regulator
[    0.140559] usb_phy_generic phy: dummy supplies not allowed for exclusive requests
[    1.508199] usbcore: registered new interface driver r8152
[    1.508274] usbcore: registered new interface driver lan78xx
[    1.508360] usbcore: registered new interface driver smsc95xx
[    1.556002] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 1
[    1.557814] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 2
[    1.557836] xhci_hcd 0000:01:00.0: Host supports USB 3.0 SuperSpeed
[    1.558214] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.01
[    1.558235] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.558249] usb usb1: Product: xHCI Host Controller
[    1.558263] usb usb1: Manufacturer: Linux 6.1.21-v8+ xhci-hcd
[    1.558275] usb usb1: SerialNumber: 0000:01:00.0
[    1.559105] hub 1-0:1.0: USB hub found
[    1.560148] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 6.01
[    1.560171] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.560186] usb usb2: Product: xHCI Host Controller
[    1.560200] usb usb2: Manufacturer: Linux 6.1.21-v8+ xhci-hcd
[    1.560213] usb usb2: SerialNumber: 0000:01:00.0
[    1.560898] hub 2-0:1.0: USB hub found
[    1.563807] usbcore: registered new interface driver uas
[    1.563925] usbcore: registered new interface driver usb-storage
[    1.575796] usbcore: registered new interface driver usbhid
[    1.575810] usbhid: USB HID core driver
[    1.814947] usb 1-1: new high-speed USB device number 2 using xhci_hcd
[    1.965513] usb 1-1: New USB device found, idVendor=2109, idProduct=3431, bcdDevice= 4.21
[    1.965551] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    1.965566] usb 1-1: Product: USB2.0 Hub
[    1.967415] hub 1-1:1.0: USB hub found
[    2.262902] usb 1-1.4: new full-speed USB device number 3 using xhci_hcd
[    2.369316] usb 1-1.4: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice= 2.63
[    2.369346] usb 1-1.4: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[    2.369362] usb 1-1.4: Product: USB2.0-Serial
[    6.153943] usbcore: registered new interface driver brcmfmac
[    6.522257] usbcore: registered new interface driver usbserial_generic
[    6.522367] usbserial: USB Serial support registered for generic
[    6.608848] usbcore: registered new interface driver ch341
[    6.608949] usbserial: USB Serial support registered for ch341-uart
[    6.636039] usb 1-1.4: ch341-uart converter now attached to ttyUSB0
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

waltervl wrote: Thursday 07 March 2024 15:07
Copitano wrote: Thursday 07 March 2024 15:03 Same problem here. Found no solution yet. Has anybody seen @DomoticX around on the forum. Mybe he can provide a solution?
USER STATISTICS DomoticX
Joined:Sunday 07 January 2018 21:19
Last active:Sunday 30 August 2020 21:26

So do not expect a solution from him/her....

Did you check the wiki on this error? https://www.domoticz.com/wiki/Using_Pyt ... ules_Fails
Yes, but it didn't solve all. https://www.domoticz.com/forum/viewtopi ... 20#p315320
Would it be a good idea to downgrade the Python version to the latest version under which the plugin fully worked?
User avatar
waltervl
Posts: 5374
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by waltervl »

You can try to downgrade Python but that is not an easy process.
The Docker version of Domoticz runs with python 3.8 I believe. Perhaps it that an option?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
simat
Posts: 33
Joined: Thursday 04 November 2021 21:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: UK
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by simat »

My version is still working fine on 2024.4

https://github.com/simat-git/SDM120-Modbus

Easy to adapt to any modbus meter if you know the register numbers.
Raspberry Pi4, Sunny Boy 4000TL, Victron Multiplus II 10kw ESS, 44kWh LiFEPO4, Batrium BMS, NodeRED on Cerbo GX
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

@simat
I just saw your response now. I had given up for the time being because my knowledge of Phyton does not extend that far. But I'll definitely see if I can get things working again with your solution. Although it would be very nice if a next version of Domoticz could include a native version for Modbus RTU that is also maintained in new versions. :D
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

waltervl wrote: Tuesday 26 March 2024 0:11 You can try to downgrade Python but that is not an easy process.
The Docker version of Domoticz runs with python 3.8 I believe. Perhaps it that an option?
On second thought, that doesn't seem to be the way to go. I think that will get in the way of every further update. But I don't have another solution yet. Unfortunately, my pyranometer has to keep running on an old Pi 3B+ with version 2021.1 on it. My Enphase inverters unfortunately no longer work on it due to an (unrequested) security update from Enphase.
Ik hoop dat er in een van de komende stable versies een native Modbus RTU module ingebouwd kan worden in de lijn van die van DomoticX.
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

simat wrote: Tuesday 14 May 2024 9:43 My version is still working fine on 2024.4

https://github.com/simat-git/SDM120-Modbus

Easy to adapt to any modbus meter if you know the register numbers.
I have looked at your version, but I can't figure out how to adapt it for more general use. So not only specifically for your meter, but also for my pyranometer that measures the global radiation of the sun.
Rosomak
Posts: 7
Joined: Wednesday 30 January 2019 20:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: IE
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Rosomak »

Hi All,
I rewrote the script of the Read plugin and it reads the modbus RTU and modbus TCP/IP registers correctly.
I have no way to check modbus RTU over IP.
Just replace the plugin.py file in the location .../domoticz/plugins/modbus-read and restart Domoticz
I will work on the plugin for writing next week.
Dependences needed:
pip3 install -U pymodbus pymodbusTCP
pip install pyserial



P.S. I'm not able to attach file here so I left it on https://easyupload.io/fj9psi
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

Rosomak wrote: Friday 20 September 2024 17:49 Hi All,
I rewrote the script of the Read plugin and it reads the modbus RTU and modbus TCP/IP registers correctly.
I have no way to check modbus RTU over IP.
Just replace the plugin.py file in the location .../domoticz/plugins/modbus-read and restart Domoticz
I will work on the plugin for writing next week.
Dependences needed:
pip3 install -U pymodbus pymodbusTCP
pip install pyserial



P.S. I'm not able to attach file here so I left it on https://easyupload.io/fj9psi
Super!!!! I will be testing this tomorrow.
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

As I said, I tested today with the new plugin.py version 2024 beta. Unfortunately, I now have the problem back that I also mentioned above. No widget is created. I have not been able to change that yet as with the previous version because those lines in the script are commented out.
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

Rosomak wrote: Friday 20 September 2024 17:49 Hi All,
I rewrote the script of the Read plugin and it reads the modbus RTU and modbus TCP/IP registers correctly.
I have no way to check modbus RTU over IP.
Just replace the plugin.py file in the location .../domoticz/plugins/modbus-read and restart Domoticz
I will work on the plugin for writing next week.
Dependences needed:
pip3 install -U pymodbus pymodbusTCP
pip install pyserial



P.S. I'm not able to attach file here so I left it on https://easyupload.io/fj9psi
I am getting this Error:

Code: Select all

2024-09-28 13:22:34.672 Error: Test Total Solar Radiation: (ModbusREAD) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/modbus-read/:/usr/lib/python39.zip:/usr/lib/python3.9:/usr/lib/python3.9/lib-dynload:/usr/local/lib/python3.9/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.9/dist-packages'.
2024-09-28 13:22:34.673 Error: Test Total Solar Radiation: Traceback (most recent call last):
2024-09-28 13:22:34.673 Error: Test Total Solar Radiation: File "/home/pi/domoticz/plugins/modbus-read/plugin.py", line 163, in <module>
2024-09-28 13:22:34.673 Error: Test Total Solar Radiation: from pymodbus import FramerType
2024-09-28 13:22:34.673 Error: Test Total Solar Radiation: ImportError: cannot import name 'FramerType' from 'pymodbus' (/usr/local/lib/python3.9/dist-
I am using Python Version: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
and I did:
sudo apt-get update && sudo apt-get upgrade
pip3 install -U pymodbus pymodbusTCP
pip install pyserial

Looks like FramerType isn't where it should be. How do I get it in the right place?
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Copitano »

Rosomak wrote: Friday 20 September 2024 17:49 Hi All,
I rewrote the script of the Read plugin and it reads the modbus RTU and modbus TCP/IP registers correctly.
Hi Rosomak,
I solved the problem of not creating devices/widgets by a clean install of the operating system and python 3.9.6 Below the result. Looks as if its working for me aswell :D Now I just have to test with the sunsensor on the roof connected 8-) .
Attachments
Schermafbeelding 2024-09-29 180026.jpg
Schermafbeelding 2024-09-29 180026.jpg (12.91 KiB) Viewed 1208 times
JPSke
Posts: 33
Joined: Wednesday 11 November 2020 11:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Sint-Gillis-Waas, Belgium
Contact:

Re: Python plugin: Modbus RTU / ASCII / TCP/IP

Post by JPSke »

Hello developers,

I am looking for someone with enough knowledge of the origininal Python plugin (version V2020.2F) to solve a problem I have:
After an update by Domoticz or a restart of the RPi, all my READ sensors start at the same time (heartbeat I presume).
I use the plugin to read information from a Solax Solar inverter and this device allows only one call per second.
This means that most of the 7 values I read come back wrong or not at all.
I have to adjust the heartbeats of each sensor by manually starting and stopping the hardware at different moments.
I tried to solve the problem by working with the polling rate and giving each sensor a different rate, but after some time they will be aligning again for a short period and giving errors again.
I was hoping that someone might be willing to change the plugin so that not only the polling rate but also the starting point or delay of the sensor can be set. My knowledge of Python is far too limited to try and do it myself, so I am calling on the community for help.
Thanks in advance
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests