Skip to content

Modbus input - negative values not supported with FLOAT32 #7317

@kolmodin

Description

@kolmodin

Relevant telegraf.conf:

[[inputs.modbus]]
holding_registers = [
  { name = "outdoor_temperature",   byte_order = "AB",   data_type = "FLOAT32",   scale=0.1,     address = [903]},
]

Related issue: #7266.

The register holds a temperature scaled 10x. I want to store the decimals so I use FLOAT32.
When the temperature outdoors is 5.3° the register holds the int 53, and I want to use scaling to store 5.3.
When the temperature is below 0° the register holds a signed integer representing a negative value.
The problem is when the modbus plugin treats negative values.

Expected behavior:

The modbus plugin should handle negative values as well as positive. When the register holds -13 it should be intepreted as -1.3 after scaling.

Actual behavior:

Negative values are treated as unsigned. With a few negative degrees it stores the float 6554.0.
I see no way around this in telegraf except using the type INT16 instead of FLOAT32 and thus throw away the decimals.

Additional info:

FLOAT32 is handled here. It assumes a UINT16 but INT16 values are also possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/modbusbugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions