Detect Serial Communication fault

Hi, I am using Node-RED to connect my laptop to a device that has serial communication and is connected to COM2. I am receiving the data in Node-RED through a serial in node and showing the data in a webpage by using uibuilder nodes. I am looking for a way to detect when the device has been disconected and thus the serial in node stops sending data to the uibuilder node. I want to show an alert on the webpage of the uibuilder in case there is no connection to the device. Do you know if there is a way to achieve this? Thanks in advance.


Use the status node to monitor the status of the serial node.

1 Like

Hello @Johrdan, welcome to Node-red.

Here is a little flow to show how you can trigger an alert if the input stops arriving.
If you keep clicking the button all is fine, but when you stop it shows a warning message.

[{"id":"c855f06d63e66941","type":"trigger","z":"947cea7bd1d96252","name":"","op1":"","op2":"You stopped clicking","op1type":"nul","op2type":"str","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":340,"y":100,"wires":[["be60c652792e9de8"]]},{"id":"be60c652792e9de8","type":"ui_toast","z":"947cea7bd1d96252","position":"dialog","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"Warning Popup","x":520,"y":100,"wires":[[]]},{"id":"dc8c6df00dc33355","type":"ui_button","z":"947cea7bd1d96252","name":"","group":"a6e358b.672ffa8","order":2,"width":"0","height":"0","passthru":false,"label":"Don't Stop Clicking","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"date","topic":"topic","topicType":"msg","x":150,"y":100,"wires":[["c855f06d63e66941"]]},{"id":"a6e358b.672ffa8","type":"ui_group","name":"Demo","tab":"4e528085.a1bfa","order":6,"disp":false,"width":"6","collapse":false,"className":"compact"},{"id":"4e528085.a1bfa","type":"ui_tab","name":"Demo","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
1 Like

Thanks, it worked.
I see that the status node only sends a message if the node to which it is connected changes from "connected" to "disconnected" or viceversa. Is it possible to activate the status node every, for example, 5 seconds, to continuously check the status of the node?

That’s not really the model that nodejs uses, and is a bit of an antipattern. It is mainly event driven so things only happen when some changes. If the value is the same we won’t send it again. If you really do need to do this, then you can save the value in a context variable, and then use another flow use a repeating object to read and resend it.

1 Like

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