Modbus coils give wrong values

Hello!

I’m query coils on 2 modbus hosts.
One give me the correct values.
The other give me all coils “0” if the first coil is “0”
and if the first coil is “1” the host responds with “1” for the first coil and the rest of the coils with “0”.

here are the values by a “modbus-query-tool”:

values:
  1 (ad 00056):     0
  2 (ad 00057):     0
  3 (ad 00058):     1
  4 (ad 00059):     0
values:
  1 (ad 00000):     0
  2 (ad 00001):     0
  3 (ad 00002):     1
  4 (ad 00003):     1

and here the complete telegraf-config with results:

[[inputs.modbus]]
name = “test_bad”
slave_id = 200
controller = “tcp://10.0.0.222:502”

coils = [
{ name = “Coil_1” , address = [56]},
{ name = “Coil_2” , address = [57]},
{ name = “Coil_3” , address = [58]},
{ name = “Coil_4” , address = [59]},
]

[[inputs.modbus]]
name = “test_good”
slave_id = 1
controller = “tcp://10.0.0.113:502”

coils = [
{ name = “Coil_1” , address = [0]},
{ name = “Coil_2” , address = [1]},
{ name = “Coil_3” , address = [2]},
{ name = “Coil_4” , address = [3]},
]

Starting Telegraf 1.17.0
modbus,host=test,name=test_good,type=coil Coil_1=0i,Coil_2=0i,Coil_3=1i,Coil_4=1i 1611599581000000000
modbus,host=test,name=test_bad,type=coil Coil_1=0i,Coil_2=0i,Coil_3=0i,Coil_4=0i 1611599581000000000

Coil_3 (addr 58) should be “1”

here are 2 wireshark packets for each host:
test.pcapng.gz (505 Bytes)

Hello,

Do you think the problem you are having could be related to this issue?

Hello,

I’m not sure because in my case it happens even with 2 coils (if the first one is “true”).
Maybe TomGdy could test it with 2 coils which are both “true”.

In my case the response ip-packet comming from modbus-device seems to be valid but only misinterpreted by telegraf (did you take a look at the captured packets?).
I dont konw if this is the case on the other issue.

Hi,

I had a look at your capture packets. From looking at the code I think the input plugin only reads 8 bits from the coils, so where in test_bad the value is at bit 56 it’s not getting to it.

I would recommend creating an issue in the Telegraf repo with your use case, to see if others have experienced something similar so it can be worked on / looked into further.