thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
223 stars 55 forks source link

Measurement with unit - C8y mapper #3243

Closed DevAZK closed 2 weeks ago

DevAZK commented 2 weeks ago

Describe the bug Sending measurements with units does not work correctly for Cumulocity. The measurement is transmitted and displayed in Cumulocity, but the units do not appear on the graph.

To Reproduce

  1. Simply create a device and set the unit of e.g. temperature.
tedge mqtt pub -r 'te/device/test///m/environment/meta' '{
  "units": {
    "tavg": "°C"
  }
}'
  1. Then, publish some data:
tedge mqtt pub -r 'te/device/test///m/environment' '{
  "time": "2024-11-12T20:00:00",
  "tavg": 32
}'

The temperature value is displayed as expected, but without any units.

Expected behavior The units should be displayed alongside the data.

reubenmiller commented 2 weeks ago

Apologies, the feature of adding units to the measurements hasn't been implemented yet. The documentation does describe how the feature is intended to work, but as of thin-edge.io 1.3.1, the tedge-mapper-c8y does not read this information when converting the tedge measurements to Cumulocity measurements.

I've created a PR to remove it from the public documentation. We already have an issue with tracks the feature to add support for publishing measurements with units in this ticket: https://github.com/thin-edge/thin-edge.io/issues/982

reubenmiller commented 2 weeks ago

@DevAZK though technically when the feature is implemented, you should be using the tavg property in the /meta message, as that property should match the property you're using when publishing the message, otherwise thin-edge.io has no idea that tavg is actually a temperature value.

So in your example meta message should be:

tedge mqtt pub -r 'te/device/test///m/environment/meta' '{
  "units": {
    "tavg": "°C"
  }
}'

But again, this is not yet implemented by thin-edge.io.

DevAZK commented 2 weeks ago

Oh, I see, all clear. I’ll wait until the feature is implemented then. Yes, obviously the attribute should be "tavg" and not "temperature"—my bad. Thanks for clarifying!