ICP_6 - akkipant/IoT-Fall-2019 GitHub Wiki
Introduction:
This lab introduced various function nodes like Switch, Change, Range, RBE, and input/output nodes related to WebSocket, HTML, and MQTT.
- Switch node is like an if-else statement, it will send output to the respective payload according to the set condition.
- Change node will change the input to the output set in the Change Node.
- Range Node will change the range of the input values. It can be used to scale up or scale down values.
- RBE Node will give output only if it is different from the previous input. You can set the tolerance for the same. In the demo, you will see that when the value is greater than 10% of previous value, it will display in the payload.
- HTTP is the transfer protocol to transfer webpages from server to browser and HTML is the language that converts normal text to hypertext.
- WebSocket is a full-duplex communication protocol that works on a single TCP connection.
- MQTT is a lightweight protocol for connecting sensors over the internet.
Objectives:
- To provide demos of function nodes like Switch, Change, Range, RBE, and input/output nodes related to WebSocket, HTML, and MQTT.
- To combine all the flows and create a useable flow.
Approaches/Methods:
Our approach was to execute the examples step by step. First, we started with the Switch function using Random Number generator, then we created flow for Change and RBE. Flows for HTML, WebSocket and MQTT followed. MOTT setup was lengthy and required a lot of installations. We then, created videos for each demo and then proceeded with the combined flow.
Workflow:
Switch:
- Pull out a inject node, Switch function node, General function node, 4 debug nodes.
- Configure the inject node as a timestamp.
- Take a function node to edit and type a JavaScript code to generate a random number. Connect this node to the Switch Node.
- In Switch Node set the conditions you require. We have used < 50, = 50, > 50. Connect the respective payloads to the switch output.
- Deploy the code and activate the inject node to get the output in the debug window.
Change:
- Pull the inject node and set it to string mode. Type the required string. For.eg. "Hello"
- Take a Change Function node, In payload, add the string that you want in the output. For. eg. "Good Morning".
- Connect the debug node at the end. Deploy the flow and check the output.
- You will see the string has changed from Hello to Good Morning.
Range:
- Add 3 input nodes with some numeric values.
- Place a Range node, and connect debug node to it.
- In Range node, set the map input range to result in range.
- Deploy the flow and check the output. Numbers in the input range will be scaled to the output range.
RBE:
- Place a timestamp and a random number generator function as in switch function.
- Pull an RBE function and set it to "block if the value is greater than" in the mode tab. Set any percent value.
- Deploy the code and activate the inject. It will block the values for which the difference is less than 50% of the previous value and only display values greater than 50%.
HTTP:
- Place an HTTP input node and the HTTP output node. Configure the input node to set the URL for Webpage.
- Add a template function node to input and write the HTML code to create "Hello Roos IOT World" as the header.
- Place output HTTP node. After, deploying code, open browser window, and type http://localhost:1880/typeURL.
- The webpage is created.
WebSocket:
- Place input and output WebSocket nodes.
- Connect the inject node to input and debug node to output WebSocket node.
- Select the "Connect to" option and type URL of a public WebSocket tester link https://www.websocket.org/echo.html to test the connection.
- Check the output in the debug window.
MQTT
- Place inject node, input MQTT node, output MQTT Node and debug node.
- MQTT requires a broker and an MQTT Client. Install Hivemq broker. Installation of Hivemq is an arduous task. It requires Java (JRE) 11+ version. Complete all the installations.
- For MQTT Client, install any client. We installed the MQTT.fx client. Configure the client.
- From the installation folder of Hivemq, run the "run.bat" file. This will activate the broker.
- Configure the inject node to string. Setting the "Topic" of the input node is critical in MQTT. Create a folder structure "iot/icp5" in "Topic". Type the required string.
- In the MQTT output node, set the server address as 127.0.0.1:1883, which is the broker address and port number.
- Once the client and broker are active, MQTT gets connected after deploying the flow.
Flow Diagram:
- Switch Node
- Change Node
- Range Node
- RBE Node Demo
- HTTP Node Demo
- WebSocket Demo
- MQTT Demo
Parameters:
All the parameters are mentioned in the video and flow diagrams.
Video:
-
Demo of the Switch Function and Change Node Function
-
Demo of Range Function
-
Demo of RBE Function
-
Demo of HTTP Input-Output Nodes
-
Demo of WebSocket input output
-
Demo of MQTT with Hivemq broker and MQTT.fx client
Evaluation and Discussion:
The MQTT connection was difficult as it required installations of 2-3 software. It required JAVA 11+ and an MQTT broker and a client. Configuring the "Topic" was confusing but later we figured out the correct method.
Conclusion:
From this lab, we learned various nodes of Node-Red. The MQTT initial setup was difficult but ultimately was a good learning experience. We learned to configure the WebSocket and create HTTP page with Node-red along with the Switch, Range and Change function nodes.