Closed phagemann closed 11 months ago
The issue seems to be caused by gos7 itself. When querying a single bool in a batch, gos7 builds a different address opposed to a byte. Provided the following S7DataItemStructs
dataItems := []gos7.S7DataItem{
{s7areape, 0x01, 0, 32, 1, make([]byte, 2), ""},
{s7areape, 0x02, 0, 32, 1, make([]byte, 2), ""},
}
I would expect gos7 to query address 32. But instead it queries the following (inspected by wireshark):
The issue seems to be
https://github.com/robinson/gos7/blob/ebce1a99aa32e62adad61e5dffc5a8e316cd5f18/multi.go#L165-L169
Where bit, counter and timer addresses are parsed different. For bits this seems to be wrong, counters and timers I can't test as of right now.
Based on the screenshot above bits addresses should be parsed like the other types.
As there is no way to encode the bit address in S7Comm struct I suggest to query bit addresses as bytes
https://github.com/influxdata/telegraf/blob/f4c56e1597956cd95eb37336e0c08ae361338aba/plugins/inputs/s7comm/s7comm.go#L43
and decode it to bit in
https://github.com/influxdata/telegraf/blob/f4c56e1597956cd95eb37336e0c08ae361338aba/plugins/inputs/s7comm/type_conversions.go#L16
Although this introduces some inefficiencies (querying the same byte-address multiple times for different bits), from my point of view this seems to be the best solution, as otherwise significant changes to gos7 would be required.
Would be happy to provide a PR after some discussion =)
The issue seems to be caused by gos7 itself.
I would not want to take a temporary fix that would need to get reverted or changed, when the upstream has been responsive to PRs.
Can you please put in a fix to the upstream library and we would be happy to update to the latest version of it.
Thanks!
Relevant telegraf.conf
Logs from Telegraf
System info
Telegraf 1.29, Ubuntu 22.04 LTS, S7 CPU 317-3PN/DP
Docker
No response
Steps to reproduce
Expected behavior
Values to be parsed correctly as indicated in Debug log. See Actual behavior
Actual behavior
Value being parsed to
false
independently of actual value indicate by byte[1]
Additional info
Change parsing function in 'telegraf/plugins/inputs/s7comm/type_conversion.go' Line 16 to
Might be a local problem. @srebhan Could you please explain the original function
(buf[0] & (1 << extra)) != 0
so I don't miss something?