Modbus TCP, Pokeys57E & Analog sensors

I’m unable to read analogue values using the Modbus TCP binding from a Pokeys57E.
My Config looks like this:

modbus:tcp.slave1.connection=192.168.1.250:502
#modbus:tcp.slave1.port=502
modbus:tcp.slave1.type=coil
modbus:tcp.slave1.id=1
modbus:tcp.slave1.start=0
modbus:tcp.slave1.length=55

My .items file:

Group gModbus(gAll)

Contact LandingMotion    "Contact0 [MAP(en.map):%s]"     (gModbus)   {modbus="slave1:0"}
Number     LightLevelFront    "Light [%f]"                    (gModbus)   {modbus="slave1:40"}
Number     LightlevelRear    "Light [%f]"                    (gModbus)   {modbus="slave1:41"}

The Contact motion sensor works without a problem, values for the analogues sensors (lightLevel*), read as “undefined” -

2015-11-06 12:47:56 - LandingMotion state updated to CLOSED
2015-11-06 12:47:56 - LightLevelFront state updated to Undefined
2015-11-06 12:47:56 - LightlevelRear state updated to Undefined
2015-11-06 12:47:56 - LandingMotion state updated to OPEN
2015-11-06 12:47:56 - LightLevelFront state updated to Undefined

Cheers
James

Hi James,

please double check whether you really want to read out ‘Number’ items by type==coil?

Please try to setup a slave2 configuration using modbus:tcp.slave2.type=input or holding

See also https://github.com/openhab/openhab/wiki/Modbus-Tcp-Binding

Best regards
Jens

Hi Jens,

Thanks for the pointer, hadn’t spotted the subtlety there!
I’ve now got the following config:

modbus:tcp.slave1.connection=192.168.1.250:502
#modbus:tcp.slave1.port=502
modbus:tcp.slave1.type=coil
modbus:tcp.slave1.id=1
modbus:tcp.slave1.start=0
modbus:tcp.slave1.length=39
#modbus:tcp.slave1.valuetype=

modbus:tcp.slave2.connection=192.168.1.250:502
#modbus:tcp.slave2.port=502
modbus:tcp.slave2.type=input
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=40
modbus:tcp.slave2.length=47
modbus:tcp.slave2.valuetype=float32

Which gives:

2015-11-06 17:50:47.041 [DEBUG] [.b.modbus.internal.ModbusSlave] - ModbusSlave:Error Code = 4
2015-11-06 17:50:47.043 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2015-11-06 17:50:47.247 [DEBUG] [.b.modbus.internal.ModbusSlave] - ModbusSlave:Executing transaction failed (tried 3 times)
2015-11-06 17:50:47.249 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave

I’ve tried commenting out the valuetype too, to no effect.

Thanks
James

I would recommend using wireshark to see what the commands that are being sent. I’ve used it to diagnose modbus problems in the past. if you have another program that actually communicates with the device capture its working packets as well and compare the two. That error usually comes wen you request the wrong type of register or address.

Here is an explanation of the error codes. LINK

I’ve not made much progress this week.
with the following config:

modbus:tcp.slave2.connection=192.168.1.250:502
modbus:tcp.slave2.type=input
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=40
modbus:tcp.slave2.length=2

I get the following in the Wireshark trace:

Query:
- Modbus
    Function Code: Read Input Registers (4)
    Reference Number: 40
    Word Count: 2

Response:
- Modbus
    Function 4:  Read Input Registers.  Exception: Slave device failure
    Exception Code: Slave device failure (4)

I’m afraid I’m not really sure how that helps…

Cheers
J

try and see if you need to be using RTU

modbus:tcp.slave2.connection=192.168.1.250:502:rtu

looking at page 73 is says that 10-16 is analog input register. 20-45 are encoder counter values. also the specific regesteres have to be enabled in the software first page 75 of the Manual

Thanks David,

I hadn’t spotted that (p73), I’d assumed each coil/input etc was referenced by the same input as it is with the Pokeys config.

So, changing the config to:

modbus:tcp.slave2.connection=192.168.1.250:502
modbus:tcp.slave2.type=holding
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=10
modbus:tcp.slave2.length=6

Gives the following output in openhab.log

2015-11-15 08:46:15.499 [DEBUG] [modbus.internal.ModbusTcpSlave] - ModbusSlave: Error connecting to master: Connection timed out: connect
2015-11-15 08:46:15.499 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave not connected
2015-11-15 08:46:15.703 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave

However, the corresponding wireshark trace shows that it’s reading the registers as I’d expect…

- Modbus
    Function Code: Read Holding Registers (3)
    Byte Count: 12
    Register 0 (UINT16): 2414
    Register 1 (UINT16): 0
    Register 2 (UINT16): 0
    Register 3 (UINT16): 0
    Register 4 (UINT16): 0
    Register 5 (UINT16): 0
    Register 6 (UINT16): 0

Bizarre :confused:

Thanks
James

Try changing the item to read decimal instead of float. but it is going to read the voltage. once you read it you will need to make a rule to convert the min max to span 0% to 100%

Number     LightLevelFront_RAW    "Light [%d]"                    (gModbus)   {modbus="slave2:0"}

You have modbus turned on right? PoKeys config tool, Device, Modbus configuration, then turn on what you want to read.

That has been mentioned.

Right now he is receiving a response in modbus but OpenHAB is not parsing it correctly.

:smile:

Result, it’s working, mostly.

Just need to work out why I’m getting so many failures:

2015-11-15 20:16:43.018 [DEBUG] [.b.modbus.internal.ModbusSlave] - ModbusSlave:Executing transaction failed (tried 3 times)
2015-11-15 20:16:43.033 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave

Changing the Poll interval to 1000 doesn’t seem to make much difference either…

Cheers
James

Cool, what do did your config and items end up looking like? I would like to move from http to modbus for my sensors (currently using http).

As far as your errors, I use 200 ms right now for my door / window sensors without any issue.

HI Nathan,

Pokeys:
Pin 41: Configured as an analogue input with an LDR voltage divider circuit (I haven’t looked at using the “EasySensor” config for this; that might allow easy conversion to 0-100 range that I want)

openhab.cfg:

modbus:tcp.slave2.connection=192.168.1.250:502
modbus:tcp.slave2.type=holding
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=10
modbus:tcp.slave2.length=1

.items:

Number  LightLevelFront_RAW "Light [%d]"                (gModbus)   {modbus="slave2:0"}

The missed readings seems to be due to this config, when used with only the config to read coils, there are no failures.

Cheers
J