Hello, I integrated a load management for the winter in my house. For that I´m using my inverter (charge / discharge battery in the night with cheap prices.
Sometimes the program from the inverter in linux hang up and send no new values. If that happen, the load management couldn´t be safe and must switch off charging battery.
All values from interter comes via MQTT.
Now my idea is to read via Nodered, if the program hangs up and send no new values. I realized that in a different way with Blockly like this:
"Current time" minus "last change from that value" > 1 minute
I´m not sure, what should be the best: Last change from that value or last update / new information from that value. I think I must try what is the best, because Mosquitto maybe send permanent values - I don´t know currently- have to test that.
I tried that with Trigger nodes, but it didn´t work as I thougt:
You can implement a reaction to missing messages process using a single trigger node.
Let's say that messages normally arrive from the inverter at 1 minute intervals and you want to take action after 2 minutes without news.
Set the trigger node to send nothing, wait 125 seconds, then send an alert. Check "Extend delay if new message arrives".
Take a look at the MQTT Last Will & Testament feature.
With this the MQTT broker and client (the inverter) send an intermittent handshake. If the client does not respond to the handshake for 30 seconds, the broker publishes a LWT message for the client which Node-red can subscribe to.
There is a Birth message too, sent when the client reconnects.
That was a really good idea.
If the program is hanging up, the MQTT didn´t receive any message. After 10 times no new message command kill for the program and restart after delay 5 min. that program with dex. Great.
With your Last Will & Testament - I think that should be QoS 0, 1, 2
In the past I didn´t use that. Maybe that is a good idea, but with the point above my problem is done.
If a client has a birth, close or will message set up (in Node-red they are on the Messages tab of the server setup), these messages are sent to the broker when the client first connects.
The birth message is sent to subscribers immediately.
The close message is sent when the connection is closed gracefully.
An exchange of handshake messages allows the broker to spot if the client has crashed or hung up. After a period of time with no successful handshake, default 30 sec, the will (aka LWT) message is sent to subscribers.
OK, new for me, and I found that.
But I think with every 5 seconds a new message should receive I´m in the end of my problem. Otherwise I can add the LWT
You are right the trigger node should be sufficient for your requirement.
The only extra value of LWT for you would be if a third machine was subscribed to the LWT of both your Node-red machine and the source of your messages, you would have the possibility of detecting if either goes down.
The program is hangig up and no new values comes - value is ever the same.
The trigger must react after 45 seconds and restart the program. But the problem is: The program isn´t really hanging up, only the USB connection to the inverter. That means, the program sends continously new messages, every 5 seconds to MQTT and then to NodeRED. But the value didn´t change, it´s freezed.
So now is the question, how the trigger can detect, if the current value 0789 change latest after 45 seconds. If the value didn´t change, the trigger send the restart command.
Sorry but I thought the problem was fixed in our last discussion in that topic. Thanks for your help again.