Sign inSign up

dersimn/mosquitto-with-user-properties-plugin

By dersimn

•Updated over 1 year ago

Image
0

1.4K

dersimn/mosquitto-with-user-properties-plugin repository overview

⁠Purpose

Plugin that adds userProperties

  • $TIMESTAMP: Exact unix epoch (in ms) when the broker received a published message
  • $CLIENT_ID: Client ID of sender
  • $CLIENT_USERNAME: Client Username of sender

to every message on the broker side. Example:

Payload: Packet {
  cmd: 'publish',
  retain: true,
  qos: 0,
  dup: false,
  length: 135,
  topic: 'test-retained',
  payload: <Buffer 7b 22 76 61 6c 22 3a 30 7d>,
  properties: {
    userProperties: [Object: null prototype] {
      foo: 'bar',
      '$TIMESTAMP': '1695466515661',
      '$CLIENT_ID': 'myClient123-retained',
      '$CLIENT_USERNAME': 'myUser-retained'
    }
  }
}
Received by us: 1695466523203
Diff (received by us/received by broker): 7542

As you can see, $TIMESTAMP is the exact time the broker received the message. The difference between "now" and $TIMESTAMP is 7542 ms in this example, so we now know how old a retained message is.

⁠Why?

For example, if you have battery-powered sensors that send values only every few minutes. You probably want to retain these messages to display them in a user interface, but you still want to know how old a received message is. If the sensor doesn't have a built-in RTC, it can't attach a useful timestamp itself - so why not let the broker do it?

⁠Source

See further examples on GitHub: dersimn/mosquitto-with-user-properties-plugin⁠.

Tag summary

Content type

Image

Digest

sha256:a098d3fc5…

Size

4.2 MB

Last updated

over 1 year ago

docker pull dersimn/mosquitto-with-user-properties-plugin