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

Python and python framework
Post Reply
Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

[RELEASED] Python plugin: Modbus RTU / ASCII / TCP/IP

Post by Domoticx » Monday 08 January 2018 0:07

DOWNLOAD
You can download the plugin directly from here: https://github.com/DomoticX/domoticz-mo ... master.zip
Project @ GitHub: https://github.com/DomoticX/domoticz-modbus

Please note: Tested and working on Domoticz stable v3.8153 and may not work on some beta versions, i can't give support for (all) beta versions.

MASTER Hardware
RTU RS485
- Raspberry Pi / Windows - USB RS485 to Serial stick: http://domoticx.nl/webwinkel/index.php? ... uct_id=386
TCP/IP
- Nothing specific

SLAVE Hardware (examples)
RTU RS485
- Relais module 12V, 4x250V/10A NO/NC Modbus RS485: http://domoticx.com/modbus-relaisbord/
- KWh meter – DDS238-1 ZN: http://domoticx.com/modbus-kwh-meter-dds238-1-zn/
- KWh meter – Eastron SDM120: http://domoticx.com/modbus-kwh-meter-eastron-sdm120/
- KWh meter – Socomec Countis E03: http://domoticx.com/modbus-kwh-meter-so ... untis-e03/
- D/A converter – HY4AO: http://domoticx.com/modbus-d-a-converter-hy4ao/

Create your own MODBUS SLAVES! :ugeek:
RTU RS485
- Arduino UNO/MEGA/NANO/MINI: http://domoticx.com/arduino-modbus-rs485-rtu-slave/
TCP/IP
- Arduino UNO/MEGA & Ethernet W5100 shield: http://domoticx.com/arduino-shield-ethe ... -ip-slave/
- Arduino UNO/MEGA/NANO/MINI & ENC28J60 module: http://domoticx.com/module-ethernet-lan ... -ip-slave/
- Wire the ENC28J60 module: http://domoticx.com/module-ethernet-lan ... -enc28j60/
TCP/IP Wireless
- ESP8266/NodeMCU/Wemos: http://domoticx.com/esp8266-wifi-modbus-tcp-ip-slave/

SIMULATOR
No hardware? try a Modbus simulator: https://sourceforge.net/projects/modrssim/
-----------------------------
So i am using Domoticz (again) now for 3 days (before that trying OpenHab) and see it's maturity has grown since the last years!, very nice! so i installed it all again....and still no Modbus, M-bus, KNX, KAKU TCP-200/300 support!

I also use pymodbus to readout and switch some Modbus stuff you can read here on this page: http://domoticx.com/io-interface/

So.....after many many hours of learning and experimenting...trial and error (since python 3 is pretty new for me) about how to build a Domoticz Python plugin, i have almost finished the first Modbus plugin for Domoticz !!

I still have to make some small adjustments (de puntjes op de "i") and post it on github and wiki so we can all improve it to make it better!

For now i have implemented the SWITCH function for ON/OFF usage (READ functions need to be build but that should be easy, any help is welcome)

I'll try to release the plugin this week!

Here is a sneek peek:
modbusrtu domoticz.png
modbusrtu domoticz.png (125.39 KiB) Viewed 8425 times
modbusrtu functions domoticz.png
modbusrtu functions domoticz.png (29 KiB) Viewed 8425 times
Logs:

Code: Select all

2018-01-07 20:41:55.300 (TEST) onCommand called for Unit 1: Parameter 'Off', Level: 0
2018-01-07 20:41:55.300 (TEST) MODBUS DEBUG HW - Port=/dev/ttyUSB0 BaudRate=9600 StopBits=1 ByteSize=8 Parity=N
2018-01-07 20:41:55.300 (TEST) MODBUS DEBUG CMD - Address=1 Register=4 Function=6 PayLoadON=0x0100 PayLoadOFF=0x0200
Last edited by Domoticx on Monday 12 March 2018 21:46, edited 25 times 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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Monday 08 January 2018 0:10

Ps. There will be 2 universal plugins, one to READ and one to WRITE :D
modbus domoticz universal write 01.png
modbus domoticz universal write 01.png (146.07 KiB) Viewed 8421 times
modbus domoticz universal write 02.png
modbus domoticz universal write 02.png (64.21 KiB) Viewed 8421 times
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!)

miljume
Posts: 80
Joined: Thursday 03 December 2015 22:36
Target OS: Raspberry Pi
Domoticz version: v3.8742
Contact:

Re: Python plugin: Modbus Universal

Post by miljume » Monday 08 January 2018 10:35

Really great work!

Any chance you will include Modbus TCP support as well?

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Monday 08 January 2018 19:49

miljume wrote:
Monday 08 January 2018 10:35
Really great work!

Any chance you will include Modbus TCP support as well?
Well that should be possible i have to merge/abuse some settings then :lol:

Also i don't have any Modbus TCP laying around, so i can write psuedo code so people can test it out!
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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Monday 08 January 2018 21:14

So i had to crank some (serial) settings into eachother (stopbit, bytesize, parity) to make some room for more settings, because domoticz officially supports ONLY 6 extra fields....

Sneek peeks:
domoticz modbus portsettings.png
domoticz modbus portsettings.png (76.66 KiB) Viewed 8362 times
domoticz modbus methode.png
domoticz modbus methode.png (68.78 KiB) Viewed 8362 times
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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Monday 08 January 2018 22:26

Alright....the Modbus WRITE v1.0.0 has been released! Enjoy! :D
https://github.com/DomoticX/domoticz-modbus

Now i will write the Universal READ plugin... ;)

Stay tuned!
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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Tuesday 09 January 2018 18:31

Modbus WRITE examples

Settings RTU example
domoticz modbus rtu voorbeeld.png
domoticz modbus rtu voorbeeld.png (97.21 KiB) Viewed 8304 times
Settings TCP example:
domoticz modbus tcp voorbeeld.png
domoticz modbus tcp voorbeeld.png (97.87 KiB) Viewed 8304 times
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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Thursday 11 January 2018 1:11

Hi All,

Today i've finished the Modbus READ plugin, it works very nice! you can download it here: https://github.com/DomoticX/domoticz-modbus

Enjoy!
domoticz modbus universal read.png
domoticz modbus universal read.png (85.58 KiB) Viewed 8257 times
Supported Functions:
domoticz modbus universal read functions.png
domoticz modbus universal read functions.png (19.15 KiB) Viewed 8257 times
Supported Datatypes:
domoticz modbus universal read data types.png
domoticz modbus universal read data types.png (10.12 KiB) Viewed 8257 times
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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

Re: Python plugin: Modbus Universal

Post by Domoticx » Thursday 11 January 2018 1:15

Tested the modbus READ plugin with the EASTRON SDM120 KWH Modbus meter:
http://domoticx.com/modbus-kwh-meter-eastron-sdm120/

Result (voltage):
domoticz modbus universal read test.png
domoticz modbus universal read test.png (17.38 KiB) Viewed 8255 times
Ps. if you wanna buy 8-) :
http://domoticx.nl/webwinkel/index.php? ... ct_id=1865
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!)

devros
Posts: 192
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

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

Post by devros » Thursday 11 January 2018 21:29

Great and what about 3 phase metter? any cheap supported device?

Ricard1
Posts: 78
Joined: Saturday 07 November 2015 13:30
Target OS: Windows
Domoticz version: Beta
Location: Sweden
Contact:

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

Post by Ricard1 » Friday 12 January 2018 12:26

Hi @Domoticx

Big thanks for initiating Modbus support to Domotiz!

I am soon going to replace my home Ventilation unit and new one will have Modbus... :)

Best Regards,
Ricard

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

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

Post by Domoticx » Friday 12 January 2018 19:18

devros wrote:
Thursday 11 January 2018 21:29
Great and what about 3 phase metter? any cheap supported device?
Hi devros,

It's a universal modbus plugin, so it wil work with all modbus appliances!
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!)

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

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

Post by Domoticx » Friday 12 January 2018 19:20

Ricard1 wrote:
Friday 12 January 2018 12:26
Hi @Domoticx

Big thanks for initiating Modbus support to Domotiz!

I am soon going to replace my home Ventilation unit and new one will have Modbus... :)

Best Regards,
Ricard
No problem ;) let me know if it works as it is intended or if you need any help.
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
EdddieN
Posts: 567
Joined: Wednesday 16 November 2016 12:31
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Scotland
Contact:

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

Post by EdddieN » Friday 12 January 2018 19:24

Is there a Like? This is fantastic! Great work
11101101 - www.machinon.com

winnie
Posts: 5
Joined: Saturday 13 January 2018 8:45
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Belgium
Contact:

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

Post by winnie » Saturday 13 January 2018 9:03

Hi @Domoticx,

Thanks for sharing the plugin. It looks great !
But i have a problem. I can't fill in any parameter.

Any idea?
Thanks Erwin.
Attachments
Knipsel.PNG
Knipsel.PNG (373.46 KiB) Viewed 8125 times

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

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

Post by Domoticx » Sunday 14 January 2018 9:27

Hello Erwin,

That is really strange, i use the same domoticz version, and i got all the options :roll: , i assume you restarted domoticz like:

Code: Select all

sudo service domoticz.sh restart
Or rebooted it?

It seems the XLM layout (plugin) isn't loaded somehow.... i cannot recreate your situation on my pi...

Can you test:
Open a browser to the domoticz log window, and a putty session and use

Code: Select all

sudo service domoticz.sh restart
What does the log say?
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: 5
Joined: Saturday 13 January 2018 8:45
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Belgium
Contact:

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

Post by winnie » Sunday 14 January 2018 15:42

Hello Domoticx,

Thanks for your suggestions.
I have restart domoticz several times wihout results.

Here a copy of the log file, baybe you see something wrong...
Greetz and thanks in advance,
Erwin;


2018-01-14 09:10:17.473 Domoticz V3.8153 (c)2012-2017 GizMoCuz
2018-01-14 09:10:17.473 Build Hash: 494fff7, Date: 2017-07-30 12:19:41
2018-01-14 09:10:17.473 Startup Path: /home/pi/domoticz/
2018-01-14 09:10:17.526 EventSystem: reset all events...
2018-01-14 09:10:17.613 PluginSystem: Started, Python version '3.4.2'.
2018-01-14 09:10:17.624 WebServer(HTTP) started on address: :: with port 8080
2018-01-14 09:10:17.630 WebServer(SSL) started on address: :: with port 443
2018-01-14 09:10:17.631 Proxymanager started.
2018-01-14 09:10:17.632 Camera: settings (re)loaded
2018-01-14 09:10:17.678 RxQueue: queue worker started...
2018-01-14 09:10:17.833 Incoming connection from: 127.0.0.1
2018-01-14 09:10:17.875 Incoming connection from: 192.168.0.121
2018-01-14 09:10:19.679 Wunderground: Worker started...
2018-01-14 09:10:19.681 Hardware Monitor: Started
2018-01-14 09:10:19.694 EventSystem: reset all events...
2018-01-14 09:10:19.695 EventSystem: reset all device statuses...
2018-01-14 09:10:19.894 RFLink: Using serial port: /dev/ttyACM0
2018-01-14 09:10:19.918 Python EventSystem: Module not found - Trying to initialize.
2018-01-14 09:10:19.920 Python EventSystem: Initalizing event module.
2018-01-14 09:10:19.920 EventSystem: Started
2018-01-14 09:10:20.028 PluginSystem: Entering work loop.
2018-01-14 09:10:20.814 RFLink: Controller Initialized!...
2018-01-14 09:10:20.890 RFLink Detected, Version: 1.1 Revision: 45 Build: 9
2018-01-14 09:10:22.179 Incoming connection from: 172.16.0.109
2018-01-14 09:11:00.451 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_zwembad.lua
2018-01-14 09:11:00.561 LUA: =====================================================
2018-01-14 09:11:00.561 LUA: >>> Handler: oled
2018-01-14 09:11:00.561 LUA: .....................................................
2018-01-14 09:11:00.561 LUA: Zwembadtemperatuur: 18.62
2018-01-14 09:11:00.612 LUA: .....................................................
2018-01-14 09:11:00.612 LUA: <<< Done
2018-01-14 09:11:00.612 LUA: -----------------------------------------------------

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

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

Post by Domoticx » Sunday 14 January 2018 15:43

What could this be?

Code: Select all

Python EventSystem: Module not found - Trying to initialize.
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: 5
Joined: Saturday 13 January 2018 8:45
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Belgium
Contact:

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

Post by winnie » Sunday 14 January 2018 16:36

I also noticed this error, find out if there is something to find about this.
Last edited by winnie on Wednesday 24 January 2018 22:41, edited 1 time in total.

Domoticx
Posts: 73
Joined: Sunday 07 January 2018 22:19
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Deventer / The Netherlands
Contact:

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

Post by Domoticx » Sunday 14 January 2018 20:28

Indeed wierd..... i have a higher python version (stretch image) :roll:

This is my log:
2018-01-14 18:22:48.140 Domoticz V3.8153 (c)2012-2017 GizMoCuz
2018-01-14 18:22:48.140 Build Hash: 494fff7, Date: 2017-07-30 10:19:41
2018-01-14 18:22:48.140 Startup Path: /home/pi/domoticz/
2018-01-14 18:22:48.182 Sunrise: 07:42:00 SunSet:15:53:00
2018-01-14 18:22:48.182 EventSystem: reset all events...
2018-01-14 18:22:48.319 PluginSystem: Started, Python version '3.5.3'.
2018-01-14 18:22:48.327 Active notification Subsystems: (0/12)
2018-01-14 18:22:48.329 WebServer(HTTP) started on address: :: with port 8080
2018-01-14 18:22:48.334 WebServer(SSL) started on address: :: with port 443
2018-01-14 18:22:48.336 Proxymanager started.
2018-01-14 18:22:48.337 Starting shared server on: :::6144
2018-01-14 18:22:48.337 TCPServer: shared server started...
2018-01-14 18:22:48.337 RxQueue: queue worker started...
2018-01-14 18:22:49.240 Incoming connection from: 192.168.0.1
2018-01-14 18:22:50.338 EventSystem: reset all events...
2018-01-14 18:22:50.339 EventSystem: reset all device statuses...
2018-01-14 18:22:50.494 Python EventSystem: Module not found - Trying to initialize.
2018-01-14 18:22:50.494 Python EventSystem: Initalizing event module.
2018-01-14 18:22:50.494 EventSystem: Started
2018-01-14 18:22:50.683 PluginSystem: Entering work loop.

Also the same error (can be common though)

Code: Select all

2018-01-14 18:22:50.494 Python EventSystem: Module not found - Trying to initialize.
2018-01-14 18:22:50.494 Python EventSystem: Initalizing event module.
But it loads the plugins nicely!

Have you installed pymodbus:

Code: Select all

sudo pip3 install -U pymodbus
Aslo a thing noticed is that the log should say Modbus - Universal READ loaded. because it's stated in the python file:

Code: Select all

    def onStart(self):
        # Domoticz.Log("onStart called")
        if (len(Devices) == 0): Domoticz.Device(Name="ModbusDEV-READ", Unit=1, TypeName="Custom", Image=0, Used=1).Create() # Used=1 to add a switch immediatly!
        DumpConfigToLog()
        Domoticz.Log("Modbus - Universal READ loaded.")
        return
on plugin load and the message is also gone on my side (plugin loaded correctly though), really wierd, hopefully someone can shed a light on this
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 4 guests