2

Can somenoe tell me how to get the publish-time of a mqtt message in node-red?

I have a retained message on my broker which gets fed to node-red via mqtt. The message is from a homematic wall-button which is hooked up to my broker via homegear.

The problem now is, that homegear retains all messages which is obviously good for sensors and so on. But the "true" message of the button - if pressed - also retains in it's topic. On deploy or restart of node-red it will receive the retained message and act if when the message just arrived.

Till homegear will put a "false" in the topic after the button is pressed, I have to check if the message in the topic is not an old one. Any chance?

The mqtt help of node-red tells me there are only four properties from mqtt: msg.topic, msg.payload, msg.qos, msg.retain.

Thanks for you help!

Cheers, Patrik

pmayer
  • 341
  • 2
  • 13

1 Answers1

1

Unfortunately there is no way to get the time the message was actually published, the fields you are getting (qos, retained, topic and payload) are the only data in the whole message (MQTT is specifically designed to be as light as possible so has the absolute minimum data in the headers).

The only way to get the time is for the publisher to include it in the message payload.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • I thought about that but hoped that I can at least the time. But it's totaly unterstandable... Thank you! – pmayer Aug 11 '16 at 20:54
  • Momentary/push buttons would be better to not publish retained messages, but if not they need to publish their state properly (true when closed, false when open) – hardillb Aug 11 '16 at 20:56
  • Your are absolutely right. I'm in contact with the developer of homegear to change that behavior. Unfortunately you can only retain all or none. I think I can work out a solution with him. – pmayer Aug 11 '16 at 21:00
  • To be complete: Homegear got updated and won't retain messages which came from actions anymore. – pmayer Aug 18 '16 at 21:21