Search code examples
mqttsensorsmeasurement

Best practice for sensor data over MQTT


Currently I am using the following approach to send sensor data:

Use case send outside temperature of 23.5 °C.

  • topic: weather/outside/temperature
  • content: 23.5

It is quite easy to send or consume such a message but for the receiver it is difficult to determine the unit of the content.

I have also seen the approach to send "23.5 °C" as content but then it is more difficult to parse.

I can also imagine using a part of the topic name for the unit.

So my question is: What are best practices to send scalar values with a unit in such a way that it is possible to reason about the unit in a automated way but also make it easy to send/receive the data. Are there maybe even standards for this?


Solution

  • {value:23.5, unit:"C"} can be used. I couldn't find any best practises for payloads.