Skip to content

Commit eede67a

Browse files
authored
Merge pull request #142 from arduino/karlsoderby/nred-review-may
Node-RED Review
2 parents 228e9ed + 6e9b997 commit eede67a

File tree

1 file changed

+69
-63
lines changed

1 file changed

+69
-63
lines changed

content/cloud/iot-cloud/tutorials/11.nodered/nodered-intro.md

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,40 @@ In this tutorial, we will look into the applications of using Node-RED together
2121

2222
## Goals
2323

24-
- Set up Node-RED with the Arduino IoT Cloud
25-
- Use simple Flows with Node-RED
26-
- Build a Node-RED Flow that pulls data from Arduino IoT Cloud
27-
- Manipulate data received from the Arduino IoT Cloud using JavaScript code
28-
- Send email notifications with data from the Arduino IoT Cloud
24+
- Set up Node-RED with the Arduino IoT Cloud.
25+
- Use simple Flows with Node-RED.
26+
- Build a Node-RED Flow that pulls data from Arduino IoT Cloud.
27+
- Manipulate data received from the Arduino IoT Cloud using JavaScript code.
28+
- Send email notifications with data from the Arduino IoT Cloud.
2929

3030
## Hardware & Software Requirements
3131

32-
- The [Arduino Create Agent](https://github.com/arduino/arduino-create-agent)
32+
- [Arduino Create Agent](https://github.com/arduino/arduino-create-agent)
33+
- [Node.js](https://nodejs.org/en/) and [Node-RED installed]()
3334
- An [Arduino account](http://create.arduino.cc/iot).
3435

35-
You will also need a cloud compatible board:
36+
For this tutorial, you will need a cloud compatible board. You will find all compatible boards in the link below:
3637

37-
- [MKR 1000 WiFi](https://store.arduino.cc/arduino-mkr1000-wifi)
38-
- [MKR WiFi 1010](https://store.arduino.cc/arduino-mkr-wifi-1010)
39-
- [MKR WAN 1300](https://store.arduino.cc/arduino-mkr-wan-1300-lora-connectivity-1414)
40-
- [MKR WAN 1310](https://store.arduino.cc/mkr-wan-1310)
41-
- [MKR GSM 1400](https://store.arduino.cc/arduino-mkr-gsm-1400)\*
42-
- [MKR NB 1500](https://store.arduino.cc/arduino-mkr-nb-1500-1413)\*
43-
- [Nano RP2040 Connect](https://store.arduino.cc/nano-rp2040-connect)
44-
- [Nano 33 IoT](https://store.arduino.cc/arduino-nano-33-iot)
45-
- [Portenta H7](https://store.arduino.cc/portenta-h7)
38+
- [Arduino IoT Cloud compatible hardware.](/cloud/iot-cloud/tutorials/iot-cloud-getting-started#compatible-hardware)
4639

47-
***Please note: The MKR GSM 1400 and MKR NB 1500 require a SIM card to connect to the cloud, as they communicate over mobile networks.***
4840

4941
## Node-RED Setup
5042

5143
Setting up Node-RED is simple, we will run it locally following the steps below:
5244

53-
**1.** [Install a supported version of Node.js](https://nodered.org/docs/faq/node-versions) if it's not already installed.
45+
**1.** Install [Node.js](https://nodejs.org/en/). To check if Node.js is installed, open a terminal and enter the following command:
5446

55-
**2.** Install Node-RED from the command line using the command `sudo npm install -g --unsafe-perm node-red`, delete `sudo` if you are using a Windows device.
47+
```shell
48+
node --version
49+
```
50+
51+
If correctly installed, you will see the version number printed in the terminal.
52+
53+
**2.** Install Node-RED from the command line using the command `sudo npm install -g --unsafe-perm node-red`, delete `sudo` if you are using a Windows machine.
5654

57-
**3.** Start it by running the command `node-red` in the terminal, you should see a similar output to this:
55+
**3.** After installation, start it by running the command `node-red` in the terminal, you should see a similar output to this:
5856

59-
```shell
57+
```shell
6058
$ node-red
6159

6260
Welcome to Node-RED
@@ -77,21 +75,22 @@ Setting up Node-RED is simple, we will run it locally following the steps below:
7775
30 Jun 23:43:44 - [info] Started flows
7876
30 Jun 23:43:44 - [info] Server now running at http://127.0.0.1:1880/red/
7977

80-
```
78+
```
79+
8180
**4.** Open the Node-RED editor by going to your browser and entering `http://localhost:1880`.
8281

83-
For a more detailed guide, you can check [Node-RED's installation page](https://nodered.org/docs/getting-started/local).
82+
***For more details on installing Node-RED, you can check [their installation page](https://nodered.org/docs/getting-started/local).***
8483

8584
## The Node-RED Editor
8685

8786
The Node-RED editor consists of four main parts:
8887

89-
- a header on the top containing the deploy button, main menu, and the user menu (only visible if user authentication is enabled)
90-
- the palette on the left side, containing the available nodes
91-
- a workspace in the middle, where flows can be created
92-
- the sidebar on the right, containing editing tools such as a node configuration tool and a debugger
88+
- A header on the top containing the deploy button, main menu, and the user menu (only visible if user authentication is enabled).
89+
- The palette on the left side, containing the available nodes
90+
- A workspace in the middle, where flows can be created
91+
- The sidebar on the right, containing editing tools such as a node configuration tool and a debugger.
9392

94-
![the node red editor](./assets/nodered-01.png)
93+
![The Node-RED editor](assets/nodered-01.png)
9594

9695
You can run the simple flow shown below using Node-RED's default nodes:
9796

@@ -106,38 +105,38 @@ You can run the simple flow shown below using Node-RED's default nodes:
106105
- press Depoly from the header on the top
107106
- finally, press on the checkbox of the message node
108107

109-
![Creating a simple flow](./assets/nodered-02.gif)
108+
![Creating a simple flow](assets/nodered-02.gif)
110109

111110
Your message should be printed to the console on the right side.
112111

113112
In addition to the default nodes installed in node-RED, you can use the palette manager to install additional nodes that can be useful to creating more advanced flows. Follow the steps below to install the Arduino IoT Cloud nodes using the palette manager:
114113

115-
**1.** click on the menu in the header bar in the top right corner
114+
**1.** Click on the menu in the header bar in the top right corner.
116115

117-
**2.** select **"Manage palette"**
116+
**2.** Select **"Manage palette"**.
118117

119-
**3.** go to the "install" tab
118+
**3.** Go to the **"Install"** tab.
120119

121-
**4.** search for "Arduino"
120+
**4.** Search for **"Arduino"**.
122121

123-
**5.** from the shown results, install **"@arduino/node-red-contrib-arduino-iot-cloud"**
122+
**5.** From the results, install **"@arduino/node-red-contrib-arduino-iot-cloud"**.
124123

125-
![Installing the Arduino IoT Cloud Pallette](./assets/nodered-03.gif)
124+
![Installing the Arduino IoT Cloud Palette](assets/nodered-03.gif)
126125

127126
Now, you should be able to use the Arduino IoT Cloud nodes from the palette on the left side of the editor. There are five IoT Cloud nodes: property in, property out, historic, periodic, and inject. Each of the nodes has a description of its function, which appears when you hover over the node.
128127

129128
## Setting Up a Thing
130129

131-
The Thing we will set for this example is quite simple. It is a sketch to read humidity values from a **DHT11 humidity sensor**, any other values can be used alternatively, such as temperature, soil moisture, light...etc. Keep in mind that the code and example below are specific to using the DHT11 humidity sensor.
130+
The Thing we will create for this example is quite simple. It is a sketch to read humidity values from a **DHT11 humidity sensor**, any other values can be used alternatively, such as temperature, soil moisture, light etc. Keep in mind that the code and example below are specific to using the DHT11 humidity sensor.
132131

133132
Follow the steps below to set up the Thing:
134133

135134
- Go to the Arduino IoT Cloud -> Thing -> Create a Thing
136135
- Add your Device and your Network credentials
137136
- Add an integer Variable, with the name humidity, and set permissions to Read Only
138-
- Go to the sketch tab -> replace the code with the code below:
137+
- Go to the **"Sketch"** tab and replace the code with the code below:
139138

140-
```c++
139+
```arduino
141140
142141
#include "thingProperties.h"
143142
#include <Arduino_MKRIoTCarrier.h>
@@ -170,40 +169,47 @@ Follow the steps below to set up the Thing:
170169
171170
int readValue = DHT.read11(DHT11_PIN); // check the data coming from the DHT pin
172171
humidity = DHT.humidity; // assign the humidity variable to data from sensor
173-
delay (1000);
174172
}
175173
176174
```
177175

178-
- The final step is connecting the **DHT11 humidity sensor** to our Arduino MKR WiFi 1010 board, as shown in the image below. Feel free to use any other Cloud compatible board, and a sensor of your choice.
176+
### Circuit
177+
178+
The final step is connecting the **DHT11 humidity sensor** to our Arduino MKR WiFi 1010 board, as shown in the image below. You can also freely use any other [IoT Cloud compatible board](/cloud/iot-cloud/tutorials/iot-cloud-getting-started#compatible-hardware) and a different sensor.
179179

180-
![Connecting the DHT11 Sensor](./assets/nodered-09.png)
180+
![Connecting the DHT11 Sensor.](assets/rednode-09.png)
181181

182182
## Communicating with Node-RED
183183

184184
Use the steps below to use Node-RED with the Arduino IoT Cloud:
185185

186-
![Obtaining API Key](./assets/nodered-04.gif)
186+
![Obtaining API Key](assets/nodered-04.gif)
187+
188+
**1.** Go to the Arduino IoT Cloud -> Integrations -> Create API Key
189+
190+
**2.** Save the Client ID and Client Secret in a safe document
191+
192+
**3.** Go to Node-RED web page at [http://localhost:1880](http://localhost:1880)
193+
194+
**4.** Add the Arduino IoT Cloud "**property out**" node from the palette menu on the left side
195+
196+
**5.** Double click on the node -> select "Add new Arduino-connection"
197+
198+
**6.** Click on the pen icon to enter the API Key details -> enter the Client ID and Client Secret saved in the previous steps -> click on the ADD button
187199

188-
- Go to the Arduino IoT Cloud -> Integrations -> Create API Key
189-
- Save the Client ID and Client Secret in a safe document
190-
- Go to Node-RED web page at [http://localhost:1880](http://localhost:1880)
191-
- Add the Arduino IoT Cloud "**property out**" node from the pallette menu on the left side
192-
- Double click on the node -> select "Add new Arduino-connection"
193-
- Click on the pen icon to enter the API Key details -> enter the Client ID and Client Secret saved in the previous steps -> click on the ADD button
194-
- Now, you should be able to select any of your Things and properties (Variables). In our case, we select the **Humidity Thing**, and **humidity property** (Variable) to retrieve data values from.
200+
**7.** You should now be able to select any of your Things and properties (Variables). In our case, we select the **Humidity Thing**, and **humidity property** (Variable) to retrieve data values from.
195201

196-
![Communicating with the Cloud](./assets/nodered-05.gif)
202+
![Communicating with the Cloud.](assets/nodered-05.gif)
197203

198-
![Values in console](./assets/nodered-06.gif)
204+
![Values in console.](assets/nodered-06.gif)
199205

200206
### Creating a Flow
201207

202-
Now that you have a node pulling data from the Arduino IoT Cloud, you need to use the inject node in order to manipulate and send the data. All you need to do is dragging an inject node and connect it to the property out node, then double clicking on the inject node to ensure that the right Thing and property are selected. Finally, we will add a debug node from the top of the pallette menu, to print the values coming from the Arduino IoT Cloud into the console.
208+
Now that you have a node pulling data from the Arduino IoT Cloud, you need to use the inject node in order to manipulate and send the data. All you need to do is dragging an inject node and connect it to the property out node, then double clicking on the inject node to ensure that the right Thing and property are selected.
203209

204-
Now, you will be able to see the values from the humidity sensor printed into the Node-RED console.
210+
Finally, we will add a debug node from the top of the palette menu, to print the values coming from the Arduino IoT Cloud into the console. You will now be able to see the values from the humidity sensor printed into the Node-RED console.
205211

206-
The next step is adding a **function node** that processes the data coming from the Arduino IoT Cloud. This node is important when working with a constant flow of data, as it allows you to use JavaScript code to create customized triggers from the received values. After dragging the function node into the editor, double click on the node and select "**on message**" tab, then insert the code below:
212+
The next step is adding a **function node** that processes the data coming from the Arduino IoT Cloud. This node is important when working with a constant flow of data, as it allows you to use JavaScript code to create customized triggers from the received values. After dragging the function node into the editor, double click on the node and select **"on message"** tab, then insert the code below:
207213

208214
```js
209215
let data = msg.payload;
@@ -225,26 +231,26 @@ if(data<60 && trigger){
225231
}
226232
```
227233

228-
This simple code will only send values when they are above 60, or when they change back to below 60. You can connect it to the flow, in between the humidity inject node, and the debug node. Try it out by blowing on the humidity sensors to increase the values.
234+
This code will only send values when they are above 60, or when they change back to below 60. You can connect it to the flow, in between the humidity inject node, and the debug node. Try it out by blowing air on the humidity sensors to increase the values.
229235

230-
![Filtering values with a function](./assets/nodered-07.gif)
236+
![Filtering values with a function.](./assets/nodered-07.gif)
231237

232238
### Sending Email Notifications
233239

234240
Now that you are able to pull and manipulate data from the Arduino IoT Cloud, it's time to use this data. In this example, we will show how to send alarm notifications to your email, using the Arduino IoT Cloud. To achieve this, we need to add an email nodes following the steps below:
235241

236-
- click on the menu in the header bar in the top right corner
237-
- select **"Manage palette"**
238-
- go to the "install" tab
239-
- search for "Email"
240-
- from the shown results, install **"node-red-node-email"**
242+
- Click on the menu in the header bar in the top right corner.
243+
- Select **"Manage palette"**.
244+
- Go to the "install" tab.
245+
- Search for "Email".
246+
- From the shown results, install **"node-red-node-email"**.
241247

242-
Next, drag the email node from the pallette menu on the left side into the editor. Double click on the node, then enter an email to send the data to, as well as your email information to send the data from.
248+
Next, drag the email node from the palette menu on the left side into the editor. Double click on the node, then enter an email to send the data to, as well as your email information to send the data from.
243249

244250
![Email node](./assets/nodered-08.png)
245251

246252
Now, all you need to do is replace the debug node with the email node to receive email notifications with the humidity data received from the Arduino IoT Cloud. You can customize the emails using the function node if you wish.
247253

248254
## Further Applications
249255

250-
In this tutorials we demonstrated how you can use the Arduino IoT Cloud together with Node-RED to build a more complex automation applications. The email notification is only one of the many different use cases, other applications can be creating communication between the Arduino IoT Cloud to other home automation devices, sending customized SMS and WhatsApp messages, and many more.
256+
In this tutorials we demonstrated how you can use the [Arduino IoT Cloud](https://create.arduino.cc/iot/) together with [Node-RED](https://nodered.org/) to build a more complex automation applications. The email notification is only one of the many different use cases, other applications can be creating communication between the Arduino IoT Cloud to other home automation devices, sending customized SMS and WhatsApp messages, and many more.

0 commit comments

Comments
 (0)