OH3 Waveshare Relay v1 modbus

Hello,
has anyone tried to configure it to read the states and change the states of the relays?
Hardware:
Waveshare relay 8ch modbus rtu
image
https://www.waveshare.com/wiki/Modbus_RTU_Relay#demo_codes
I have tried various configurations but none of them works properly. From what I understood, the states of the relays are written in addresses from 0-8 as a bit type, so we read FC1 “read coil” but I get the error “Bridge is not online”

1 Like

When you’re ready, share your best guess.

I think you’ll find this easiest to use in ‘coil’ read/write mode, Modbus FC01 and FC05

Use a third party tool like MBpoll for the one-time task of setting address and baud.

I use qModbus for one-time attempts. I know the ID, the baud is also correct and it is even possible to change the state of the relay, but it cannot be read.
To change state:
FC5 address 0 (for the first relay).
It looks like I have a problem with every device I plug into the bus :))

type=“input”
modbus.thing

Bridge modbus:tcp:WSRELAYID23 [ host="192.168.2.9", port=502, id=23, receiveTimeoutMillis="150", timeBetweenTransactionsMillis="50" ]
    {
     Bridge poller int8ID23 [start=255, length=1, refresh=500, type="input" ]{
            Thing data Relay1 [ readStart="255.0", readValueType="bit" ]
  }
}

log

2021-12-14 19:20:13.241 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE
2021-12-14 19:20:13.263 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE
2021-12-14 19:20:13.270 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from OFFLINE to ONLINE
2021-12-14 19:20:13.271 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from OFFLINE (CONFIGURATION_ERROR): readStart=X.Y is not allowed to be used with coils or discrete inputs! to OFFLINE (BRIDGE_OFFLINE): No online bridge
2021-12-14 19:20:13.273 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from OFFLINE (BRIDGE_OFFLINE): No online bridge to ONLINE
2021-12-14 19:20:23.892 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveIOExceptionImpl) with read. Request: ModbusReadRequestBlueprint [slaveId=23, functionCode=READ_INPUT_REGISTERS, start=255, length=1, maxTries=3]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null
2021-12-14 19:20:23.895 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.core.io.transport.modbus.internal.ModbusSlaveIOExceptionImpl: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null
2021-12-14 19:20:23.896 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveIOExceptionImpl) with read. Request: ModbusReadRequestBlueprint [slaveId=23, functionCode=READ_INPUT_REGISTERS, start=255, length=1, maxTries=3]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null to OFFLINE (BRIDGE_OFFLINE): No online bridge

type=“coil”

Bridge modbus:tcp:WSRELAYID23 [ host="192.168.2.9", port=502, id=23, receiveTimeoutMillis="150", timeBetweenTransactionsMillis="50" ]
    {
     Bridge poller int8ID23 [start=255, length=1, refresh=500, type="coil" ]{
            Thing data Relay1 [ readStart="255.0", readValueType="bit" ]
  }
}

event.log

2021-12-14 19:17:23.423 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:tcp:WSRELAYID23' changed from UNINITIALIZED to INITIALIZING
2021-12-14 19:17:23.435 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:tcp:WSRELAYID23' changed from INITIALIZING to ONLINE
2021-12-14 19:17:23.439 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from UNINITIALIZED to INITIALIZING
2021-12-14 19:17:23.450 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from INITIALIZING to ONLINE
2021-12-14 19:17:23.473 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from UNINITIALIZED to INITIALIZING
2021-12-14 19:17:23.484 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from INITIALIZING to OFFLINE (CONFIGURATION_ERROR): readStart=X.Y is not allowed to be used with coils or discrete inputs!

image

I do not know how i can read value of relay…:frowning:

If you’ve already used qModbus for setting this box up, you should be able to use qModbus to read and write to your relays, and all you have to do is mirror that setup.

Okay, your document gives a sample command 01, we’d usually call that FC01 in Modbus land.
FC01 is associated with reading coils in Modbus land - seems reasonable for relays.

Then it gets a bit muddled. The docs suggest reading one coil from address 255 and you then get 8 coil states back. That’s technically invalid in Modbus protocol - maybe that is why there is a v2 module version doing it differently.
Anyway, you’ve got v1.
The device will return a byte representing 8 relays, but the binding may not let you interpret that because you only asked for one bit, if you follow the example.

Try it and see what happens if you ask for 8 -

     Bridge poller int8ID23 [start=255, length=8, refresh=1000, type="coil" ]{
            Thing data Relay1 [ readStart="255", readValueType="bit" ]
            Thing data Relay2 [ readStart="256", readValueType="bit" ]

I trayed :frowning:

2021-12-14 21:39:05.843 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE
2021-12-14 21:39:05.859 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE
2021-12-14 21:39:05.861 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from OFFLINE to ONLINE
2021-12-14 21:39:05.863 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error (ModbusConnectionException) with read. Request: ModbusReadRequestBlueprint [slaveId=23, functionCode=READ_COILS, start=255, length=1, maxTries=3]. Description: ModbusConnectionException(Error connecting to endpoint=ModbusIPSlaveEndpoint [address=192.168.2.9, port=502]). Message: Error connecting to endpoint ModbusIPSlaveEndpoint [address=192.168.2.9, port=502]
2021-12-14 21:39:05.865 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.core.io.transport.modbus.exception.ModbusConnectionException: Error connecting to endpoint ModbusIPSlaveEndpoint [address=192.168.2.9, port=502]
2021-12-14 21:39:05.868 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from OFFLINE (COMMUNICATION_ERROR): Error (ModbusConnectionException) with read. Request: ModbusReadRequestBlueprint [slaveId=23, functionCode=READ_COILS, start=255, length=1, maxTries=3]. Description: ModbusConnectionException(Error connecting to endpoint=ModbusIPSlaveEndpoint [address=192.168.2.9, port=502]). Message: Error connecting to endpoint ModbusIPSlaveEndpoint [address=192.168.2.9, port=502] to OFFLINE (BRIDGE_OFFLINE): No online bridge
2021-12-14 21:39:16.467 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.core.io.transport.modbus.exception.ModbusConnectionException: Error connecting to endpoint ModbusIPSlaveEndpoint [address=192.168.2.9, port=502] to OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.core.io.transport.modbus.internal.ModbusSlaveIOExceptionImpl: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null

As you can see, that is not the setup that I suggested.

Anyways,

suggests you have something else wrong - IP address, device ID?

Sorry, read FC01 255 1 working and give state one relay but FC01 255 8 or reading FC01 256 1 is not working. I try give type=“input” and read bit0 bit1 but i dont thing so thet will by good idea.

2021-12-14 22:59:08.172 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:tcp:WSRELAYID23' changed from UNINITIALIZED to INITIALIZING
2021-12-14 22:59:08.182 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:tcp:WSRELAYID23' changed from INITIALIZING to ONLINE
2021-12-14 22:59:08.186 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from UNINITIALIZED to INITIALIZING
2021-12-14 22:59:08.196 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from INITIALIZING to ONLINE
2021-12-14 22:59:08.217 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from UNINITIALIZED to INITIALIZING
2021-12-14 22:59:08.228 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from INITIALIZING to ONLINE
2021-12-14 22:59:18.720 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveIOExceptionImpl) with read. Request: ModbusReadRequestBlueprint [slaveId=23, functionCode=READ_COILS, start=255, length=8, maxTries=3]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null
2021-12-14 22:59:18.722 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:poller:WSRELAYID23:int8ID23' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.core.io.transport.modbus.internal.ModbusSlaveIOExceptionImpl: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null
2021-12-14 22:59:18.724 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'modbus:data:WSRELAYID23:int8ID23:Relay1' changed from OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveIOExceptionImpl) with read. Request: ModbusReadRequestBlueprint [slaveId=23, functionCode=READ_COILS, start=255, length=8, maxTries=3]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: SocketTimeoutException Read timed out', cause2=null to OFFLINE (BRIDGE_OFFLINE): No online bridge

Device ID, IPD address is ok becauce on this adapter working 22 slaves and relay can read state but only one relay

Ok i upgrade relays to v2

Okay, I think you are out of options. This device does not conform to Modbus protocol. Can it be updated to v2?

Yes, i will try update and should by working.
One more question:
If coil with state is on address 255 and to write 0 can i give in Bridge poller start=0 length=256 ?
it will not be too large a frame where only two values ​​interest me ?

The address the poller Thing uses is purely about reading. You can set any random address in each data Thing for writes.
So it would look something like -

            Thing data Relay1 [ readStart="255", readValueType="bit". writeStart="0", writeType="coil" ]

@ssalonen It might perhaps be possible to cater to this oddball device (so many Modbus oddballs!)

To summarise the issue -
Device accepts FC01 READ COILS to address with coils length = 1
Device responds with a complete byte (as it should) BUT fully populates byte with 8 value bits, not just the 1 requested.
Device will NOT respond to standard FC01 requesting 8 bits.
So, to read all 8 coil bits you must request only 1 but analyse 8 in the response.

This gives a configuration issue, because we should not be looking at bit 1,2,3 etc.if we only asked for one bit 0 to start with.
I would think the actual data handling would work out, since we would normally get a byte in response to a 1-bit request (but ignore bits 1-7).
It’s just validating the data readStart configurations for address+1, +2, etc. when that is out of range of the poller’s length parameter.?

On the other hand, we do not want to remove the “sanity checks” against accidental misconfiguration. Maybe if config error was WARN report only in this circumstance.

Yeah… :sweat_smile:

Is the v1 updatable to v2 or is it a separate device? According to docs, v2 seems to be compliant with the modbus standard.

I thing its updatable, today i will try update. I have soft from Waveshare

1 Like

OK, to upgrade You need ST-Link V2.
After upgrade its works very good.
FC01 0-8 - state all of relay
FC05 0-8 - change state of relay

Bridge modbus:tcp:WSRELAYID23 [ host="192.168.2.9", port=502, id=23, receiveTimeoutMillis="150", timeBetweenTransactionsMillis="50" ]
    {
     Bridge poller int8ID23 [start=0, length=8, refresh=500, type="coil" ]{
           Thing data Relay1 [ readStart="0", readValueType="bit", writeType="coil", writeStart="0", writeValueType="bit" ]
           Thing data Relay2 [ readStart="1", readValueType="bit", writeType="coil", writeStart="1", writeValueType="bit" ]
           Thing data Relay3 [ readStart="2", readValueType="bit", writeType="coil", writeStart="2", writeValueType="bit" ]
           Thing data Relay4 [ readStart="3", readValueType="bit", writeType="coil", writeStart="3", writeValueType="bit" ]
           Thing data Relay5 [ readStart="4", readValueType="bit", writeType="coil", writeStart="4", writeValueType="bit" ]
           Thing data Relay6 [ readStart="5", readValueType="bit", writeType="coil", writeStart="5", writeValueType="bit" ]
           Thing data Relay7 [ readStart="6", readValueType="bit", writeType="coil", writeStart="6", writeValueType="bit" ]
           Thing data Relay8 [ readStart="7", readValueType="bit", writeType="coil", writeStart="7", writeValueType="bit" ]
  }
}
2 Likes

Hi, i am also using wavshare relay, do you have any documentation on how to update to v2, i already have ST-link v2 . Thanks

Hello @kusanghi,
to update to V2 you need to take apart the case, there are SWD pins, you should connect it to an ST-Link V2 and program it with the ST-Link Utility software.
You will also need to request the V2.2.hex update file from your Waveshare Modbus Relay supplier.