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

Python and python framework

Moderator: leecollings

Post Reply
User avatar
McMelloW
Posts: 434
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 »

Domoticx wrote: Saturday 27 January 2018 19:13 @McMelloW
No, this is a universal plugin for modbus, it can read 1-4 registers (depending on selected datatype)
It seems like you need a Modbus plugin (written) for your device!
@Domoticx,

Thanks for your update. It was a nice bit of trial and error. Tested the connection with a Win10 modbus scanner to find out what I can expect for data. I will look for other ways to read my SolarEdge
Greetings McMelloW
palmipete
Posts: 10
Joined: Thursday 25 January 2018 15:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by palmipete »

Hi all,
I have now running since 3 days 3 different Modbus equipments in my house for thermal and energy metering as well as for my heating system.
In general it works quite well (reading).

However, sometimes domoticz, even if it is displaying OK when I check the status, the web interface is blocked.
as soon as I restart domoticz all works again.
This happened 2 times in 3 days.
I tried to put an automatic restart in crontab (hourly) but this did not work yet (I perhaps not so bad in Python, but beginner in Linux).

my main comments to the plugin:
- I would preefer to put an additional parameter in the hardware menu for defining a time step (it is nice to have data every 10seconds, but if I need an energy value every hour this consumed memory for nothing).
- one step further, I am planning to put some kid of check and compare to the last value, and only save data if the change is higher than a limit which is specified in the hardware interface as well
- I do not like these 5 minutes averages in domoticz. For my needs the best would be to save only event based (if change is > threshold) but then keep ALL dataa, also when exporting. I guess this is not the right place to ask this question, but perhaps you have already thought about this since it is typically a problem for periodic measurements (such as modbus) that are in most cases too many values for nothing ...

at the end a question: in the modbus write function, I can switch off my heating system, but it fails later. I think this is due to the hex format of data.
my code is 0 or 1 and I tried: 0x00 for 0 and 0x01 for 1.
but it only cuts the systems, switching on does not work? is this format correct?

Peter
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 palmipete,

Are you using RTU or TCP?
palmipete wrote: Tuesday 30 January 2018 15:57 Hi all,
I have now running since 3 days 3 different Modbus equipments in my house for thermal and energy metering as well as for my heating system.
In general it works quite well (reading).
Great! :D
palmipete wrote: Tuesday 30 January 2018 15:57 my main comments to the plugin:
- I would preefer to put an additional parameter in the hardware menu for defining a time step (it is nice to have data every 10seconds, but if I need an energy value every hour this consumed memory for nothing).
There are no more configurable fields available in domoticz....i also wanted timeout and retry setting...but there is no more room...
palmipete wrote: Tuesday 30 January 2018 15:57 - one step further, I am planning to put some kid of check and compare to the last value, and only save data if the change is higher than a limit which is specified in the hardware interface as well
Hopefully future versions of domoticz can implement this, based on plugin return data...
palmipete wrote: Tuesday 30 January 2018 15:57 - I do not like these 5 minutes averages in domoticz. For my needs the best would be to save only event based (if change is > threshold) but then keep ALL dataa, also when exporting. I guess this is not the right place to ask this question, but perhaps you have already thought about this since it is typically a problem for periodic measurements (such as modbus) that are in most cases too many values for nothing ...
Hopefully future versions of domoticz can implement this...
palmipete wrote: Tuesday 30 January 2018 15:57 at the end a question: in the modbus write function, I can switch off my heating system, but it fails later. I think this is due to the hex format of data.
my code is 0 or 1 and I tried: 0x00 for 0 and 0x01 for 1.
but it only cuts the systems, switching on does not work? is this format correct?
The HEX seems ok, are you sure you need to send 0x01 to switch it on?, what does the manual 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!)
palmipete
Posts: 10
Joined: Thursday 25 January 2018 15:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by palmipete »

I use Modbus RTU with a USB converter.
I understood the code so no I could make it work as I wanted (Modbus write).
I also wrote a code as python plugin to make an Event-Logger (check all 10 secs for new values and save to a daily log file).
perhaps somebody is interested in.
JackWolfskind
Posts: 5
Joined: Wednesday 14 February 2018 9:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by JackWolfskind »

Hi,

I'm currently stuck with the error "Modbus error communicating!, check your settings!" with two different Modbus TCP devices which work fine with different home automation SW.

Anybody got Modbus TCP working with any device at all?
Thanks
Jack
pablo86
Posts: 1
Joined: Wednesday 23 November 2016 22:06
Target OS: Linux
Domoticz version:
Contact:

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

Post by pablo86 »

good morning.
i have the same problem with tcp modbus

2018-02-14 22:19:21.747 (test) MODBUS DEBUG TCP CMD - Method=tcp, Address=192.168.3.5, Port=502, Register=9, Data type=16int
2018-02-14 22:19:21.747 (test) Modbus error communicating!, check your settings!
2018-02-14 22:19:21.747 (test - ModbusDEV-READ) Updating device from 0:'0' to have values 0:'0'.
2018-02-14 22:19:21.748 (test) Modbus error decoding (or recieved no data)!, check your settings!
2018-02-14 22:19:21.748 (test - ModbusDEV-READ) Updating device from 0:'0' to have values 0:'0'.

my hardware is ad4eth Papouch 4-20mA 4 analog input

with software medford work fine
Attachments
Immagine24.jpg
Immagine24.jpg (72.66 KiB) Viewed 3873 times
Immagine23.jpg
Immagine23.jpg (224.6 KiB) Viewed 3874 times
JackWolfskind
Posts: 5
Joined: Wednesday 14 February 2018 9:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by JackWolfskind »

Actually it seems this plugin only supports "Modbus RTU over TCP" (which is Modbus RTU send over TCP by a serial to LAN converter ) and not the more much common "Modbus TCP protocol", which is very similar but with different structure!
Maybe this helps to better understand:
http://control.com/thread/1305797461

Maybe in the future the plugin can Support both ways? 8-)
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 Jack,

I think you are right, so maybe i can make a test plugin with this:
https://pypi.python.org/pypi/pyModbusTCP/

:D :roll: will make a alpha/beta plugin soon to test things 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!)
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 »

Domoticx wrote: :D :roll: will make a alpha/beta plugin soon to test things out!
great :mrgreen:
User avatar
McMelloW
Posts: 434
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 »

Domoticx wrote: Thursday 22 February 2018 20:42 :D :roll: will make a alpha/beta plugin soon to test things out!
+1 looking forward to it
Greetings McMelloW
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 All,

Here is the TEST APLHA PLUGIN :roll: 8-)

So now you need 2 modbus dependancies:

- PYMODBUS v1.4.0 or higher
- Install for python 3.x with: sudo pip3 install -U pymodbus
- PYMODBUSTCP v0.1.5 or higher
- Install for python 3.x with: sudo pip3 install -U pymodbusTCP

Option "TCP" is now modbusTCP and other has been renamed to "RTU over TCP"

Please test if the code/plugin works! (i do not have TCP hardware to test it on)

*edit file removed* (now got my own test software :D)
Last edited by Domoticx on Friday 23 February 2018 22:34, edited 2 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!)
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 »

You can use a modbus esclave simulator
Here one
https://sourceforge.net/projects/modrssim/
Last edited by papoo on Friday 23 February 2018 22:07, edited 1 time in total.
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 »

Thanks for that!

Ps. i see i also got another import error, i will look how to solve (*sigh*....domoticz paths....)
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 »

Domoticx wrote: Friday 23 February 2018 22:05 Thanks for that!

Ps. i see i also got another import error, i will look how to solve (*sigh*....domoticz paths....)
Fixed the importbug.

Ps. is port 502 default?

Also with the simulator i can use the machines IP right?
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 »

Yes!! :D :lol: got a Python script working with the windows simulator!! but there is/was a catch hahaha, i have to make the plugin a bit smarter....

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!)
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 tested it with te emulation software, got a working version now!! 8-) 8-)

I proudly present READ v1.1.0 with true TCP/IP support :lol: :lol: (grab @ Github) >> https://github.com/DomoticX/domoticz-modbus

Enjoy!, let me show your findings and neat projects!! :geek:

Ps. my tests and config:
modbus tcp-ip screen 01 emulator or device.png
modbus tcp-ip screen 01 emulator or device.png (23.13 KiB) Viewed 3704 times
modbus tcp-ip screen 02 config.png
modbus tcp-ip screen 02 config.png (153.12 KiB) Viewed 3704 times
modbus tcp-ip screen 03 dash.png
modbus tcp-ip screen 03 dash.png (29.26 KiB) Viewed 3704 times
Last edited by Domoticx on Saturday 24 February 2018 0:03, edited 2 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!)
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 »

Great
User avatar
McMelloW
Posts: 434
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 »

Looks great !!
What is the length of the register you can read? For the SolarEdge over port 502, you have to read 0 - 122 positions.
Greetings McMelloW
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

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

Post by freijn »

looks good, curious on results !
User avatar
McMelloW
Posts: 434
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 »

Installing the READ plugin hangs domoticz. After restarting Domoticz, no screen visible and no connection via the browser is possible. SSH via Putty remains active. Removing the plugin from the Plugin directory and Domoticz restart solved the problem.

It is sadly, because it looked promising
Greetings McMelloW
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest