Modbus - unable to control coils

Hello there, I am trying to make my own node with arduino comunicating by modbus. After some fighting I got working reading of input register (slave1 in my cfg). But I am unable to control coils; with 3rd party modbus master I am.

Inside arduino, the 1st register contains distance from ultrasonic sensor, then in next register are 4 bits for relays / outputs.

1st issue is that I didn’t see any writing modbus function in logs yet. For coil it should be “5”.

2nd, small, issue is that modbus polling (binding) is not started automaticaly now, I am working with it like I am stopping and restarting binding from karaf console, because when I have been editing files, sometimes the tty got blocked, and I was unable to free it to use it again…

So this is my node.items:

// Number waterpit_level "Water Pit Level [%s]" <cistern> (ALL) {modbus="slave1:0"}
// Number waterpit_outs (ALL) {modbuss="slave2:0"}

Switch waterpit_pump "Water Pit Pump" (ALL) {modbus=">slave3:0"}

// Switch waterpit_elm1 "Water Pit eValve 1" (ALL) {modbus=">slave4:0"}
// Switch waterpit_elm2 "Water Pit eValve 2" (ALL) {modbus=">slave5:0"}
// Switch waterpit_elm3 "Water Pit eValve 3" (ALL) {modbus=">slave6:0"}

These are my slaves in modbus.cfg:

#serial.slave1.connection=/dev/ttyAMA0:19200:8:none:1:rtu:150
#serial.slave1.id=1
#serial.slave1.start=0
#serial.slave1.length=1
#serial.slave1.type=input
#serial.slave1.valuetype=uint16

#serial.slave2.connection=/dev/ttyAMA0:19200:8:none:1:rtu:150
#serial.slave2.id=1
#serial.slave2.start=1
#serial.slave2.lenght=1
#serial.slave2.type=holding
#serial.slave2.valuetype=uint16

serial.slave3.connection=/dev/ttyAMA0:19200:8:none:1:rtu:150
serial.slave3.id=1
serial.slave3.start=16
#serial.slave3.valuetype=bit
serial.slave3.type=coil

#serial.slave4.connection=/dev/ttyAMA0:19200:8:none:1:rtu:150
#serial.slave4.id=1
#serial.slave4.start=1
#serial.slave4.type=coil

#serial.slave5.connection=/dev/ttyAMA0:19200:8:none:1:rtu:150
#serial.slave5.id=1
#serial.slave5.start=2
#serial.slave5.type=coil

#serial.slave6.connection=/dev/ttyAMA0:19200:8:none:1:rtu:150
#serial.slave6.id=1
#serial.slave6.start=3
#serial.slave6.type=coil

this is my main.sitemap:

sitemap main label="My home automation"
{
  Frame label="Water Pit"
  {
    /* Text item=waterpit_level label="Value [%s]" */
    Switch item=waterpit_pump label="Pump"
    /* Switch item=waterpit_elm1 label="ELM 1"
    Switch item=waterpit_elm2 label="ELM 2"
    Switch item=waterpit_elm3 label="ELM 3" */
  }
}

I am trying different things, for example using transformations in bindings everything except simple definition w/o < or > is not working, getting parsing errors …

Switch waterpit_pump "Water Pit Pump" (ALL) {modbus=">[slave3:0:trigger=ON, transformation=65535]"}
// or 
Switch waterpit_pump "Water Pit Pump" (ALL) {modbus=">[slave3:0:valuetype=bit]"}

Also I do not understand, why the slave is still polled by reading when I am just writing to it…

2017-06-11 23:22:12.320 [INFO ] [b.core.service.AbstractActiveService] - Modbus Polling Service has been started
2017-06-11 23:22:12.407 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:12.439 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:13.487 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:13.507 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:14.558 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:14.573 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:15.617 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:15.632 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:16.677 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:16.693 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:17.737 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:17.751 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:18.797 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:18.811 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:19.857 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:19.871 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:20.918 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-11 23:22:20.945 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-11 23:22:21.966 [INFO ] [b.core.service.AbstractActiveService] - Modbus Polling Service has been shut down

Last thing … it is somehow possible to reset modbus binding without restartin RPI? I found out that there some configurations are left in /var/lib/openhab2/config/org/openhab/modbus.config even I will change the modbus.cfg and restart RPI. I have to delete that file before restart…

I must say I am very confused from binding wiki page :frowning:

So that Openhab can monitor the actual status of the coils instead of guessing e.g. after a restart, or if some other action independently changes them (you might have manual buttons on your arduino for example)

That format isn’t shown in the binding Wiki.

If your arduino is capable of reading back coil status in the usual way, just use the simple binding

Switch waterpit_pump "Water Pit Pump" (ALL) {modbus="slave3:0"}

If your coil is write only, the format is like this

Switch waterpit_pump "Water Pit Pump" (ALL) {modbus=">[slave3:0]"}

but you must use binding version 1.10 for that

Thank you for info! I must say that I have overviewed the information about 1.10 binding , I have seen the information about 1.9 but not this one. I am searching and learning how to upgrade bindings right now, it is different than usual linux stuf.

Anyway, all that weird stuff I have in configs is because I am not able to make it work. So for the simple config:

Switch waterpit_pump "Water Pit Pump" (ALL) {modbus="slave3:0"}

I am getting such errors:

2017-06-12 17:49:31.721 [INFO ] [b.core.service.AbstractActiveService] - Modbus Polling Service has been started
2017-06-12 17:49:31.813 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-12 17:49:31.843 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-12 17:49:31.857 [WARN ] [inding.modbus.internal.ModbusBinding] - Item 'waterpit_pump' read index '0' is out-of-bounds. Slave 'slave3' has been configured to read only '0' bits. Check your configuration!
2017-06-12 17:49:32.903 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-12 17:49:32.917 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-12 17:49:32.933 [WARN ] [inding.modbus.internal.ModbusBinding] - Item 'waterpit_pump' read index '0' is out-of-bounds. Slave 'slave3' has been configured to read only '0' bits. Check your configuration!
2017-06-12 17:49:33.973 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 01 01 00 10 00 00 3d cf
2017-06-12 17:49:33.987 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Response: 01 01 00 21 90
2017-06-12 17:49:34.001 [WARN ] [inding.modbus.internal.ModbusBinding] - Item 'waterpit_pump' read index '0' is out-of-bounds. Slave 'slave3' has been configured to read only '0' bits. Check your configuration!

Also I stil do not understand why the node is polled with FC1 … maybe just for reading the state … but is that normal?

Ok I get rid of that error by setting length to 4 for slave3… anyway still no writing to the coil…

Heureka, it works when called manualy in karaf console: smarthome:send waterpit_pump ON

Now I will keep trying to make this work…

… last mystery solved, in habmin, the sitemap changes are not working, but number items displaying is wroking :confused:, in phone app and also in basicui it works … it has been working on 1st try probably :stuck_out_tongue_winking_eye:

Perhaps the default length=1 is broken, I don’t know, I always specify length myself.

So that Openhab can monitor the actual status of the coils instead of guessing etc.
This is the default approach, it is not mandatory, if you don’t like it (maybe your arduino cannot handle it) the n the way to make it write-only already outlined above.