Page 3 of 21
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Saturday 20 January 2018 22:59
by Domoticx
@papoo
Here is a "plain" python script using TCP, can you test it on your setup, it should print out some (debug)data, just to see if the connection is ok
Alter the parameters when needed.
*edit updated the script to print out data values
Code: Select all
#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient
# configure the client logging
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
client = ModbusTcpClient('192.168.1.21', port=502)
# OR is a unit address (with TCP) also needed if there are more devices on one address?
# client = ModbusTcpClient('192.168.1.21', port=502, unit=1)
data = client.read_input_registers(1009, 2) # FUNCTION 04 - Read register 1009, length=2
print (data)
print (data.registers[0])
print (data.registers[1])
Install modbus for python(2)
use:
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Sunday 21 January 2018 13:42
by McMelloW
Domoticx wrote: ↑Saturday 20 January 2018 22:59
Here is a "plain" python script using TCP, can you test it on your setup, it should print out some (debug)data, just to see if the connection is ok
Alter the parameters when needed.
Code: Select all
#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient
# configure the client logging
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
client = ModbusTcpClient('192.168.1.21', port=502)
// OR is a unit address (with TCP) also needed if there are more devices on one address?
// client = ModbusTcpClient('192.168.1.21', port=502, unit=1)
data = client.read_input_registers(1009, 1) # FUNCTION 04 - Read register 1009, length=1
print (data)
Thanks for this script. Coming week I will test it when my SolarEdge is reconfigured for LAN/TCP over port 502. I will keep you informed on the results
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Sunday 21 January 2018 20:47
by Domoticx
Double
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Sunday 21 January 2018 22:08
by papoo
Code: Select all
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x5 0x0 0x4 0x2 0x0 0x1
DEBUG:pymodbus.factory:Factory Response[4]
DEBUG:pymodbus.transaction:adding transaction 1
DEBUG:pymodbus.transaction:getting transaction 1
ReadRegisterResponse (1)
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Sunday 21 January 2018 22:24
by papoo
if i modify your script like this :
Code: Select all
data = client.read_input_registers(1009, 2)
print (data.registers[0])
print (data.registers[1])
this is the result
Code: Select all
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x7 0x0 0x4 0x4 0x0 0x0 0x5b 0xa0
DEBUG:pymodbus.factory:Factory Response[4]
DEBUG:pymodbus.transaction:adding transaction 1
DEBUG:pymodbus.transaction:getting transaction 1
0
23456
my meter displays 236,56m3
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Sunday 21 January 2018 23:47
by Domoticx
@papoo,
Great!, so it works!

welcome to (py)modbus
Yes, printing the data out was the next step, i just want to be sure the code works with RegisterResponse...
Have you also used unit=1?
Ps. Can you post your whole working code here?, so i can see if the plugin needs to be updated somehow....because i can't see the problem...the domoticz pluginscript works the same way....
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Monday 22 January 2018 21:18
by papoo
unit=2 and result with data.registers[1]
Code: Select all
#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient
# configure the client logging
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
client = ModbusTcpClient('192.168.1.21', port=502)
# OR is a unit address (with TCP) also needed if there are more devices on one address?
# client = ModbusTcpClient('192.168.1.21', port=502, unit=1)
data = client.read_input_registers(1009, 2) # FUNCTION 04 - Read register 1009, length=1
print (data.registers[0])
print (data.registers[1])
# print (data.registers[2])
# print (data.registers[3])
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 0:14
by Domoticx
@papoo
unit=2??
did you use?
Code: Select all
client = ModbusTcpClient('192.168.1.21', port=502, unit=2)?
The 2 in
Code: Select all
client.read_input_registers(1009, 2)
is read 2 registers from offset 1009...
can you try this?:
add on top with imports:
Then use:
Code: Select all
data = client.read_input_registers(1010, 1) #Start @ register 1010, read 1 register
print round(data.registers[0]/100, 3)
should output what you want right?
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 0:53
by Domoticx
I've just released READ v1.0.5 (please restart domoticz after plugin update)
In this version i've added a passtrough option (no conversion, like a "string") with divide options (see screen @ bottom) and some decimal fixes!
Tested succesfully!
Ps. Can you try setup in domoticz:
- ip and port
- start register address: 1010
- read: 1
- Passtrough /100
Let me know if it worked! (of not....post LOG)

- domoticz modbus rs485 passtrough.jpg (122 KiB) Viewed 3405 times
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 11:12
by Domoticx
I've just released READ v1.0.6 (please restart domoticz after plugin update)
New features:
- Length of registers to read has been removed, this is now done automatic, based on datatype!
- Added divide option, so it can be used for all datatypes.
Enjoy!
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 20:22
by papoo
Domoticx wrote: ↑Wednesday 24 January 2018 0:14
@papoo
unit=2??
yes
Domoticx wrote: ↑Wednesday 24 January 2018 0:14
did you use?
Code: Select all
client = ModbusTcpClient('192.168.1.21', port=502, unit=2)?
The 2 in
Code: Select all
client.read_input_registers(1009, 2)
is read 2 registers from offset 1009...
yes
Domoticx wrote: ↑Wednesday 24 January 2018 0:14
can you try this?:
add on top with imports:
Then use:
Code: Select all
data = client.read_input_registers(1010, 1) #Start @ register 1010, read 1 register
print round(data.registers[0]/100, 3)
should output what you want right?
yes
Code: Select all
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x4 0x3 0xf2 0x0 0x1
DEBUG:pymodbus.transaction:recv: 0x0 0x1 0x0 0x0 0x0 0x5 0x0 0x4 0x2 0x5b 0xf0
DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x5 0x0 0x4 0x2 0x5b 0xf0
DEBUG:pymodbus.factory:Factory Response[4]
DEBUG:pymodbus.transaction:adding transaction 1
DEBUG:pymodbus.transaction:getting transaction 1
235.36
The v1.0.6 don't work's for me, domoticz crash

- 2018-01-24 20_15_57-Domoticz - Firefox Developer Edition.jpg (58.65 KiB) Viewed 3373 times
2018-01-24 20:12:33.523 Incoming connection from: 127.0.0.1
2018-01-24 20:15:31.687 (compteur_edv) Started.
2018-01-24 20:15:32.242 (compteur_edv) Entering work loop.
2018-01-24 20:15:32.244 (compteur_edv) Initialized version 1.0.6, author 'S. Ebeltjes / domoticx.nl'
2018-01-24 20:15:32.298 (compteur_edv) Debug log level set to: 'true'.
2018-01-24 20:15:32.298 (compteur_edv) 'Password':'1010'
2018-01-24 20:15:32.299 (compteur_edv) 'HardwareID':'13'
2018-01-24 20:15:32.299 (compteur_edv) 'HomeFolder':'/home/pi/domoticz/plugins/modbus-read/'
2018-01-24 20:15:32.299 (compteur_edv) 'Version':'1.0.6'
2018-01-24 20:15:32.299 (compteur_edv) 'DomoticzHash':'8c2cc0ba'
2018-01-24 20:15:32.299 (compteur_edv) 'Mode2':'9600'
2018-01-24 20:15:32.299 (compteur_edv) 'Mode1':'tcp'
2018-01-24 20:15:32.299 (compteur_edv) 'Mode6':'pass'
2018-01-24 20:15:32.299 (compteur_edv) 'Username':'4'
2018-01-24 20:15:32.299 (compteur_edv) 'Address':'192.168.1.21'
2018-01-24 20:15:32.299 (compteur_edv) 'Name':'compteur_edv'
2018-01-24 20:15:32.299 (compteur_edv) 'Mode4':'debug'
2018-01-24 20:15:32.299 (compteur_edv) 'Mode5':'div100'
2018-01-24 20:15:32.299 (compteur_edv) 'DomoticzVersion':'3.8834'
2018-01-24 20:15:32.299 (compteur_edv) 'Port':'502'
2018-01-24 20:15:32.299 (compteur_edv) 'Mode3':'S1B8PN'
2018-01-24 20:15:32.299 (compteur_edv) 'Key':'Modbus'
2018-01-24 20:15:32.299 (compteur_edv) 'SerialPort':'/dev/serial0'
2018-01-24 20:15:32.300 (compteur_edv) 'Author':'S. Ebeltjes / domoticx.nl'
2018-01-24 20:15:32.300 (compteur_edv) 'DomoticzBuildTime':'2018-01-22 13:19:13'
2018-01-24 20:15:32.300 (compteur_edv) Device count: 1
2018-01-24 20:15:32.300 (compteur_edv) Device: 1 - ID: 173, Name: 'compteur_edv - ModbusDEV-READ', nValue: 0, sValue: '0'
2018-01-24 20:15:32.300 (compteur_edv) Device ID: '173'
2018-01-24 20:15:32.300 (compteur_edv) Device Name: 'compteur_edv - ModbusDEV-READ'
2018-01-24 20:15:32.300 (compteur_edv) Device nValue: 0
2018-01-24 20:15:32.300 (compteur_edv) Device sValue: '0'
2018-01-24 20:15:32.300 (compteur_edv) Device LastLevel: 0
2018-01-24 20:15:32.300 (compteur_edv) Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
2018-01-24 20:16:38.229 Domoticz V3.8834 (c)2012-2018 GizMoCuz
2018-01-24 20:16:38.229 Build Hash: 8c2cc0ba, Date: 2018-01-22 13:19:13
2018-01-24 20:16:38.230 Startup Path: /home/pi/domoticz/
2018-01-24 20:16:38.290 Sunrise: 08:25:00 SunSet: 17:49:00
2018-01-24 20:16:38.290 Day length: 09:24:00 Sun at south: 13:05:00
2018-01-24 20:16:38.290 Civil twilight start: 07:53:00 Civil twilight end: 18:21:00
2018-01-24 20:16:38.290 Nautical twilight start: 07:17:00 Nautical twilight end: 18:57:00
2018-01-24 20:16:38.290 Astronomical twilight start: 06:41:00 Astronomical twilight end: 19:33:00
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 20:37
by Domoticx
@papoo
To clearify for TCP....in the example code, did you use?
1)
Code: Select all
client = ModbusTcpClient('192.168.1.21', port=502)?
or did you use?
2)
Code: Select all
client = ModbusTcpClient('192.168.1.21', port=502, unit=2)?
------------
Ps. It keeps crashing?, it does not crash @ my side, please remove all domoticz hardware regarding this plugin (do not update and alter settings on existing domoticz modbus hardware)
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 20:53
by papoo
Code: Select all
client = ModbusTcpClient('192.168.1.21', port=502)
i remove all domoticz hardware, only modbus
It crash when this log appear
Code: Select all
Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 21:18
by Domoticx
Released v1.0.7
Changes:
- Fixed variable error (used before declaration)
@papoo,
Can you try this one?
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 21:29
by papoo
you don't update version number
y update on my version
same problem
2018-01-24 21:26:36.138 (compteur_edv) Started.
2018-01-24 21:26:38.292 (compteur_edv) Entering work loop.
2018-01-24 21:26:38.294 (compteur_edv) Initialized version 1.0.7, author 'S. Ebeltjes / domoticx.nl'
2018-01-24 21:26:38.349 (compteur_edv) Debug log level set to: 'true'.
2018-01-24 21:26:38.349 (compteur_edv) 'Password':'1010'
2018-01-24 21:26:38.349 (compteur_edv) 'Name':'compteur_edv'
2018-01-24 21:26:38.350 (compteur_edv) 'DomoticzBuildTime':'2018-01-22 13:19:13'
2018-01-24 21:26:38.350 (compteur_edv) 'DomoticzVersion':'3.8834'
2018-01-24 21:26:38.350 (compteur_edv) 'Port':'502'
2018-01-24 21:26:38.350 (compteur_edv) 'Mode1':'tcp'
2018-01-24 21:26:38.350 (compteur_edv) 'DomoticzHash':'8c2cc0ba'
2018-01-24 21:26:38.350 (compteur_edv) 'SerialPort':'/dev/ttyAMA0'
2018-01-24 21:26:38.350 (compteur_edv) 'Author':'S. Ebeltjes / domoticx.nl'
2018-01-24 21:26:38.350 (compteur_edv) 'Username':'4'
2018-01-24 21:26:38.350 (compteur_edv) 'HardwareID':'13'
2018-01-24 21:26:38.350 (compteur_edv) 'Mode4':'debug'
2018-01-24 21:26:38.350 (compteur_edv) 'Address':'192.168.1.21'
2018-01-24 21:26:38.350 (compteur_edv) 'Key':'Modbus'
2018-01-24 21:26:38.350 (compteur_edv) 'Mode5':'div100'
2018-01-24 21:26:38.351 (compteur_edv) 'Version':'1.0.7'
2018-01-24 21:26:38.351 (compteur_edv) 'Mode6':'pass'
2018-01-24 21:26:38.351 (compteur_edv) 'Mode3':'S1B8PN'
2018-01-24 21:26:38.351 (compteur_edv) 'HomeFolder':'/home/pi/domoticz/plugins/modbus-read/'
2018-01-24 21:26:38.351 (compteur_edv) 'Mode2':'9600'
2018-01-24 21:26:38.351 (compteur_edv) Device count: 1
2018-01-24 21:26:38.351 (compteur_edv) Device: 1 - ID: 173, Name: 'compteur_edv - ModbusDEV-READ', nValue: 0, sValue: '0'
2018-01-24 21:26:38.351 (compteur_edv) Device ID: '173'
2018-01-24 21:26:38.351 (compteur_edv) Device Name: 'compteur_edv - ModbusDEV-READ'
2018-01-24 21:26:38.351 (compteur_edv) Device nValue: 0
2018-01-24 21:26:38.351 (compteur_edv) Device sValue: '0'
2018-01-24 21:26:38.351 (compteur_edv) Device LastLevel: 0
2018-01-24 21:26:38.352 (compteur_edv) Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 21:37
by papoo
ma domoticz version bêta 3.8834
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 21:38
by Domoticx
Lol something went wrong when "pushing to origin", the release is now live
https://github.com/DomoticX/domoticz-mo ... 2aebe9d488
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 21:39
by Domoticx
papoo wrote: ↑Wednesday 24 January 2018 21:37
ma domoticz version bêta 3.8834
Can you try to make SD card and run v3.8153?
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Wednesday 24 January 2018 22:00
by papoo
same problem with this version
2018-01-24 21:57:18.744 (edv) Entering work loop.
2018-01-24 21:57:18.746 (edv) Initialized version 1.0.7, author 'S. Ebeltjes / domoticx.nl'
2018-01-24 21:57:18.750 (edv) Debug log level set to: 'true'.
2018-01-24 21:57:18.750 (edv) 'Key':'Modbus'
2018-01-24 21:57:18.750 (edv) 'Mode2':'9600'
2018-01-24 21:57:18.751 (edv) 'DomoticzVersion':'3.8834'
2018-01-24 21:57:18.751 (edv) 'DomoticzHash':'8c2cc0ba'
2018-01-24 21:57:18.751 (edv) 'Name':'edv'
2018-01-24 21:57:18.751 (edv) 'Mode3':'S1B8PN'
2018-01-24 21:57:18.751 (edv) 'DomoticzBuildTime':'2018-01-22 13:19:13'
2018-01-24 21:57:18.751 (edv) 'Username':'4'
2018-01-24 21:57:18.751 (edv) 'Mode5':'div100'
2018-01-24 21:57:18.751 (edv) 'Mode4':'debug'
2018-01-24 21:57:18.751 (edv) 'Password':'1010'
2018-01-24 21:57:18.751 (edv) 'Port':'502'
2018-01-24 21:57:18.751 (edv) 'Author':'S. Ebeltjes / domoticx.nl'
2018-01-24 21:57:18.751 (edv) 'SerialPort':'/dev/serial0'
2018-01-24 21:57:18.751 (edv) 'Address':'192.168.1.21'
2018-01-24 21:57:18.751 (edv) 'Version':'1.0.7'
2018-01-24 21:57:18.751 (edv) 'HardwareID':'13'
2018-01-24 21:57:18.751 (edv) 'Mode6':'pass'
2018-01-24 21:57:18.752 (edv) 'Mode1':'tcp'
2018-01-24 21:57:18.752 (edv) 'HomeFolder':'/home/pi/domoticz/plugins/modbus-read/'
2018-01-24 21:57:18.752 (edv) Device count: 1
2018-01-24 21:57:18.752 (edv) Device: 1 - ID: 173, Name: 'compteur_edv - ModbusDEV-READ', nValue: 0, sValue: '0'
2018-01-24 21:57:18.752 (edv) Device ID: '173'
2018-01-24 21:57:18.752 (edv) Device Name: 'compteur_edv - ModbusDEV-READ'
2018-01-24 21:57:18.752 (edv) Device nValue: 0
2018-01-24 21:57:18.752 (edv) Device sValue: '0'
2018-01-24 21:57:18.752 (edv) Device LastLevel: 0
2018-01-24 21:57:18.752 (edv) Modbus RS485 RTU/ASCII/TCP - Universal READ loaded.
for release version of domoticz not today, not enough time
Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP
Posted: Thursday 25 January 2018 15:58
by palmipete
Hello,
first of all, great !!! it looks really nice ... in theory.
in practice, I did not get it working ...
I think I installed all as described (plugin folders, I installed pymodbus in python 3, but I get this in the log:
2018-01-25 15:38:55.416 Domoticz V3.8153 (c)2012-2017 GizMoCuz
2018-01-25 15:38:55.416 Build Hash: 494fff7, Date: 2017-07-30 12:19:41
2018-01-25 15:38:55.417 Startup Path: /home/domoticz/domoticz/
2018-01-25 15:38:56.288 PluginSystem: Started, Python version '3.5.3'.
2018-01-25 15:38:56.299 Active notification Subsystems: gcm, http (2/12)
2018-01-25 15:38:56.337 WebServer(HTTP) started on address: :: with port 8080
2018-01-25 15:38:56.359 WebServer(SSL) started on address: :: with port 443
2018-01-25 15:38:56.361 Proxymanager started.
2018-01-25 15:38:56.362 Starting shared server on: :::6144
2018-01-25 15:38:56.362 TCPServer: shared server started...
2018-01-25 15:38:56.363 RxQueue: queue worker started...
2018-01-25 15:38:58.365 Hardware Monitor: Started
2018-01-25 15:38:58.397 EventSystem: reset all events...
2018-01-25 15:38:58.430 EventSystem: reset all device statuses...
2018-01-25 15:38:58.603 Python EventSystem: Module not found - Trying to initialize.
2018-01-25 15:38:58.603 Python EventSystem: Initalizing event module.
2018-01-25 15:38:58.604 EventSystem: Started
2018-01-25 15:38:58.692 PluginSystem: Entering work loop.
2018-01-25 15:38:59.134 Error: (Modbus) failed to load 'plugin.py', Python Path used was '/home/domoticz/domoticz/plugins/modbus-read/:/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'.
2018-01-25 15:38:59.135 Error: (energy) Module Import failed, exception: 'ImportError'
2018-01-25 15:38:59.135 Error: (energy) Module Import failed: ' Name: six'
Python script without import domoticz shows no errors.
I tried to put comments for the log, but I think the error happens before I can put errors in the log
I also tried to put some prints, but I do not know how to see them ...
I am new in Domoticz (I know and handled modbus and also succeeded on the same machine to talk to the modbus object).
thanks in advance
Peter
I tried to put