17
Temperature/Humidity Sensor with Node-RED and Cloudant Hands-On Lab

Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

  • Upload
    others

  • View
    25

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature/Humidity Sensor with Node-RED and CloudantHands-On Lab

Page 2: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Table of ContentsStep 1: Running the IoT Starter Boilerplate ...............................................................3

Step 2: Connecting a Simulated Temperature Sensor.................................................6

Step 3: Cloudant and Other Fun Nodes.....................................................................11

Copyright IBM Corporation 2013-2014. All rights reserved. | 2

Page 3: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Step 1: Running the IoT Starter Boilerplate

1. We will begin by logging in to IBM Bluemix and selecting the Internet of Things Foundation Starter Boilerplate

Figure 1 The IBM Internet of Things Foundationg Starter on Bluemix

2. The Boilerplate gives us a Node.js runtime and a Cloduant database that will connect to our application. We will now provide our app with a unique name in the dialog pane on the right.

Copyright IBM Corporation 2013-2014. All rights reserved. | 3

Page 4: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Figure 2 Create the app

3. We then click on Create, launching the app in Bluemix.

4. To see how our app is running, we select Overview in the navigation pane on the left. At this time, the app is still staging. .

Figure 3 App staging

5. When the app health changes to a check mark with the text “Your app is running”, we click on the Route to open our application in the browser.

Copyright IBM Corporation 2013-2014. All rights reserved. | 4

Page 5: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Figure 4 Mobile Boilerplate is now running

6. On the Node-RED landing page we click Go to your Node-RED flow editor.

Figure 5 Node-RED

7. The following nodes should be visible in the new tab and the URL has the name of the app.

Figure 6 Default nodes upon app creation

Copyright IBM Corporation 2013-2014. All rights reserved. | 5

Page 6: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Step 2: Connecting a Simulated Temperature Sensor8. In a new tab, type the address:

ibm.biz/iotsensor

9. We now copy the 12 character alpha-numeric address on the top right-hand side of the page.

Figure 7 The simulated sensor

Copyright IBM Corporation 2013-2014. All rights reserved. | 6

Page 7: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

10. Now that we have the sensor's unique identifier, we can navigate back to our Node-RED flow editor. From there, double-clicking the IBM IoT App In node opens a dialog box where we can paste the address from the previous step into the Device Id field (no colons). Once that is done, we click Ok to close the dialog.

Figure 8 Edit ibmiot in node dialog

11. It would be nice to see what sort of information our sensor is sending out, so now we click on the green device data node to open it. We change the options so that Output will send data to the debug tab and console.

Figure 9 Edit debug node

|

Copyright IBM Corporation 2013-2014. All rights reserved. | 7

Page 8: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

12. We now open the temp node and change the Function to fetch the temperature and humidity data from the payload and output two payloads.

Figure 10 Edit function node

13. The node following the temp node, temp thresh, sets a threshold for reporting temperatures that are too high or too low. We'll need an identical node set for the humidity output. So we'll select temp thresh, safe, and danger and copy and paste them toanother spot on the sheet.

Copyright IBM Corporation 2013-2014. All rights reserved. | 8

Page 9: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Figure 11 Copy node set for humidity

14. At this point we need to connect our new humidity nodes to the temp function and changethe values for safe and danger to fit the new input. To link the nodes, we click on the square on the bottom of the temp function and drag the line over to the input side of the new temp thresh. Then we open temp thresh to rename it to humidity thresh and change the values to 80.

Figure 12 Connecting and updating the humidity

15. Now we need to update the safe and danger thresholds to reflect the correct text.

Copyright IBM Corporation 2013-2014. All rights reserved. | 9

Page 10: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Figure 13 Updated safe template node

Figure 14 Updated danger template node

16. Once the outputs are updated, we drag the output connections for safe and dage to the input for the cpu status node.

Figure 15 Finish connecting the flow

17. As it is currently written, the flow will output the entire payload from the sensor, but we really just want to see the temperature and humidity output from our safe and danger nodes. We open the cpu status debug node and apply the following changes to get a cleanoutput.

Copyright IBM Corporation 2013-2014. All rights reserved. | 10

Page 11: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Figure 16 Update the cpu status debug node

18. Now the app is ready or at least we're pretty sure it is. Clicking Deploy at the top of the flow window will kick off the app to redeploy with our new changes. Several minutes of nail biting anticipation later and we see data in our debug tab!

Figure 17 Debug tab output

19. Tired of seeing all the data? We can just toggle the CPU status and device data nodes by clicking on the handle attached to the right side of the node to deactivate them.

Copyright IBM Corporation 2013-2014. All rights reserved. | 11

Page 12: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Step 3: Cloudant and Other Fun Nodes

Getting the temperature sensor set up was pretty easy, but the next part is going to be a cake walkin comparison. Now we want to use that Cloudant database connected to our app in Bluemix andtweet about critical temperatures if we have a Twitter.

1. To add Cloudant we scroll through the node toolbox on the left until we get to the storage section. We want to strictly output data from our device to the Cloudant database, so we'll need the node with only an output. We drag the node over to our flow and set it somewhere.

Figure 18 Cloudant output node

2. Since we want the raw data to be stored, we need to click on the grey box on the output side of the IBM IoT App In, it will turn orange on hover, and drag the line over to the input on the cloudant node.

Figure 19 Cloudant node in Node-RED flow

3. Opening up the dialog for the Cloudant db we see that there is no service assigned to this node. We now select the Cloudant service bound to our application as our Service. Next we give the database a name and check the box to only store the msg.payload object.

Copyright IBM Corporation 2013-2014. All rights reserved. | 12

Page 13: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

Figure 20 Edit cloudant out node dialog

4. We redeploy to commit the changes and navigate over to Bluemix to check if data is coming to our database. To view the database, we select the Cloudant NoSQL DB service from our application's Overview and select then LAUNCH.

Figure 21 Launch button for Cloudant

Copyright IBM Corporation 2013-2014. All rights reserved. | 13

Page 14: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

5. We now select our database, iot_temp in this case.

Figure 22 Databases view

6. In the right pane there are several documents that look like a bunch of senseless data and numbers. Clicking on the pencil icon in the upper right corner reveals a little more about these json payloads.

Figure 23 Edit icon for document

Copyright IBM Corporation 2013-2014. All rights reserved. | 14

Page 15: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

7. The data contains the temperature data our Node-RED flow is handling as well as some humidity data.

Figure 24 Contents of the document

8. Having our data readily available and archived is interesting, but maybe we want to have real-time notifications in a more easily accessible output. Scrolling up and down the node toolbox we can see dozens and dozens of nodes linking to services such as Watson and Twilio. For ease we are going to use Twitter, but if you don't have Twitter you can work with any of the other “social” nodes. We drag the twitter output node over to our flow to get started.

Figure 25 Connected Twitter node

Copyright IBM Corporation 2013-2014. All rights reserved. | 15

Page 16: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

9. In this case we only want to tweet when the temperature is out of the safe limits and we'll add a delay node to keep from spamming our Twitter timeline. To do this we drag the delay node over from the function section of the toolbar. The node is going to receive input from the danger node and output to the Tweet node. We'll set a delay of one minuteon messages.

Figure 26 Add a delay node

10.Now we open the dialog box for Tweet and select the pencil icon to the right of the Twitter field. Node-RED will now walk us through authenticating with Twitter.

Figure 27 Edit twitter out node dialog

Copyright IBM Corporation 2013-2014. All rights reserved. | 16

Page 17: Temperature/Humidity Sensor with Node-RED and Cloudantfiles.meetup.com/15337342/Lab IoT Temperature and... · Temperature Sensor with Node-RED and Cloudant 7. The data contains the

Temperature Sensor with Node-RED and Cloudant

11. We'll log in using our Twitter credentials to authorize Node-RED to access our Twitter account.

Figure 28 Authorize Node RED to Twitter

12.Upon successful authentication we should see the following message. Back in Node-RED we click Add to add the new user and Ok to close out the dialog.

Figure 29 Twitter connect success

13.We now redeploy the application to pick up our changes and navigate back over to your IoT sensor. We can use the up and down arrows to push the sensor into a critical temperature that will kick off a tweet.

This concludes this lab. Want more? Connect up a Twilio account to text notifications to your cell.

Copyright IBM Corporation 2013-2014. All rights reserved. | 17