Messages losing data

I am trying to create a flow that calculates the time of flight of a message as a way of checking my MQTT server is working properly.
My idea is that on startup the flow sends a message then every ten seconds the message is repeated. When the messages are received the time-of-flight is calculated.
Everything was going ok, but I found that the first message sent after ‘deploying’ had a very long TOF. This would have caused the planned flow to generate an error message unnecessarily.
I tried to get the first message rejected by having an additional message element msg.checkTOF and setting the first msg.checkTOF to false and the subsequent messages to to true.
Initially I thought that my logic was wrong. But, I have found that I’m not receiving all the message elements.
Debug nodes show the messages are correct before sending, but everything but the msg.payload is stripped off on receiving the messages.
Node-Red and my MQTT server (Mosquito) are on the same RaspberryPi. Rebooting the Pi doesn’t fix the problem.

MQTT nodes only ever send the msg.payload (to the msg.topic). If you want to add more to the message then you need to add it to the payload.

The Node-red MQTT node uses msg.topic and msg.payload.
Make your additional element msg.payload.checkTOF

If you use v5 protocol, you can add values to user properties (additional to topic and payload). See the built in help.

Thank you for your quick reply.
You have solved my problem :grinning:
I’ve never tried to use messages with anything more than just msg.payload before.
Thank you again, I thought I was going mad when my idea didn’t work.

If I understand correctly, I believe you are seeing "retained messages": MQTT Retained Messages Explained
So, when you re-deploy the mqtt subscribe gets the message that ends up having a large TOF...
Disable retain and you will not have this behaviour.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.