Node-RED Architecture
Node-red does most of the processing in terms of determining the temperature status and reporting back to the gateway.
Below is the complete flow of the Node-RED architecture.
(debug nodes are used for backend debugging)
The architecture can be split into 4 different sections.
- Initializing
- Publishing / Manipulating
- Plotting / Finalizing
- Thresholds
Initializing
First, before manipulating the information, Node-RED saves the previous values sent by the gateway. This is because the nodes are either sleeping to reduce energy consumption or there is no temperature change. Saving the values allows the dashboard to not have missing values.
Below is the First part, Initializing the values.
![[Initializing Values Flow]](/ArduinoGPProjectDir/images/InitializingValuesNodeRed.png)
- Node-RED recieves the values from the Gateway using a MQTT Broker. (EnvPublish4482)
- Seperate each value from the recieved json file (Set Temp Payload Temp #)
- Save last values Since the gateway sends values every second it sometimes sends values that are empty, function (save temp #) checks if its empty. If not it saves the value. The value is saved as a flow instead of msg.
- Inject Current Value every second (flow.MyNumber#)
It does this process for each of the nodes and saves the temperatures when it recieves them.
Publishing / Manipulating
The values are published onto the dashboard using a text node (Current Temp ESP-#), while temperature values are checked using function nodes (Get Message for Temperature). [Publishing/Manipulating Flow]
The manipulating is done using a function. The function checks for current saved temperature values and theshold values (see Threshold section). From the [Code] Both values are initialized and checked between eachother to determine if values are either too cold, good or too hot to then output a string message stating the current state.
Plotting / Finalizing
Below is the image displaing the plotting and finalizing of the flow. ![[Plot/Finalizing Flow]](/ArduinoGPProjectDir/images/Plot_Fin_Flow.png)
The chart node (Temp vs Time (Last 10 Readings)) recieves the continuous values from the inject node (flow.MyNumber#) to plot it over time.
the chart used only 10 readings for visuals, can be changed to a longer time interval in real life situations
The text node (Current Condition ESP-#) displays he current status of each node corresponding to the output from the (Get Message for Temperature).
The change node (set.flow.Condition#) is used to save the current condition to get it checked.
Finally the function Node (function1) collects the current condition from each node and outputs LED Values. ([Code]) If the temperature is too hot or too cold the function sends out a JSON message to the gateway (LEDOverride4482) to change the LED values of the nodes to RED. Otherwise it sends the gateway a value of GREEN.
Thresholds
The Final part is the setting that changes the threshold values for each node individually. This is done in the flow below. ![[Threshold Flow]](/ArduinoGPProjectDir/images/Threshold_setting.png)
The dashboard will display a list of inputs that can be changed.(ESP# Thresh) It will save the inputted value (StoredValues) to dynamically change the threshold values of the nodes. This will also dynamically change within Node-RED to display the current temperature condition accordingly.
Dashboard
Below is the view of the Dashboard. Including the current temperature, condition, plotted values of last minute and the interface to change individual node thresholds.
![[Node-RED Dashboard]](/ArduinoGPProjectDir/images/dashboard.png)