Inject node triggers automatically when MQTT device connects. Is this normal and expected behavior

Hi,

I was pulling my hair out with a small ESP32 device that seemed to be occasionally entering a state unexpectedly. After several hours of debugging I found that as the device came online it received several messages from node red from nodes I had wired up for testing previously. These nodes were just inject nodes connected directly to MQTT output nodes.
Is this the expected behavior. It doesn't seem right to me.

I am keen to understand why this would be happening.

Thanks in Advance

Matt

Hi @MattCohen,

it sounds like you have some retained messages published to the topics your device is subscribing to.

This will cause the broker to resend them whenever the device connects and subscribes - this isn't Node-RED's doing.

You can clear retained messages by publishing another retained message with an empty payload to those same topics.

https://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages/