在Node-RED中实现两个input

在我目前的项目中,我们试图使用Node-RED实现当前的应用程序function。 function如下所示。 这里,Fire状态接收两个input:(1) TemperatureSensor (2) SmokeDetector 。 两个传感器都使用MQTT发布者发布数据。 Firestate组件可以通过MQTT子接口接收数据。

if temperaturevalue > 70 and Smokevalue == trueif temperaturevalue > 70 and Smokevalue == true火焰状态可以基于这两个参数产生输出。 鉴于此,我的问题是 – Node-RED是否支持两种inputfunction? 如果是的话,那么我们该如何实现这个function呢? 如果没有,那么..我可以说,两个inputfunction不能用Node-RED来实现吗? 正如我们所看到的,Node-RED提供了多个输出,而不是input

在这里输入图像描述

您将需要使用function节点并利用contextvariables来保持消息之间的状态,并使用消息主题来确定消息来自哪个input。

像这样的东西:

 context.temp = context.temp || 0.0; context.smoke = context.smoke || false; if (msg.topic === 'smokeDetector') { context.smoke = msg.payload; } else if (msg.topic === 'tempSensor') { context.temp = msg.payload; } if (context.temp >= 70.0 && context.smoke) { return {topic: 'fireState', payload: 'FIRE!'} } else { return null } 

更多的细节可以在这里findfunction节点doc

Interesting Posts