Node-red last will message

Hello All,

We are trying to simulate lastwill message scenario using node-red tool. We configured lastwill topic and message in the message tab. We are trying to close the node-red command window but it seems it is always graceful disconnect.

What is the way in node-red to simulate ungraceful disconnect ?

Thanks,
Tejas

Unplug the network connection between node red server and the broker.
Alternatively kill node red with the signal that forces an immediate stop. How you do this depends on your OS.

1 Like

I did the same kill process and node-red process in windows. but it doesn't seems to be working

I don't know how to kill a process in windows in such a way that it does not shut down gracefully, so can't help with that one.
Did pulling the cable work?

First we should aggree that last will message wont be sent by node red but by the broker right? Because thats how last will messages work.

Is node red the client or the broker here?

If its the client and the broker is another mqtt server online then you can turn off the wifi on the node red server and wait for the timeout on the broker

Yes, I mean broker here. So timeout means idle timeout of mqtt broker right?

I am sorry, but that sentence means nothing to me.

Yes the right terminology is idle timeout i think.

So you need to disconnect the client not the broker here.

Broker will understand that the client has disconnected, and send the last will message that was shared by the client initially when the connection was opening.

Heres some additional reading about the topic :

https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/

@tetrived as you've seen, simply stopping Node-RED allows the client to disconnect cleanly.

On Windows, I think you can use the /f option to taskkill in order to forceable end the process without letting it shutdown cleanly - taskkill | Microsoft Docs