Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
DomoticX committed May 12, 2020
1 parent 6c8c75c commit ff6f56a
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 127 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### Modbus Read/Write Plugins for Domoticz
Author: Sebastiaan Ebeltjes / DomoticX.nl

Succesfully Tested on Domoticz version: 2020.2
Succesfully Tested on Domoticz version: 2020.2 stable

You can update domoticz with command: ```cd /home/pi/domoticz | ./updaterelease```

**Support for:**

Expand Down Expand Up @@ -68,7 +70,7 @@ Then restart domoticz with: ```sudo service domoticz.sh restart```
-----
### Dependancies

1. Raspbian image (FULL version recommended)
1. RPi: Raspbian image (FULL version recommended)
2. additional python3 libraries:

**pymodbus AND pymodbusTCP**
Expand Down
153 changes: 74 additions & 79 deletions changelog.txt → modbus-read/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,79 +1,74 @@
Modbus WRITE v2020.2B
- Added proper description

Modbus WRITE v2020.2A
- Added: version checks and notification for needed dependancies
- Improved: TCP IP and PORT options now merged
- Improved: option descriptions, sorted options
- Optimized: Debug lines and info
- Optimized: All settings read once at plugin start
- Code cleanup

Modbus READ v2020.2D
- Optimized: Added default device name
- Optimized: Debug lines and info

Modbus READ v2020.2C
- Added: Plugin description
- Optimized: All settings read once at plugin start
- Optimized: Better log, debug, error usage.
- Fixed: Bug for device update on TCP/IP (on error)
- Code cleanup

Modbus READ v2020.2B
- Added: Device polling rate setting (seconds) (e.g. ID:POLL = 1:10 then Device ID=1 and Pollingrate=10 seconds)
- Added: Some more debug lines for value output and pollingrate (heartbeat)

Modbus READ v2020.2A
- Fixed: "no data found check settings" for new domoticz v2020.x
- Fixed: default settings are now filled correctly
- Added: BOOL conversion (for read coils...not tested on hardware)
- Added: version checks and notification for needed dependancies
- Added: ability for debug yes/no (for easy troubleshooting)
- Improved: TCP IP and PORT options now merged
- Improved: option descriptions, sorted options
- Code cleanup

v2.0.0
- Fixed exception in modbus library (added .registers again)
- New plugin: modbus-device [bramvreugd]
- With this plugin you can add a device with many registers at once

v1.2.1
- Fixed the exception "Modbus Error: [Invalid Parameter] Invalid collection of registers supplied" on my Raspberry/Domoticz

v1.2.0
- Fixed TAB error.

v1.1.9
- Fixed debug output [Sandolution]

v1.1.8
- Added "sys.path.append('/usr/local/lib/python3.5/dist-packages')" in the begining for modern python libraries compatibility. [akliouev]
- After wrestling for a day finaly found out that "data" is a list and doesn't have method ".registers" associated with it. [akliouev]
Must be remnants of older pymodbus versions. Changed "data.registers" -> "data". [akliouev]
- Fix: line 403 was verifying that Username is "1" (only "read coil") and otherwise wasn't updating anything. [akliouev]

v1.1.7
- Removed debug option due to implementation of sensor type. [Sandolution]
- Added more options for data type (swapping of low/high byte/word). [Sandolution]
- Adjusted dividing settings to include 10000. [Sandolution]
- Added more append paths [Sandolution]

v1.1.6
- Added import RTU framer for RTU over TCP to work. [Sandolution]
- Fix for unit id on RTU over TCP [Sandolution]

v1.1.5
- Added ID option for IP/TCP addresses. [S. Ebeltjes]

v1.1.4
- Removed debug option due to implementation of sensor type. [Sandolution]
- Added more options for data type (swapping of low/high byte/word). [Sandolution]
- Adjusted dividing settings to include 10000. [Sandolution]

TODO: float decode word orders
float AB CD == byteorder=Endian.Big, wordorder=Endian.Big
float CD AB == byteorder=Endian.Big, wordorder=Endian.Little
float BA DC == byteorder=Endian.Little, wordorder=Endian.Big
float DC BA == byteorder=Endian.Little, wordorder=Endian.Little
Modbus READ v2020.2E
- Fixed: Plugin not starting in unreleased beta versions (dependancies check)
- Fixed: Default function set to to read holding registers.
- Improved: option and plugin descriptions
- Optimized: timeout on all methods set to 2 seconds.

Modbus READ v2020.2D
- Optimized: Added default device name
- Optimized: Debug lines and info

Modbus READ v2020.2C
- Added: Plugin description
- Optimized: All settings read once at plugin start
- Optimized: Better log, debug, error usage.
- Fixed: Bug for device update on TCP/IP (on error)
- Code cleanup

Modbus READ v2020.2B
- Added: Device polling rate setting (seconds) (e.g. ID:POLL = 1:10 then Device ID=1 and Pollingrate=10 seconds)
- Added: Some more debug lines for value output and pollingrate (heartbeat)

Modbus READ v2020.2A
- Fixed: "no data found check settings" for new domoticz v2020.x
- Fixed: default settings are now filled correctly
- Added: BOOL conversion (for read coils...not tested on hardware)
- Added: version checks and notification for needed dependancies
- Added: ability for debug yes/no (for easy troubleshooting)
- Improved: TCP IP and PORT options now merged
- Improved: option descriptions, sorted options
- Code cleanup

v2.0.0
- Fixed exception in modbus library (added .registers again)
- New plugin: modbus-device [bramvreugd]
- With this plugin you can add a device with many registers at once

v1.2.1
- Fixed the exception "Modbus Error: [Invalid Parameter] Invalid collection of registers supplied" on my Raspberry/Domoticz

v1.2.0
- Fixed TAB error.

v1.1.9
- Fixed debug output [Sandolution]

v1.1.8
- Added "sys.path.append('/usr/local/lib/python3.5/dist-packages')" in the begining for modern python libraries compatibility. [akliouev]
- After wrestling for a day finaly found out that "data" is a list and doesn't have method ".registers" associated with it. [akliouev]
Must be remnants of older pymodbus versions. Changed "data.registers" -> "data". [akliouev]
- Fix: line 403 was verifying that Username is "1" (only "read coil") and otherwise wasn't updating anything. [akliouev]

v1.1.7
- Removed debug option due to implementation of sensor type. [Sandolution]
- Added more options for data type (swapping of low/high byte/word). [Sandolution]
- Adjusted dividing settings to include 10000. [Sandolution]
- Added more append paths [Sandolution]

v1.1.6
- Added import RTU framer for RTU over TCP to work. [Sandolution]
- Fix for unit id on RTU over TCP [Sandolution]

v1.1.5
- Added ID option for IP/TCP addresses. [S. Ebeltjes]

v1.1.4
- Removed debug option due to implementation of sensor type. [Sandolution]
- Added more options for data type (swapping of low/high byte/word). [Sandolution]
- Adjusted dividing settings to include 10000. [Sandolution]

TODO: float decode word orders
float AB CD == byteorder=Endian.Big, wordorder=Endian.Big
float CD AB == byteorder=Endian.Big, wordorder=Endian.Little
float BA DC == byteorder=Endian.Little, wordorder=Endian.Big
float DC BA == byteorder=Endian.Little, wordorder=Endian.Little
55 changes: 31 additions & 24 deletions modbus-read/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Modbus RTU/ASCII/TCP - Universal READ Plugin for Domoticz
# Modbus RTU / ASCII / TCP/IP - Universal READ Plugin for Domoticz
#
# Tested on domoticz 2020.2 with Python v3.7.3 and pymodbus v2.3.0
# Tested on domoticz 2020.2 (stable) with Python v3.7.3 and pymodbus v2.3.0
#
# Author: Sebastiaan Ebeltjes / DomoticX.nl
# RTU Serial HW: USB RS485-Serial Stick, like https://webshop.domoticx.nl/index.php?route=product/search&search=RS485%20RTU%20USB
Expand All @@ -11,20 +11,24 @@
#

"""
<plugin key="ModbusREAD" name="Modbus RTU/ASCII/TCP - READ v2020.2D" author="S. Ebeltjes / DomoticX.nl" version="2020.2D" externallink="" wikilink="https://github.com/DomoticX/domoticz-modbus">
<plugin key="ModbusREAD" name="Modbus RTU / ASCII / TCP/IP - READ v2020.2E" author="S. Ebeltjes / DomoticX.nl" version="2020.2E" externallink="http://domoticx.nl" wikilink="https://github.com/DomoticX/domoticz-modbus">
<description>
<h3>Modbus RTU/ASCII/TCP - READ</h3>
With this plugin you can readout RS485 Modbus devices with methods RTU/ASCII/TCP<br/>
<h3>Modbus RTU / ASCII / TCP/IP - READ</h3>
With this plugin you can read from RS485 Modbus devices with methods RTU/ASCII/TCP<br/>
<br/>
<h3>Functions of the READ plugin:</h3>
Read Coil (Function 1)<br/>
Read Discrete Input (Function 2)<br/>
Read Holding Registers (Function 3)<br/>
Read Input Registers (Function 4)<br/>
<h4>RTU</h4>
The serial binary communication protocol. It is the communication standard that<br/>
became widely used and all series of PLC's and other device producers support it.<br/>
It goes about the network protocol of the 1Master x nSlave type. The Slave devices can be 254 at the most.<br/>
<h4>ASCII</h4>
This protocol is similar to Modbus RTU, but the binary content is transformed to common ASCII characters.<br/>
It is not used as frequently as Modbus RTU.<br/>
<h4>RTU over TCP</h4>
Means a MODBUS RTU packet wrapped in a TCP packet. The message bytes are modified to add the 6 byte MBAP header and remove the two byte CRC.
<h4>TCP/IP</h4>
It is a network protocol - classic Ethernet TCP/IP with the 10/100 Mbit/s speed rate, a standard net HW Ethernet card is sufficient.<br/>
The communication principle (1Master x nSlave) is the same as for Modbus RTU.<br/>
<br/>
<h3>Supported data types:</h3>
No conversion (passtrough) / BOOL / INT / UINT / FLOAT / STRING<br/>
<br/>
<h3>Set-up and Configuration:</h3>
See wiki link above.<br/>
</description>
Expand All @@ -33,8 +37,8 @@
<options>
<option label="RTU" value="rtu:rtu" default="true"/>
<option label="RTU (+DEBUG)" value="rtu:debug"/>
<option label="ASCII" value="ascii:ascii"/>
<option label="ASCII (+DEBUG)" value="ascii:debug"/>
<option label="RTU ASCII" value="ascii:ascii"/>
<option label="RTU ASCII (+DEBUG)" value="ascii:debug"/>
<option label="RTU over TCP" value="rtutcp:rtutcp"/>
<option label="RTU over TCP (+DEBUG)" value="rtutcp:debug"/>
<option label="TCP/IP" value="tcpip:tcpip"/>
Expand Down Expand Up @@ -71,14 +75,14 @@
<option label="115200" value="115200"/>
</options>
</param>
<param field="Address" label="TCP - IP:Port" width="140px" default="192.168.2.1:501"/>
<param field="Address" label="TCP/IP - IP:Port" width="140px" default="192.168.2.1:501"/>
<param field="Password" label="Device ID:Pollingrate(sec)" width="50px" default="1:10" required="true"/>
<param field="Username" label="Modbus Function" width="250px" required="true">
<options>
<option label="Read Coil (Function 1)" value="1"/>
<option label="Read Discrete Input (Function 2)" value="2"/>
<option label="Read Holding Registers (Function 3)" value="3"/>
<option label="Read Input Registers (Function 4)" value="4" default="true"/>
<option label="Read Holding Registers (Function 3)" value="3" default="true"/>
<option label="Read Input Registers (Function 4)" value="4"/>
</options>
</param>
<param field="Port" label="Register number" width="50px" default="1" required="true"/>
Expand Down Expand Up @@ -188,9 +192,12 @@ def onStart(self):
Domoticz.Log("Modbus RTU/ASCII/TCP - Universal READ loaded!, using python v" + sys.version[:6] + " and pymodbus v" + pymodbus.__version__)

# Dependancies notification
if (float(Parameters["DomoticzVersion"]) < float("2020.2")): Domoticz.Error("WARNING: Domoticz version is outdated/not supported, please update!")
if (float(sys.version[:1]) < 3): Domoticz.Error("WARNING: Python3 should be used!")
if (float(pymodbus.__version__[:3]) < float("2.3")): Domoticz.Error("WARNING: Pymodbus version is outdated, please update!")
try:
if (float(Parameters["DomoticzVersion"][:6]) < float("2020.2")): Domoticz.Error("WARNING: Domoticz version is outdated/not supported, please update!")
if (float(sys.version[:1]) < 3): Domoticz.Error("WARNING: Python3 should be used!")
if (float(pymodbus.__version__[:3]) < float("2.3")): Domoticz.Error("WARNING: Pymodbus version is outdated, please update!")
except:
Domoticz.Error("WARNING: Dependancies could not be checked!")

########################################
# READ-IN OPTIONS AND SETTINGS
Expand Down Expand Up @@ -312,7 +319,7 @@ def onHeartbeat(self):
Domoticz.Debug("MODBUS DEBUG - INTERFACE: Port="+self.Domoticz_Setting_Serial_Port+", BaudRate="+self.Domoticz_Setting_Baudrate+", StopBits="+str(self.StopBits)+", ByteSize="+str(self.ByteSize)+" Parity="+self.Parity)
Domoticz.Debug("MODBUS DEBUG - SETTINGS: Method="+self.Domoticz_Setting_Communication_Mode+", Device ID="+self.Domoticz_Setting_Device_ID+", Register="+self.Domoticz_Setting_Register_Number+", Function="+self.Domoticz_Setting_Modbus_Function+", Data type="+self.Domoticz_Setting_Data_Type+", Pollrate="+self.Domoticz_Setting_Device_Pollrate)
try:
client = ModbusSerialClient(method=self.Domoticz_Setting_Communication_Mode, port=self.Domoticz_Setting_Serial_Port, stopbits=self.StopBits, bytesize=self.ByteSize, parity=self.Parity, baudrate=int(self.Domoticz_Setting_Baudrate), timeout=1, retries=2)
client = ModbusSerialClient(method=self.Domoticz_Setting_Communication_Mode, port=self.Domoticz_Setting_Serial_Port, stopbits=self.StopBits, bytesize=self.ByteSize, parity=self.Parity, baudrate=int(self.Domoticz_Setting_Baudrate), timeout=2, retries=2)
except:
Domoticz.Error("Error opening Serial interface on "+self.Domoticz_Setting_Serial_Port)
Devices[1].Update(1, "0") # Set value to 0 (error)
Expand All @@ -324,7 +331,7 @@ def onHeartbeat(self):
Domoticz.Debug("MODBUS DEBUG - INTERFACE: IP:Port="+self.Domoticz_Setting_TCP_IP+":"+self.Domoticz_Setting_TCP_PORT)
Domoticz.Debug("MODBUS DEBUG - SETTINGS: Method="+self.Domoticz_Setting_Communication_Mode+", Device ID="+self.Domoticz_Setting_Device_ID+", Register="+self.Domoticz_Setting_Register_Number+", Function="+self.Domoticz_Setting_Modbus_Function+", Data type="+self.Domoticz_Setting_Data_Type+", Pollrate="+self.Domoticz_Setting_Device_Pollrate)
try:
client = ModbusTcpClient(host=self.Domoticz_Setting_TCP_IP, port=int(self.Domoticz_Setting_TCP_PORT), framer=ModbusRtuFramer, auto_open=True, auto_close=True, timeout=5)
client = ModbusTcpClient(host=self.Domoticz_Setting_TCP_IP, port=int(self.Domoticz_Setting_TCP_PORT), framer=ModbusRtuFramer, auto_open=True, auto_close=True, timeout=2)
except:
Domoticz.Error("Error opening RTU over TCP interface on address: "+self.Domoticz_Setting_TCP_IPPORT)
Devices[1].Update(1, "0") # Set value to 0 (error)
Expand All @@ -336,7 +343,7 @@ def onHeartbeat(self):
Domoticz.Debug("MODBUS DEBUG - INTERFACE: IP:Port="+self.Domoticz_Setting_TCP_IP+":"+self.Domoticz_Setting_TCP_PORT)
Domoticz.Debug("MODBUS DEBUG - SETTINGS: Method="+self.Domoticz_Setting_Communication_Mode+", Device ID="+self.Domoticz_Setting_Device_ID+", Register="+self.Domoticz_Setting_Register_Number+", Function="+self.Domoticz_Setting_Modbus_Function+", Data type="+self.Domoticz_Setting_Data_Type+", Pollrate="+self.Domoticz_Setting_Device_Pollrate)
try:
client = ModbusClient(host=self.Domoticz_Setting_TCP_IP, port=int(self.Domoticz_Setting_TCP_PORT), unit_id=int(self.Domoticz_Setting_Device_ID), auto_open=True, auto_close=True, timeout=5)
client = ModbusClient(host=self.Domoticz_Setting_TCP_IP, port=int(self.Domoticz_Setting_TCP_PORT), unit_id=int(self.Domoticz_Setting_Device_ID), auto_open=True, auto_close=True, timeout=2)
except:
Domoticz.Error("Error opening TCP/IP interface on address: "+self.Domoticz_Setting_TCP_IPPORT)
Devices[1].Update(1, "0") # Set value to 0 (error)
Expand Down
59 changes: 59 additions & 0 deletions modbus-write/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Modbus WRITE v2020.2C
- Fixed: Plugin not starting in unreleased beta versions (dependancies check)
- Improved: option and plugin descriptions
- Optimized: timeout on all methods set to 2 seconds.

Modbus WRITE v2020.2B
- Added: proper plugin description

Modbus WRITE v2020.2A
- Added: version checks and notification for needed dependancies
- Improved: TCP IP and PORT options now merged
- Improved: option descriptions, sorted options
- Optimized: Debug lines and info
- Optimized: All settings read once at plugin start
- Code cleanup

v2.0.0
- Fixed exception in modbus library (added .registers again)
- New plugin: modbus-device [bramvreugd]
- With this plugin you can add a device with many registers at once

v1.2.1
- Fixed the exception "Modbus Error: [Invalid Parameter] Invalid collection of registers supplied" on my Raspberry/Domoticz

v1.2.0
- Fixed TAB error.

v1.1.9
- Fixed debug output [Sandolution]

v1.1.8
- Added "sys.path.append('/usr/local/lib/python3.5/dist-packages')" in the begining for modern python libraries compatibility. [akliouev]
- After wrestling for a day finaly found out that "data" is a list and doesn't have method ".registers" associated with it. [akliouev]
Must be remnants of older pymodbus versions. Changed "data.registers" -> "data". [akliouev]
- Fix: line 403 was verifying that Username is "1" (only "read coil") and otherwise wasn't updating anything. [akliouev]

v1.1.7
- Removed debug option due to implementation of sensor type. [Sandolution]
- Added more options for data type (swapping of low/high byte/word). [Sandolution]
- Adjusted dividing settings to include 10000. [Sandolution]
- Added more append paths [Sandolution]

v1.1.6
- Added import RTU framer for RTU over TCP to work. [Sandolution]
- Fix for unit id on RTU over TCP [Sandolution]

v1.1.5
- Added ID option for IP/TCP addresses. [S. Ebeltjes]

v1.1.4
- Removed debug option due to implementation of sensor type. [Sandolution]
- Added more options for data type (swapping of low/high byte/word). [Sandolution]
- Adjusted dividing settings to include 10000. [Sandolution]

TODO: float decode word orders
float AB CD == byteorder=Endian.Big, wordorder=Endian.Big
float CD AB == byteorder=Endian.Big, wordorder=Endian.Little
float BA DC == byteorder=Endian.Little, wordorder=Endian.Big
float DC BA == byteorder=Endian.Little, wordorder=Endian.Little
Loading

0 comments on commit ff6f56a

Please sign in to comment.