Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to add timestamp to MQTT-Message #2586

Closed
J0s3f opened this issue Dec 21, 2019 · 2 comments
Closed

Option to add timestamp to MQTT-Message #2586

J0s3f opened this issue Dec 21, 2019 · 2 comments

Comments

@J0s3f
Copy link

J0s3f commented Dec 21, 2019

Bug Report

What happened

MQTT doesn't contain timestamps in the protocol. So if a message is sent with QoS 1 or QoS 2, cached at the message broker and retrieved at a later time, it is impossible to get the initial time it was sent.

What did you expect to happen

Have an option to add a timestamp to each message (current timestamp from the system running zigbee2mqtt)

How to reproduce it (minimal and precise)

  1. Connect a client with QoS > 0 and Persistent Session, subscribe to a topic that gets sensor data from zigbee2mqtt
  2. disconnect client
  3. configure zigbee2mqtt with QoS>0, start zigbee2mqtt, wait until at least one message is sent to the topic subscribed in 1.
  4. reconnect client
  5. receive message
  6. try to find out the time for the received sensor values
  7. you can't

My proposal would be to just add the current unixtime in UTC from the host to each message as JSON property and make this configurable.

e.g. instead of {"temperature":8.77,"linkquality":94,"humidity":85.15,"pressure":948,"battery":74,"voltage":2955} have {"temperature":8.77,"linkquality":94,"humidity":85.15,"pressure":948,"battery":74,"voltage":2955,"timestamp":1576959102}

Usecase for me is this: I have some zigbee sensors at home and collect all data of temp/humidity/rain/... sensors in InfluxDB.

My parents now also have some zigbee stuff setup, with own MQTT broker.
I want to store at least the outside weather data from their place in my InfluxDB. If everything works, no problem. But if the internet connection or VPN fails, I am missing data. The MQTT broker stores this data, but it is useless if received later. (The sensors send based on changes, so if connection was down for 10 hours and there are 6 messages with different temperatures, it is impossible currently to find out which time this temperatures have been measured)

@pcb1962
Copy link

pcb1962 commented Dec 24, 2019

You can use the last_seen option
https://www.zigbee2mqtt.io/information/configuration.html

@J0s3f
Copy link
Author

J0s3f commented Dec 26, 2019

You can use the last_seen option
https://www.zigbee2mqtt.io/information/configuration.html

This seems to be exactly what I need, thanks!

@J0s3f J0s3f closed this as completed Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants