Node-RED使用指南:14:Inject节点的触发方式

在这里插入图片描述
这篇文章介绍一下Inject节点除了手动触发之外的其他方式。

事前准备

以容器方式启动Node-RED服务,启动命令如下所示:

启动命令:docker run -it -p 1880:1880 -v $PWD/data:/data -e TZ=Asia/Shanghai --name nodered -d nodered/node-red:1.0.4

触发方式1: Deploy时触发

在这里插入图片描述

  • Inject节点设定:注意选中Inject once复选框
    Node-RED使用指南:14:Inject节点的触发方式_第1张图片

  • Debug节点设定:显示topic属性内容
    Node-RED使用指南:14:Inject节点的触发方式_第2张图片

  • flow的json表示(export输出结果)

[{"id":"347308fb.329ec8","type":"inject","z":"73554227.4474dc","name":"Deploy时触发","topic":"Deploy时会被触发","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":160,"y":120,"wires":[["bae1bac5.1ad7a8"]]},{"id":"bae1bac5.1ad7a8","type":"debug","z":"73554227.4474dc","name":"显示topic信息","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":400,"y":120,"wires":[]}]
  • 结果确认
    执行Deploy操作之后,可以看到结果显示如下图所示:
    Node-RED使用指南:14:Inject节点的触发方式_第3张图片

触发方式2: 指定时间间隔重复触发

Node-RED使用指南:14:Inject节点的触发方式_第4张图片

  • Inject节点设定:设定每3秒触发
    Node-RED使用指南:14:Inject节点的触发方式_第5张图片

  • Debug节点设定:显示topic属性内容
    Node-RED使用指南:14:Inject节点的触发方式_第6张图片

  • flow的json表示(export输出结果)

[{"id":"347308fb.329ec8","type":"inject","z":"73554227.4474dc","name":"每三秒钟触发","topic":"每三秒触发","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":120,"wires":[["bae1bac5.1ad7a8"]]},{"id":"bae1bac5.1ad7a8","type":"debug","z":"73554227.4474dc","name":"显示topic信息","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":400,"y":120,"wires":[]}]
  • 结果确认
    执行Deploy操作之后,可以看到结果显示如下图所示:
    Node-RED使用指南:14:Inject节点的触发方式_第7张图片

触发方式3: 指定时间触发

Node-RED使用指南:14:Inject节点的触发方式_第8张图片

  • Inject节点设定:指定周日20:02触发
    Node-RED使用指南:14:Inject节点的触发方式_第9张图片

  • Debug节点设定:显示topic属性内容
    Node-RED使用指南:14:Inject节点的触发方式_第10张图片

  • flow的json表示(export输出结果)

[{"id":"347308fb.329ec8","type":"inject","z":"73554227.4474dc","name":"周日20:02触发","topic":"指定周日20:02触发","payload":"","payloadType":"date","repeat":"","crontab":"02 20 * * 0","once":false,"onceDelay":0.1,"x":160,"y":120,"wires":[["bae1bac5.1ad7a8"]]},{"id":"bae1bac5.1ad7a8","type":"debug","z":"73554227.4474dc","name":"显示topic信息","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":400,"y":120,"wires":[]}]
  • 结果确认
    执行Deploy操作之后,等到周日的20:02可以看到结果显示如下图所示:
    Node-RED使用指南:14:Inject节点的触发方式_第11张图片

你可能感兴趣的:(#,Node-Red)