In my current project, we are trying to implement the current application functionality using Node-RED. The functionality is shown below. Here, Fire state receives two inputs: (1) TemperatureSensor
(2) SmokeDetector
. Both Sensors are publishing data using MQTT publishers. and Firestate
component can receives data through MQTT subsciber.
The fire state can produce an output based on the these two parameters that is if temperaturevalue > 70 and Smokevalue == true
. In view of this, my question is -- Does Node-RED support the two inputs functionality? If yes, then how can we implement this functionality? If no, then.. Can I say that two input functionality can not be implemented using Node-RED???? As we have seen that Node-RED provides multiple outputs, but not inputs.
The main method of organising flows in Node-RED is by separating them across multiple tabs within the editor. There are a few different strategies that can be used to do that. If you can identify separate logical components of your application, consider putting them on separate tabs.
The function node is used to run JavaScript code against the msg object. The function node accepts a msg object as input and can return 0 or more message objects as output. This message object must have a payload property (msg.
You will need to use a function node and make use of the context
variable to keep state between messages and use the message topic to determine which input a message came from.
Something like this:
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
}
More details can be found in the function node doc here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With