跳到主要内容

流程控制-有条件延时触发

在规定时间后未收到消息,则触发流程

问题背景

在指定时间后未收到消息时触发流程。例如,预计每 5 秒接收一次传感器读数,并且需要知道该读数是否未到达,如果未到达,则触发流程。

解决方案

使用 触发器 节点 来检测消息在定义的时间间隔后是否还未到达。

示例

点击 注入 节点,注入时间戳,5s 内如果没有再次通过 注入 节点发送消息,则 触发器 节点: 5s延时检测 会发送一条 timeout 的消息

after-define-time-trigger

示例JSON

[{"id":"6ea53ad8.2362a4","type":"debug","z":"e028a121bc4ae061","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":920,"wires":[]},{"id":"3da6946e.184a5c","type":"inject","z":"e028a121bc4ae061","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":920,"wires":[["38caaff4.03f6d","6ea53ad8.2362a4"]]},{"id":"38caaff4.03f6d","type":"trigger","z":"e028a121bc4ae061","name":"5s 延时检测","op1":"","op2":"timeout","op1type":"nul","op2type":"str","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":380,"y":960,"wires":[["ae477709.016088"]]},{"id":"ae477709.016088","type":"debug","z":"e028a121bc4ae061","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":960,"wires":[]}]

运行结果

after-define-time-trigger-result