Time stamps on MQTT messages... Capture? Where?

I just put a quick ambient light sensor together, on Arduino UNO, with PIR to trigger a light, etc. Now onto putting an Ethernet board on it. And there it is… the question that always puzzles me:

Should I add a time stamp to a MQTT message?
(It would necessitate the NTP protocol on the Arduino to be accurate, despite using accurate RTCs.)

Should the broker do it? (Can it?)

or Should OH eventually time stamp the message?

or Why bother? (I mean it would be at least helpful for debugging?!)

What format? Linux Epoch; local time; UTC, time string?

What are you doing with your MQTT messages? … with regard to time?

Nothing. Arduinos just publish raw data, very simple. Openhab event logs have a timestamp, otherwise you could write a very simple subscriber which listens to the topics of interest and dump a timestamp and value to some sort of data store.

In the meantime I found this: http://jeelabs.org/article/1604a/
Very interesting…

Thanks, most likely the path I will take :slight_smile:

If you use Openhab logging or MQTT broker logging you still need to setup NTP correctly, as this will define accuracy of timestamps.
In case of MQTT logging you can simply subscribe using following command (linux on Raspberry):
mosquitto_sub -v -t /# | xargs -d$’\n’ -L1 sh -c 'date “+%D %T.%3N $0”'
Which automatically appends timestamp to each message. Use > after command to forward output to file and you are done.