Page 1 of 21

Python plugin: Modbus RTU / ASCII / TCP/IP

Posted: Sunday 07 January 2018 23:07
by Domoticx
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

OP updated 2020-05-26

Screenshot V2020.2E
modbus domoticz 2020.2 screen.jpg
modbus domoticz 2020.2 screen.jpg (247.68 KiB) Viewed 19838 times
MASTER Hardware
RTU RS485
- Raspberry Pi / Windows - USB RS485 to Serial stick: https://webshop.domoticx.nl/index.php?r ... 0RTU%20USB
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 !!

DomoticX - ConX domotica platform (in developement Q1/Q2 2020)
So...because we are releasing our new hardware domotica line-up for Q3-Q4 2020 called ConX....we also want to support Domoticz!
ConX uses USB to RS485 conversion and 12VDC or 24VDC PoE support for all your devices, it uses RJ45 jack and is RTU based! it's a all-in-one wired and robust domotica system suitable to be placed on a DIN rail.

It will be for sale in Q3-Q4 2020, so..stay tuned! :D
2020-05-07 - Domoticx ConX teaser poster.jpg
2020-05-07 - Domoticx ConX teaser poster.jpg (263.76 KiB) Viewed 19904 times
preview poster here (dutch @ linkedin): https://www.linkedin.com/pulse/domoticx ... -ebeltjes/

oh well the hub has updated/changed since the poster :mrgreen: , hey.... time flies!

About modbus thingies...

Last week we have made a practical board to test all modbus stuff out for or new platform ConX, in wich you can create and add you own modbus devices easily!, stay tuned!
DomoticX ConX test board.jpg
DomoticX ConX test board.jpg (304.55 KiB) Viewed 19595 times

Re: Python plugin: Modbus Universal

Posted: Sunday 07 January 2018 23:10
by Domoticx
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 37716 times
modbus domoticz universal write 02.png
modbus domoticz universal write 02.png (64.21 KiB) Viewed 37716 times

Re: Python plugin: Modbus Universal

Posted: Monday 08 January 2018 9:35
by miljume
Really great work!

Any chance you will include Modbus TCP support as well?

Re: Python plugin: Modbus Universal

Posted: Monday 08 January 2018 18:49
by Domoticx
miljume wrote: Monday 08 January 2018 9: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!

Re: Python plugin: Modbus Universal

Posted: Monday 08 January 2018 20:14
by Domoticx
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 37657 times
domoticz modbus methode.png
domoticz modbus methode.png (68.78 KiB) Viewed 37657 times

Re: Python plugin: Modbus Universal

Posted: Monday 08 January 2018 21:26
by Domoticx
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!

Re: Python plugin: Modbus Universal

Posted: Tuesday 09 January 2018 17:31
by Domoticx
Modbus WRITE examples

Settings RTU example
domoticz modbus rtu voorbeeld.png
domoticz modbus rtu voorbeeld.png (97.21 KiB) Viewed 37599 times
Settings TCP example:
domoticz modbus tcp voorbeeld.png
domoticz modbus tcp voorbeeld.png (97.87 KiB) Viewed 37599 times

Re: Python plugin: Modbus Universal

Posted: Thursday 11 January 2018 0:11
by Domoticx
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 37552 times
Supported Functions:
domoticz modbus universal read functions.png
domoticz modbus universal read functions.png (19.15 KiB) Viewed 37552 times
Supported Datatypes:
domoticz modbus universal read data types.png
domoticz modbus universal read data types.png (10.12 KiB) Viewed 37552 times

Re: Python plugin: Modbus Universal

Posted: Thursday 11 January 2018 0:15
by Domoticx
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 37550 times
Ps. if you wanna buy 8-) :
http://domoticx.nl/webwinkel/index.php? ... ct_id=1865

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

Posted: Thursday 11 January 2018 20:29
by devros
Great and what about 3 phase metter? any cheap supported device?

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

Posted: Friday 12 January 2018 11:26
by Ricard1
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

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

Posted: Friday 12 January 2018 18:18
by Domoticx
devros wrote: Thursday 11 January 2018 20: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!

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

Posted: Friday 12 January 2018 18:20
by Domoticx
Ricard1 wrote: Friday 12 January 2018 11: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.

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

Posted: Friday 12 January 2018 18:24
by EdddieN
Is there a Like? This is fantastic! Great work

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

Posted: Saturday 13 January 2018 8:03
by winnie
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.

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

Posted: Sunday 14 January 2018 8:27
by Domoticx
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?

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

Posted: Sunday 14 January 2018 14:42
by winnie
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: -----------------------------------------------------

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

Posted: Sunday 14 January 2018 14:43
by Domoticx
What could this be?

Code: Select all

Python EventSystem: Module not found - Trying to initialize.

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

Posted: Sunday 14 January 2018 15:36
by winnie
I also noticed this error, find out if there is something to find about this.

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

Posted: Sunday 14 January 2018 19:28
by Domoticx
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