您希望根据 msg.topic
属性的值将消息路由到不同的流。例如,您有一个订阅了多个传感器的 MQTT
节点,并且您希望将消息传递给不同的 Dashboard ui_gauge
节点。
使用 Switch
节点将属性值与节点不同输出对应的不同值进行比较。
[{"id":"3bc8e1d2.744abe","type":"switch","z":"ac14500e.2c57d","name":"Route ","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"temperature","vt":"str"},{"t":"eq","v":"humidity","vt":"str"},{"t":"eq","v":"pressure","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":330,"y":420,"wires":[["907bf3b8.def45"],["fe425938.926838"],["ec261304.52f73"]]},{"id":"be3da36c.1c142","type":"inject","z":"ac14500e.2c57d","name":"","topic":"temperature","payload":"27","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":380,"wires":[["3bc8e1d2.744abe"]]},{"id":"f271ceef.172b3","type":"inject","z":"ac14500e.2c57d","name":"","topic":"humidity","payload":"45","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":420,"wires":[["3bc8e1d2.744abe"]]},{"id":"907bf3b8.def45","type":"debug","z":"ac14500e.2c57d","name":"Temperature","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":510,"y":380,"wires":[]},{"id":"fe425938.926838","type":"debug","z":"ac14500e.2c57d","name":"Humidity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":500,"y":420,"wires":[]},{"id":"ec261304.52f73","type":"debug","z":"ac14500e.2c57d","name":"Pressure","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":500,"y":460,"wires":[]},{"id":"fca957dd.9d8078","type":"inject","z":"ac14500e.2c57d","name":"","topic":"pressure","payload":"1001","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":460,"wires":[["3bc8e1d2.744abe"]]}]
Switch
节点会将收到的消息发送到符合规则的输出。
它可以配置为发送到所有匹配的规则,或者只发送到第一个匹配的规则。
版权所有 OpenJS 基金会 和 Node-RED 贡献者。保留所有权利。OpenJS 基金会 已注册商标并使用商标。有关 OpenJS 基金会 商标列表,请参阅我们的商标政策和商标列表。未在OpenJS 基金会商标列表中指明的商标和徽标是其各自持有者的商标™或注册®商标。使用它们不表示与其有任何关联或获得其认可。
OpenJS 基金会 | 使用条款 | 隐私政策 | OpenJS 基金会章程 | 商标政策 | 商标列表 | Cookie 政策