I'm using the node-red-node-serialport to read and send data to serial and USB ports. How can I react on disconnection of such a device? I'm looking for something like: If device A is currently connected (online), make something, if not (offline) make something else.
Which device? Serial or usb?
Are you asking it for data? If so what happens if it is offline?
These are serial sensors connected via USB-Converters. Some of them I have to ask constantly to send me data. Others are satisfied with a one-time request to send me constantly data. If the device gets offline I have to send this one-time request again as soon as the device gets online. So I want to check if the device is currrently online or offline.
save a timestamp with every msg received. Create another flow that checks the time difference between msg arrived and now. if difference is to big send new request.
Feed the messages from each sensor through a Trigger node (one for each sensor), set to initially send nothing, and send a message after the specified interval. The result will be that provided the messages keep coming in at the expected rate then the Trigger node will be continually reset and will never send its message. If the sensor stops then the trigger will timeout and send its message, which you can use to take whatever action is required. You may need an inject node set to inject once on startup to hit the trigger initially on startup in case the sensor never responds to its first request.
[Edit] This flow pattern is described in one of the examples in the cookbook:
Trigger is the best solution. Thanks for the tip!
Thanks that almost solved my problem.
Is it possible to set the intervall by a message? I can set the intervalls of the sensors dynamically and want therefore to set the trigger seconds dynamically.