You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***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.***
48
40
49
41
## Node-RED Setup
50
42
51
43
Setting up Node-RED is simple, we will run it locally following the steps below:
52
44
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:
54
46
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.
56
54
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:
58
56
59
-
```shell
57
+
```shell
60
58
$ node-red
61
59
62
60
Welcome to Node-RED
@@ -77,21 +75,22 @@ Setting up Node-RED is simple, we will run it locally following the steps below:
77
75
30 Jun 23:43:44 - [info] Started flows
78
76
30 Jun 23:43:44 - [info] Server now running at http://127.0.0.1:1880/red/
79
77
80
-
```
78
+
```
79
+
81
80
**4.** Open the Node-RED editor by going to your browser and entering `http://localhost:1880`.
82
81
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).***
84
83
85
84
## The Node-RED Editor
86
85
87
86
The Node-RED editor consists of four main parts:
88
87
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.
93
92
94
-

93
+

95
94
96
95
You can run the simple flow shown below using Node-RED's default nodes:
97
96
@@ -106,38 +105,38 @@ You can run the simple flow shown below using Node-RED's default nodes:
106
105
- press Depoly from the header on the top
107
106
- finally, press on the checkbox of the message node
108
107
109
-

108
+

110
109
111
110
Your message should be printed to the console on the right side.
112
111
113
112
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:
114
113
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.
116
115
117
-
**2.**select**"Manage palette"**
116
+
**2.**Select**"Manage palette"**.
118
117
119
-
**3.**go to the "install" tab
118
+
**3.**Go to the **"Install"** tab.
120
119
121
-
**4.**search for "Arduino"
120
+
**4.**Search for **"Arduino"**.
122
121
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"**.
124
123
125
-

124
+

126
125
127
126
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.
128
127
129
128
## Setting Up a Thing
130
129
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, lightetc. Keep in mind that the code and example below are specific to using the DHT11 humidity sensor.
132
131
133
132
Follow the steps below to set up the Thing:
134
133
135
134
- Go to the Arduino IoT Cloud -> Thing -> Create a Thing
136
135
- Add your Device and your Network credentials
137
136
- 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:
139
138
140
-
```c++
139
+
```arduino
141
140
142
141
#include "thingProperties.h"
143
142
#include <Arduino_MKRIoTCarrier.h>
@@ -170,40 +169,47 @@ Follow the steps below to set up the Thing:
170
169
171
170
int readValue = DHT.read11(DHT11_PIN); // check the data coming from the DHT pin
172
171
humidity = DHT.humidity; // assign the humidity variable to data from sensor
173
-
delay (1000);
174
172
}
175
173
176
174
```
177
175
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.
179
179
180
-

180
+

181
181
182
182
## Communicating with Node-RED
183
183
184
184
Use the steps below to use Node-RED with the Arduino IoT Cloud:
185
185
186
-

186
+

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
187
199
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.
195
201
196
-

202
+

197
203
198
-

204
+

199
205
200
206
### Creating a Flow
201
207
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.
203
209
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.
205
211
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:
207
213
208
214
```js
209
215
let data =msg.payload;
@@ -225,26 +231,26 @@ if(data<60 && trigger){
225
231
}
226
232
```
227
233
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.
229
235
230
-

236
+

231
237
232
238
### Sending Email Notifications
233
239
234
240
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:
235
241
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"**.
241
247
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.
243
249
244
250

245
251
246
252
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.
247
253
248
254
## Further Applications
249
255
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