Modbus openHAB2 binding available for alpha testing

my port is working. I use UART - RS485. tell me where to put it “writeMultipleEvenWithSingleRegisterOrCoil” ?
I use devices with the function 06 of 16 in one network.

Hi!

Check out the documentation, and let me know if it unclear.

All the parameters are documented there and this one is not any different. Let me know if there is something to improve in the docs.

Please also note that yuu can use Paper UI for configuration, avoiding the textual configuration. I personally find the textual configuration is convenient and a way of documenting the setup.

Sami

1 Like

everything worked out. Thank you. I use text settings.

1 Like

Can you please provide me the error message?

You can also paste the configuration here, I can check it.

Regarding the encoding, yes, I have read that UTF-8 BOM is the problem… unrelated to this binding as you mentioned also.

Best,
Sami

Hi ssalonen,
I have done some more testing and the binding seems to be stable (at least in my simple test setup). When I find the time, I will do some more performance testing within my productive setup.

However, there is still a practical problem with some devices that I may have mentioned earlier (can’t find the corresponding post anymore…):

I have some devices that take measurements on request but also provide some more I/Os. The measurement process takes time (~2 seconds) during which the device is not reachable. If the measurement function was the only thing the device is doing, I could simply omit automatic polling and use a rule to start the measurement (write to a certain holding register), wait 2 seconds and then request a refresh of the item corresponding to the input register containing the measured value (and therefore never use automatic polling).

However there are also the I/Os… of course I want these (coils/inputs) to be polled as often as possible. If I use a poller-thing for that, I get time out errors whenever the measurement-rule is triggering (every 5 minutes). I could write another rule that would have to be executed more than once per second (ideally every couple hundred milliseconds), request updates for the I/O-items manually and pause when the measurement is taking place - but that is not a nice solution and produces a lot of overhead and CPU load considering we’re talking 10+ devices here…

It would be a lot nicer to use the poller thing instead and be able to disable polling from a rule. For example we could make the refresh parameter of the poller thing available as a channel and bind a number item to it.

What do you think about that? It would not be that big a deal and make the binding a lot more flexible.

Best,
Max

1 Like

Hi, great to hear from you!

I wonder if you can follow the advice from here to reconfigure pollers : Thing configuration from rules

I have not tested that personally and not sure if there are some issues in case the things are defined using the text file…

This would be ideal, I think. I am a bit hesitant to introduce configuration options as channels, haven’t seen that with other bindings.

Best
Sami

1 Like

Hi Sami,
even if that works with textually configured things it’s still just a hack (or work around). I could also change the configuration files using a shell script and maybe create a ramdisk and mount it to the things folder to avoid harddisk writing.

Both solutions don’t sound very appealing to me.

How is this handled in other bindings? What about the thing-status (thing.getStatus())? Can one set the status of a thing to “offline” in, for example, the TCP or HTTP binding and therefore stop polling?

And while were at it: How does the HTTP-Binding or the TCP-Binding handle a loss of connection to its endpoint? Is the corresponding thing’s status set to offline? The latter is sth. I would expect to be the behaviour of the Modbus-Binding too.

Kind regards,
Max

Please help
I am allways get error:

Could not get port identifier, maybe insufficient permissions. gnu.io.NoSuchPortException: null

What I did:

  1. Install OH2(2.3.0) on my Synology DS418
  2. Make all installation steps for serial connection(GitHub - openhab/openhab-syno-spk: openHAB Synology SPK Install Package). Create group, set permission on device, modify udev rules, change owner of lock dir. Also add -Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB1 to karaf script
  3. Install serial transport
  4. Install Modbus Binding
  5. Install openHAB MODBUS Transport Bundle
  6. set log TRACE …
  7. Create Thing : slave serial, /dev/ttyUSB1
  8. Create Poller for slave: holding register

But connection always could not created:

2018-06-20 22:04:46.106 [TRACE] [ing.ModbusSlaveConnectionFactoryImpl] - Created connection SerialConnection@7a70950e[portName=/dev/ttyUSB1,port=<null>] for endpoint ModbusSerialSlaveEndpoint@73a395c7[portName=/dev/ttyUSB1]
2018-06-20 22:04:46.108 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. gnu.io.NoSuchPortException: null
2018-06-20 22:04:46.110 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/1 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@7a70950e[portName=/dev/ttyUSB1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@73a395c7[portName=/dev/ttyUSB1]
2018-06-20 22:04:46.111 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 1, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@7a70950e[portName=/dev/ttyUSB1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@73a395c7[portName=/dev/ttyUSB1]
2018-06-20 22:04:46.112 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@7a70950e[portName=/dev/ttyUSB1,port=<null>] for endpoint ModbusSerialSlaveEndpoint@73a395c7[portName=/dev/ttyUSB1]: Could not get port identifier, maybe insufficient permissions. null

java version:

java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

DS418
Realtek RTD1296 SoC
DSM 6.1.7-15284

Hi Max!

I can see that my suggestion feels like a hack/workaround…

Regarding the thing status: as far as I know, binding controls the thing status, and thus not possible to “set” it from outside. Even if it would be possible, the binding is updating the status all the time, thus overwriting any possible changes.

TCP and HTTP are version 1 bindings, and have no concept of OFFLINE or OFFLINE so I think we should not compare to those.

knx binding was rewritten for openHAB2 and does have regular polling (readInterval) as well. The implementation is similar to modbus binding – I can’t see any way to disable polling “during runtime”.

Another example is the Atlona binding (polling).

In case of read/write errors, the modbus binding is setting the data and poller things OFFLINE. The status is reseted to ONLINE whenever operation is successful.

Does this help at all?

Best,
Sami

Hi Sami,

Sure. I assumed those bindings had already made it to version 2. Sry for the bad research.

The KNX spec specifies how KNX devices communicate on a low level (bus communication, addressing) and on a higher level in order to allow for interoperability. That is not the case with Modbus. Modbus only specifies the low level communication and that’s it. The rest is vendor specific. Since things are a lot clearer in KNX, the need to disable polling for a specific device during runtime may never have arisen…

Nice! I like that :slight_smile:

I will try the hacky workarounds although I’d love to see a cleaner solution.

Thx for the good work! I hope this binding will soon be merged.

Best,
Max

I found some details on the SMA inverter I was trying to communicate with.

I’m trying to read the Input registers (Uint32 and Int32), normally read length of 2.

This is not working with SMA, if I set the length to 4 it works perfectly - but why?

It seems to be problem/bug with the device, see discussion here https://github.com/openhab/openhab1-addons/issues/4931

Best
Sami

Thanks Sami, good to know that I haven’t “lost” it.

Hi Sami,
seems like that doesn’t work with textually configured things:

2018-06-22 23:38:57.718 [INFO ] [st.core.internal.thing.ThingResource] - Received HTTP PUT request for update configuration at 'things/modbus:poller:wc101:coils/config' for an unmanaged thing 'modbus:poller:wc101:coils'.

Best,
Max

@andrey I believe you messaged me privately as well?

Unfortunately I can’t help you with the Synology, sounds like something special needs to be done with this device.

The README of GitHub - openhab/openhab-syno-spk: openHAB Synology SPK Install Package says that

For Z-Wave and Devices that use dev/ttyACM0 or dev/ttyACM1 will at install a script copy to /usr/local/etc/rc.d that will execute install or on Boot. This exec on the Port´s chmod 777. And load some USB Kernelmodules. To make these it´s necessary to enter on Installation the Admin Password from DSM.

By looking into pacakge.tgz, you can find openHAB-zwave.sh:

sudo insmod /lib/modules/usbserial.ko
sudo insmod /lib/modules/ftdi_sio.ko
sudo insmod /lib/modules/cdc-acm.ko

sudo chmod 777 /lib/modules/usbserial.ko
sudo chmod 777 /lib/modules/ftdi_sio.ko
sudo chmod 777 /lib/modules/cdc-acm.ko

sudo chmod 777 /dev/ttyACM0
sudo chmod 777 /dev/ttyACM0

Perhaps something similar is needed for your serial port? You might consider opening a new thread regarding serial port configuration with Synology.

Best,
Sami

@zacofunny, can you please try out with the latest version?

We now have caching in place (used only with REFRESH commands) to avoid spamming the modbus, see cacheMillis parameter of poller in docs.

Default cache is now 50 ms which probably cuts out the majority of REFRESH calls.

@mbs38 Thanks for trying it out! I will try to figure something out for you .

Will first get the PR merged, and then introduce additional improvement to tackle this…

All, I noticed that the Marketplace was pointing to 2.3.0-SNAPSHOT allthough 2.4.0-SNAPSHOT is the latest.

Please try out with this new version! All feedback is now highly appreciated since the code is about to be merged to main openHAB code base.

Hi! I will try it asap! Thanks for your hard work!

You are welcome Sami. Thx for tackling this issue.

Btw: I’m really looking forward to the merge. I’ve got a friend who has another huge Modbus-Installation (~50 devices spread over multiple serial ports, >1500 I/Os). I am excited to see how the new binding is going to perform there :smiley: