Send me notification if status still "reconnecting after "

Hello ,
how I can read communication status with device and it still more 1 minute the systeme send me notification " problem connect to devise".
image

One possible way is using the status node to capture the status from the modbus node. You will get the status on the property "msg.status.text".

You may want to use then a switch node to define which message will trigger the notification (you will see that the modbus node provides more then one type of status). A trigger node will allow you to define how long to wait and how to notify.

Hi Andrei ,
You can send me source code ,
I am begginer in node red

Sure, see below. You will need to tweek the configuration of the nodes and probably modify the flow to suit your use case.

[{"id":"38fe8a3a.af0a46","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"72d0b325.2f226c","type":"modbus-read","z":"38fe8a3a.af0a46","name":"mytcp","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"","adr":"0","quantity":"1","rate":"2","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"1fdecf8e.d4979","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":340,"y":160,"wires":[[],["514e3237.6f0e0c"]]},{"id":"514e3237.6f0e0c","type":"debug","z":"38fe8a3a.af0a46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":200,"wires":[]},{"id":"3f4699c9.f32e06","type":"status","z":"38fe8a3a.af0a46","name":"","scope":["72d0b325.2f226c"],"x":180,"y":340,"wires":[["8c64a36.b68816"]]},{"id":"413a1bdc.37ac74","type":"debug","z":"38fe8a3a.af0a46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":340,"wires":[]},{"id":"3a8ec86e.794008","type":"trigger","z":"38fe8a3a.af0a46","name":"","op1":"","op2":"failed","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":340,"wires":[["413a1bdc.37ac74"]]},{"id":"da629ff1.066ba","type":"debug","z":"38fe8a3a.af0a46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":460,"wires":[]},{"id":"8c64a36.b68816","type":"switch","z":"38fe8a3a.af0a46","name":"","property":"status.text","propertyType":"msg","rules":[{"t":"eq","v":"broken","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":340,"wires":[["3a8ec86e.794008"],["da629ff1.066ba"]]},{"id":"eb18db0.ba65528","type":"comment","z":"38fe8a3a.af0a46","name":"Here a node to notify, for example, Telegram","info":"","x":880,"y":300,"wires":[]},{"id":"1fdecf8e.d4979","type":"modbus-client","z":"","name":"mytcp","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

thanks it is work but I have ,
some time value 1 and 0 , I don't understand why

[{"id":"2e7b7ba7.9731b4","type":"tab","label":"Flow 10","disabled":false,"info":""},{"id":"d56a2027.13657","type":"modbus-read","z":"2e7b7ba7.9731b4","name":"","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"Coil","adr":"10198","quantity":"2","rate":"","rateUnit":"","delayOnStart":false,"startDelayTime":"","server":"143b6522.db746b","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":130,"y":100,"wires":[[],["8f031964.89edf8"]]},{"id":"8f031964.89edf8","type":"debug","z":"2e7b7ba7.9731b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"msg.status.text","targetType":"msg","statusVal":"","statusType":"auto","x":350,"y":240,"wires":[]},{"id":"51af56c0.69ba18","type":"status","z":"2e7b7ba7.9731b4","name":"","scope":["d56a2027.13657"],"x":80,"y":420,"wires":[["aea7db89.3a70d8"]]},{"id":"fc7e36ed.41e568","type":"debug","z":"2e7b7ba7.9731b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":360,"wires":[]},{"id":"96ad5477.621888","type":"trigger","z":"2e7b7ba7.9731b4","name":"","op1":"1","op2":"0","op1type":"val","op2type":"val","duration":"250","extend":"false","units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":420,"y":360,"wires":[["fc7e36ed.41e568"]]},{"id":"aea7db89.3a70d8","type":"switch","z":"2e7b7ba7.9731b4","name":"","property":"status.text","propertyType":"msg","rules":[{"t":"eq","v":"broken","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":420,"wires":[["96ad5477.621888"]]},{"id":"143b6522.db746b","type":"modbus-client","z":"","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"195.145.150.106","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

Indeed, this happens as consequence of how the trigger node is configured (picture below). As per the used configuration the trigger node will send the value "1" wait the configured time (250 ms) and then will send the value "0". You may want to change this configuration to the way that works better for you (for instance, send nothing and after 250ms sends an arbitrary value to notify.

in this example we don't have comparison between new status and old status
But I can't receive notification if status device still offline more 250ms.
I want compare after 250 ms new status with old status if equals send notification

Apparently the modbus node takes 25 seconds to send an update status.If this is true then you won´t be able to manage the notification with 250 milliseconds granularity.

I am not sure I understand how do you want to compare old status with new status. What do you expect to happen when old status = connection broken and new status is the same = connection broken ? Do you want to trigger notification in such case or only when the status changes from connected to not connected (or vice versa) ?

yes I want send notification (via mail ) if devise offline

thanks for all ,
I find solution
Link : https://cookbook.nodered.org/basic/trigger-timeout
just change timestamp by status

[{"id":"6ea53ad8.2362a4","type":"debug","z":"ac14500e.2c57d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":450,"y":1160,"wires":[]},{"id":"3da6946e.184a5c","type":"inject","z":"ac14500e.2c57d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":1160,"wires":[["38caaff4.03f6d","6ea53ad8.2362a4"]]},{"id":"38caaff4.03f6d","type":"trigger","z":"ac14500e.2c57d","op1":"","op2":"timeout","op1type":"nul","op2type":"str","duration":"5","extend":true,"units":"s","reset":"","bytopic":"all","name":"Watchdog","x":270,"y":1200,"wires":[["ae477709.016088"]]},{"id":"ae477709.016088","type":"debug","z":"ac14500e.2c57d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":1200,"wires":[]}]

1 Like

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