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

Python and python framework

Moderator: leecollings

winnie
Posts: 7
Joined: Saturday 13 January 2018 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by winnie »

I tried to run the script from the command line. (/modbus_read/plugin.py)

Traceback (most recent call last):
File "plugin.py", line 75, in <module>
import Domoticz
ImportError: No module named Domoticz

Is this an indication of the problem?
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Well....i don't know the local paths, includes or workfolder that domoticz is using to load libraries, but you can comment this line out with # and try again :roll:

Ps, domoticz is using python3, when i run this command:

Code: Select all

sudo python3 /home/pi/domoticz/plugins/modbus-read/plugin.py
i got no errors....
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
winnie
Posts: 7
Joined: Saturday 13 January 2018 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by winnie »

@Domoticx,

Thanks for all your help.
Apparently this is not a general problem.
Today I am leaving on vacation for a week.
When I am back I will try with a fresh installation.

Kind Regards,
Erwin.
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

nice projet, thanks
i can't setup modbus-read in TCP mode, may be you can help me?
The modbus counter work's fine, it have count 232,46 m3 of water (can we adjust the comma decimal in your plugin?)
i can read the input 1010 in 32uint type data with a modbus sofware, ip adress 192.168.1.21 port 502
but don't works with those parameters in python plugin
2018-01-15 23_05_00-Domoticz.jpg
2018-01-15 23_05_00-Domoticz.jpg (278.33 KiB) Viewed 4950 times
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Hi papoo,

Thanks for trying it out. :D

I have updated the plugins! (grab new version from github)
* I have found a uint32 bug in the plugin code (decoded as uint16)
* Added DEBUG option, so you can check stuff in the LOG

Next for you...

Your TCP config seems OK!

1) Have you installed Pymodbus correctly for python3?
2) Are you using the right modbus function (4) to read the data out of the device?
3) To read a 32uint you need 4 bytes, thus you need to read out 2 registers (not 1) :geek:

Ps. You can now check stuff in the LOG if DEBUG is True
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

thanks for your job
the 1.0.1 version don't work

Code: Select all

Error: (Modbus) start up failed, Domoticz module not found in interpreter.
i added ligne81

Code: Select all

import Domoticz
then plugin log

Code: Select all

2018-01-16 22:20:31.143 (compteur_edv) onHeartbeat called
2018-01-16 22:20:31.143 (compteur_edv) MODBUS DEBUG TCP CMD - Method=tcp Address=192.168.1.21 Port=502 Registers to read=4 Data type=32int
2018-01-16 22:20:31.144 (compteur_edv) Modbus error communicating!, check your settings!
Data is empty
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Uploaded v1.0.2 READ !!

1) Bugfix uint32 typo (again) hahahaha :shock: :shock:
2) added import Domoticz
3) Also added the register address in de LOG

Please set register to 2 (=4 bytes) for uint32 (not 1 or 4)
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

same problem

Code: Select all

2018-01-16 22:57:54.822 (compteur_edv) Started.
2018-01-16 22:57:55.287 (compteur_edv) Entering work loop.
2018-01-16 22:57:55.289 (compteur_edv) Initialized version 1.0.1, author 'S. Ebeltjes / domoticx.nl'
2018-01-16 22:57:55.344 (compteur_edv) Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
2018-01-16 22:58:04.816 (compteur_edv) onHeartbeat called
2018-01-16 22:58:04.816 (compteur_edv) MODBUS DEBUG TCP CMD - Method=tcp Address=192.168.1.21 Port=502 Register=1009 Registers to read=2 Data type=32int
2018-01-16 22:58:04.818 (compteur_edv) Modbus error communicating!, check your settings!
2018-01-16 22:58:14.801 (compteur_edv) onHeartbeat called
2018-01-16 22:58:14.802 (compteur_edv) MODBUS DEBUG TCP CMD - Method=tcp Address=192.168.1.21 Port=502 Register=1009 Registers to read=2 Data type=32int
2018-01-16 22:58:14.804 (compteur_edv) Modbus error communicating!, check your settings!
my modbus register table
2018-01-16 22_59_35-HWg-PWR.png
2018-01-16 22_59_35-HWg-PWR.png (9.43 KiB) Viewed 4913 times
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

In the log above you still using v1.0.1 wich has the bug "Data type=32int" (in v1.0.2 it is corrected to: Data type=32uint) :shock:

please after download and overwrite plugin files, restart domoticz:

Code: Select all

sudo service domoticz.sh restart
And i see in your register table it should be 32bit INT (not UINT) so i will add more decoding options in v1.0.3 to try out! :D
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Hi papoo,

I have updated the READ to v1.0.3, added more decoding options :geek:

Also in your "Modbus example window" you are reading 1010 (and the program adds offset +1?) so you are actually reading register 1011 16Bit INT? (that explains the number of registers=1)

Ps. what kind of Modbus TCP unit do you have? (i only have RTU stuff here)
domoticz read v1.0.3 decode options.png
domoticz read v1.0.3 decode options.png (104.4 KiB) Viewed 4907 times
Last edited by Domoticx on Tuesday 16 January 2018 23:59, edited 1 time in total.
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

TCP mode with 1.0.2
I test uint mode with the same result (register 9 and 10)
I try 1.0.3 tomorow
Thank’s for tour job
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

papoo wrote: Tuesday 16 January 2018 23:52 TCP mode with 1.0.2
I test uint mode with the same result (register 9 and 10)
I try 1.0.3 tomorow
Thank’s for tour job
No problem, the thing is i don't have any Modbus TCP stuff to test on...i only have SERIAL RTU stuff here :D

Ps. what kind of TCP unit do you have?
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

Hwg-PWR 3 gateway Mbus->modbus tcp-ip
https://hw-group.us//device/hwg-pwr31225
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

with register 10 /32b UINT

Code: Select all

2018-01-17 21:19:38.721 (compteur_edv) Started.
2018-01-17 21:19:39.207 (compteur_edv) Entering work loop.
2018-01-17 21:19:39.208 (compteur_edv) Initialized version 1.0.4, author 'S. Ebeltjes / domoticx.nl'
2018-01-17 21:19:39.263 (compteur_edv) Debug log level set to: 'true'.
2018-01-17 21:19:39.263 (compteur_edv) 'Mode3':'S1B8PN'
2018-01-17 21:19:39.263 (compteur_edv) 'Mode5':'2'
2018-01-17 21:19:39.263 (compteur_edv) 'Author':'S. Ebeltjes / domoticx.nl'
2018-01-17 21:19:39.263 (compteur_edv) 'DomoticzBuildTime':'2018-01-15 13:01:28'
2018-01-17 21:19:39.263 (compteur_edv) 'Mode2':'9600'
2018-01-17 21:19:39.263 (compteur_edv) 'DomoticzHash':'4ec5e160'
2018-01-17 21:19:39.263 (compteur_edv) 'Mode4':'debug'
2018-01-17 21:19:39.263 (compteur_edv) 'HardwareID':'13'
2018-01-17 21:19:39.263 (compteur_edv) 'DomoticzVersion':'3.8809'
2018-01-17 21:19:39.263 (compteur_edv) 'Username':'4'
2018-01-17 21:19:39.263 (compteur_edv) 'HomeFolder':'/home/pi/domoticz/plugins/modbus-read/'
2018-01-17 21:19:39.264 (compteur_edv) 'Address':'192.168.1.21'
2018-01-17 21:19:39.264 (compteur_edv) 'Password':'10'
2018-01-17 21:19:39.264 (compteur_edv) 'SerialPort':'/dev/serial0'
2018-01-17 21:19:39.264 (compteur_edv) 'Version':'1.0.4'
2018-01-17 21:19:39.264 (compteur_edv) 'Port':'502'
2018-01-17 21:19:39.264 (compteur_edv) 'Mode1':'tcp'
2018-01-17 21:19:39.264 (compteur_edv) 'Name':'compteur_edv'
2018-01-17 21:19:39.264 (compteur_edv) 'Mode6':'32uint'
2018-01-17 21:19:39.264 (compteur_edv) 'Key':'Modbus'
2018-01-17 21:19:39.264 (compteur_edv) Device count: 1
2018-01-17 21:19:39.264 (compteur_edv) Device: 1 - ID: 173, Name: 'compteur_edv - ModbusDEV-READ', nValue: 0, sValue: '0'
2018-01-17 21:19:39.264 (compteur_edv) Device ID: '173'
2018-01-17 21:19:39.264 (compteur_edv) Device Name: 'compteur_edv - ModbusDEV-READ'
2018-01-17 21:19:39.264 (compteur_edv) Device nValue: 0
2018-01-17 21:19:39.264 (compteur_edv) Device sValue: '0'
2018-01-17 21:19:39.264 (compteur_edv) Device LastLevel: 0
2018-01-17 21:19:39.265 (compteur_edv) Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
2018-01-17 21:19:41.485 Incoming connection from: 127.0.0.1
2018-01-17 21:19:48.737 (compteur_edv) Calling message handler 'onHeartbeat'.
2018-01-17 21:19:48.737 (compteur_edv) MODBUS DEBUG TCP CMD - Method=tcp Address=192.168.1.21 Port=502 Register=10 Registers to read=2 Data type=32uint
2018-01-17 21:19:48.738 (compteur_edv) Modbus error communicating!, check your settings!
2018-01-17 21:19:48.738 (compteur_edv - ModbusDEV-READ) Updating device from 0:'0' to have values 0:'0'.
2018-01-17 21:19:48.749 (compteur_edv) Modbus error decoding (or recieved no data)!, check your settings!
2018-01-17 21:19:48.749 (compteur_edv - ModbusDEV-READ) Updating device from 0:'0' to have values 0:'0'.
2018-01-17 21:19:58.743 (compteur_edv) Calling message handler 'onHeartbeat'.
with register 1009 /32b INT

Code: Select all

2018-01-17 21:22:25.742 (compteur_edv) Started.
2018-01-17 21:22:26.248 (compteur_edv) Entering work loop.
2018-01-17 21:22:26.249 (compteur_edv) Initialized version 1.0.4, author 'S. Ebeltjes / domoticx.nl'
2018-01-17 21:22:26.304 (compteur_edv) Debug log level set to: 'true'.
2018-01-17 21:22:26.304 (compteur_edv) 'Mode3':'S1B8PN'
2018-01-17 21:22:26.304 (compteur_edv) 'Mode5':'2'
2018-01-17 21:22:26.304 (compteur_edv) 'Author':'S. Ebeltjes / domoticx.nl'
2018-01-17 21:22:26.304 (compteur_edv) 'DomoticzBuildTime':'2018-01-15 13:01:28'
2018-01-17 21:22:26.304 (compteur_edv) 'Mode2':'9600'
2018-01-17 21:22:26.304 (compteur_edv) 'DomoticzHash':'4ec5e160'
2018-01-17 21:22:26.304 (compteur_edv) 'Mode4':'debug'
2018-01-17 21:22:26.304 (compteur_edv) 'HardwareID':'13'
2018-01-17 21:22:26.304 (compteur_edv) 'DomoticzVersion':'3.8809'
2018-01-17 21:22:26.304 (compteur_edv) 'Username':'4'
2018-01-17 21:22:26.304 (compteur_edv) 'HomeFolder':'/home/pi/domoticz/plugins/modbus-read/'
2018-01-17 21:22:26.304 (compteur_edv) 'Address':'192.168.1.21'
2018-01-17 21:22:26.304 (compteur_edv) 'Password':'1009'
2018-01-17 21:22:26.304 (compteur_edv) 'SerialPort':'/dev/serial0'
2018-01-17 21:22:26.305 (compteur_edv) 'Version':'1.0.4'
2018-01-17 21:22:26.305 (compteur_edv) 'Port':'502'
2018-01-17 21:22:26.305 (compteur_edv) 'Mode1':'tcp'
2018-01-17 21:22:26.305 (compteur_edv) 'Name':'compteur_edv'
2018-01-17 21:22:26.305 (compteur_edv) 'Mode6':'32int'
2018-01-17 21:22:26.305 (compteur_edv) 'Key':'Modbus'
2018-01-17 21:22:26.305 (compteur_edv) Device count: 1
2018-01-17 21:22:26.305 (compteur_edv) Device: 1 - ID: 173, Name: 'compteur_edv - ModbusDEV-READ', nValue: 0, sValue: '0'
2018-01-17 21:22:26.305 (compteur_edv) Device ID: '173'
2018-01-17 21:22:26.305 (compteur_edv) Device Name: 'compteur_edv - ModbusDEV-READ'
2018-01-17 21:22:26.305 (compteur_edv) Device nValue: 0
2018-01-17 21:22:26.305 (compteur_edv) Device sValue: '0'
2018-01-17 21:22:26.305 (compteur_edv) Device LastLevel: 0
2018-01-17 21:22:26.305 (compteur_edv) Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
2018-01-17 21:22:35.778 (compteur_edv) Calling message handler 'onHeartbeat'.
2018-01-17 21:22:35.778 (compteur_edv) MODBUS DEBUG TCP CMD - Method=tcp Address=192.168.1.21 Port=502 Register=1009 Registers to read=2 Data type=32int
2018-01-17 21:22:35.779 (compteur_edv) Modbus error communicating!, check your settings!
2018-01-17 21:22:35.779 (compteur_edv - ModbusDEV-READ) Updating device from 0:'0' to have values 0:'0'.
2018-01-17 21:22:35.789 (compteur_edv) Modbus error decoding (or recieved no data)!, check your settings!
2018-01-17 21:22:35.789 (compteur_edv - ModbusDEV-READ) Updating device from 0:'0' to have values 0:'0'.
2018-01-17 21:22:45.774 (compteur_edv) Calling message handler 'onHeartbeat'.
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Hi papoo,

Strange...but i will write you a example python code soon, to communicate with the device you can test in python(2), i have to know if the code is build up good for TCP 8-)
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by papoo »

ok
User avatar
McMelloW
Posts: 427
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by McMelloW »

Hallo Domoticx,

thanks for the great job you did on Domoticz-Modbus. This looks very interesting.

My Solarpanels are connected to a SolarEdge Inverter. SolarEdge says that you can read the data from this inverter via LAN/TCP and Modbus. The modus is according the SunSpec open protocol. See this document from SolarEdge for detailed information.
And here you can find a synspec python library

Does this plugins support the SunSpec open protocol and do you think I can use this plugin to read the dat from my SolarEdge, instead of via an API at https://monitoringapi.solaredge.com/...
Last edited by McMelloW on Saturday 20 January 2018 12:26, edited 1 time in total.
Greetings McMelloW
Arek84
Posts: 3
Joined: Friday 12 January 2018 18:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Poland
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Arek84 »

Is it possible to run this plug-in via esp8266?
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

McMelloW wrote: Friday 19 January 2018 20:56 Does this plugins support the SunSpec open protocol and do you think I can use this plugin to read the dat from my SolarEdge, instead of via an API at https://monitoringapi.solaredge.com/...
Hi, it is an universal plugin, good chance it will read out the data! ;)
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Arek84 wrote: Friday 19 January 2018 21:50 Is it possible to run this plug-in via esp8266?
You're pointing using an ESP8266 as modbus slave?, any example script to turn one into a slave?
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests