9. Tasks๏ƒ

The tasks below are designed to teach Node-RED UI and its basics

9.1. Task 1๏ƒ

9.1.1. Task 1.1๏ƒ

Todo

Create a flow with an inject node and debug node.

Follow the steps below:
  1. Add the nodes on workspace and join them.

  2. Deploy the flow.

  3. Open Debug window from sidebar.

  4. Click on the square button on inject node and observe the output on debug window. You must see some numbers in debug. Check the help to find what these numbers mean.

9.1.2. Task 1.2๏ƒ

Todo

Inject automatically after 2 second. See the complete message in Debug.

Follow the steps below:
  1. Open the node configuration of inject and set it to repeat every 2 seconds.

  2. Open the node configuration of debug and set it to display complete message.

  3. Deploy the changes and observe the Debug window. You must see the complete message between { } brackets.

9.1.3. Task 1.3๏ƒ

Todo

Use function to add property to a message.

Follow the steps below:
  1. Add a function node in between the inject node and debug node.

  2. Add the following code to the function. This function adds a property called name to the message and then returns it out from the function.

    msg.name = "[YOUR NAME]";
    return msg;
    
  3. Deploy the changes and observe the Debug window. You must see your name on the debug window.

9.2. Task 2๏ƒ

Note

You would need the following palettes installed.

Todo

Use random function to publish values between 15 to 35. It must repeat every 5 seconds. Add a function to convert these values from celsius in fahrenheit. Name the function Temp Converter. Use the output of this function to display values on a chart.

The label of chart must be room temperature. Set the value of x-axis to last 10 minutes.

Note

To open dashboard, look for a bar chart icon on side panel. Click on it and then find an icon as in image below.

../../_images/dashboard_icon.png

Fig. 9.3 Dashboard Icon๏ƒ

Hint

You will need to add an inject node before the random function generator to repeat values at specified interval.

9.3. Task 3๏ƒ

Todo

Create a HTTP endpoint which responds to GET requests and handles the parameters passed in the url.

http://example.com/hello-query?PARAMETER_1=VALUE_1

../../_images/http_task_flow.png

Fig. 9.4 Task flow structure๏ƒ

Tips for First Flow are provided below:
  1. In template node from function section. Enter the following code in the editor.
    <html>
        <head></head>
        <body>
            <h1>Hello {{req.query.name}}!</h1>
        </body>
    </html>
    
Tips for Second Flow are provided below:
  1. In http request node. In URL, enter the following and keep the rest setting unchanged.

    http://localhost:1880/hello-query?name={{{payload}}}
    

    or this if the above doesnโ€™t work

    http://127.0.0.1:1880/hello-query?name={{{payload}}}
    

The output must look like this: Remember to See the blue highlighted text below. You output must be as in blue color.

../../_images/http_task_output.png

Fig. 9.5 Task output๏ƒ

9.4. Task 4๏ƒ

Todo

Create a user input form on dashboard. The form should take the following inputs from user: Name, Email-ID and Favorite number.

Use this form to save data to a .txt file.

Use the Node-RED help book icon ( ๐Ÿ“• ).