AdSense

Showing posts with label IoT PLATFORMS. Show all posts
Showing posts with label IoT PLATFORMS. Show all posts

Tuesday, August 15, 2017

IBM Watson IoT (2): connecting a Raspberry Pi as a Registered Device with Node-RED


IBM WATSON IoT (2): CONNECTING A RASPBERRY PI AS A REGISTERED DEVICE WITH NODE-RED


- Layout for this exercise:





* To complete this exercise it is assumed the previous existence of an account on the IBM Bluemix platform


* This exercise is based in the previous exercise flow:


https://dgmsp.blogspot.com/2017/08/ibm-watson-iot-1-connecting-raspberry.html




1 - Creating an IBM Watson IoT Platform organization


- In this exercise, and unlike the previous one with Quickstart, the Raspberry Pi connects to the IoT platform providing credentials and registration of the device.

- Creating a private organization space that requires authentication and registration for all devices and applications to use in that organization. - Each organization is defined by a 6-character ID, as we will see in short.

- The first step consists of the login process into the IBM Bluemix account. Let's notice that IBM Watson IoT is a service provided by the IBM Bluemix cloud platform:







- Going to the Internet of Things Platform:






- Creating an IBM Watson IoT  service:





- Clicking Launch:






- Entering the IBM Watson organization space:






2 - Creating a Device Type 


- Devices connected to the IBM Watson IoT Platform are associated with a Device Type, what are intended to be groups of devices sharing common characteristics. 


- Going to Devices:





- Browse and Create Type:









- Creating a "device type" (be careful not confusing with "gateway type"):





- Entering Name and Description:





- Defining the template is optional. In this case Manufacturer and Model are defined:







- Metadata is optional:






3 - Adding and registering a device to the the IBM Watson IoT Platform


- Choosing the Device Type:








- The Security step allows to enter an optional token, or otherwise it can be auto generated.  


- In this case we choose an authentication token  auto generated by the service, what will be displayed and the end of the registration process:









- Adding the device RBP_1:





- After adding the device the auto generated Device Credentials are displayed. It is important to write down all this information because in case of loss there is no possible recovery:





- Clicking the X, the Security step is ended:






4 - Generating API Keys


- Some API Keys must be generated to enable the connectivity. Going to Apps, clicking Generate API Key:









- API Keys are generated to allow the connection:



















5 - Connecting the Raspberry Pi as a registered Device


- At this point a device RBP_1 has been created, added and registered to the IBM Watson IoT platform, and also some API Keys for enabling the connectivity have been generated.


- To connect the Raspberry Pi device (in this case as Registeredaccording to the previous exercise flow:


https://dgmsp.blogspot.com/2017/08/ibm-watson-iot-1-connecting-raspberry.html


- The Watson IoT node must be edited as Registered:





- Clicking the Credentials icon:     





- Entering the credentials (Organization ID, Device Type, Device ID, Authentication Token) obtained at point 2 of this exercise:







- Deploying:





- Eventually the connection is achieved:






6 - Receiving data from the Raspberry Pi device at the Watson IoT platform


- Now the RBP_1 is connected:






- The Connection Log shows the sucssessfull connection:





- Events are generated every 5 seconds, displaying the last received CPU temperature from the RBP_1 device:















Monday, August 14, 2017

IBM Watson IoT (1): connecting a Raspberry Pi as a Device with Node-RED Quickstart


IBM WATSON IoT (1): CONNECTING A RASPBERRY PI AS A DEVICE WITH NODE-RED QUICKSTART


- Layout for this exercise:






1 - Introduction

The IBM Watson IoT Platform is a fully managed cloud-hosted service that makes it simple to derive value from Internet of Things (IoT) devices.

- It provides solutions for device registration, connectivity, control, rapid visualization and storage of data derived from the IoT.

- When combined with the IBM Bluemix environment and access to secure Watson APIs the platform allows to integrate and analyze predictive, cognitive, and contextual analytics for stronger decision-making.

https://www.ibm.com/internet-of-things/platform/watson-iot-platform/

Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.

- It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.

https://nodered.org/

- The goal of this exercise is to connect a Raspberry Pi device to the IBM Watson IoT Platform using the Node-RED programming tool and the Quickstart service.

- The Raspberry Pi device will send messages about its CPU temperature every 5 seconds and the IBM Watson IoT platform receives and handles the information displaying the messages at a website.

- Quickstart is a sandbox service provided by Node-RED that runs 24/7 and it's freely accesible. However, it does not provide any security that data is coming from a trusted source, so anybody using the API can send data into the service. That is the reason because in the next exercise we will see how to use Node-RED with a Registered device.


2 - Installing Node-RED nodes at the Raspberry Pi

- Installing a pair of Node-RED nodes for connecting the Raspberry Pi as a Device (also as a Gateway) to the IBM Watson Internet of Things Platform:





- Installing a pair of Node-RED nodes for connecting to both the Quickstart and Registered flows in IBM Watson IoT Platform:




- Starting Node-RED:





- Browsing to localhost IP at port 1880 lets us access the Node-RED editor:






 - Checking that the installation of the two nodes has been successful:














3 - Creating a Node-RED flow

- This flow measures the CPU temperature from the Raspberry Pi and sends it to the IBM Watson IoT platform:




- Let's check the configuration of the nodes.

- The first node is the injection node, what injects messages every 5 seconds from the start:






- The exec node runs the function vcgencmed with the option measure_temp to measure the CPU temperature of the Raspberry Pi device:











- The function node formats the msg.payload:







- The debug node outputs the msg.payload to the Debug tab:






- Finally, the Watson IoT node allow to connect the Raspberry Pi device sending events to the IoT platform. In this case, the Quickstart mode is selected:





- Exporting the flow to the clipboard:


[{"id":"aa1ea7a8.5cac6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"474020f5.41c758","type":"inject","z":"aa1ea7a8.5cac6","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"x":216,"y":212,"wires":[["3377c7a3.ca8418"]]},{"id":"3377c7a3.ca8418","type":"exec","z":"aa1ea7a8.5cac6","command":"vcgencmd","addpay":false,"append":"measure_temp","useSpawn":"","timer":"","oldrc":false,"name":"RaspberryPi_CPU_temperature","x":410,"y":305.5,"wires":[["69a8e49e.1adb7c","21d130ef.8669c8"],[],[]]},{"id":"69a8e49e.1adb7c","type":"debug","z":"aa1ea7a8.5cac6","name":"debug","active":true,"console":"false","complete":"payload","x":845,"y":117.5,"wires":[]},{"id":"21d130ef.8669c8","type":"function","z":"aa1ea7a8.5cac6","name":"msg.payload","func":"msg.payload = {\"d\":{\"temp\":msg.payload.replace(\"temp=\",\"\").replace(\"'C\\n\",\"\")}};\nreturn msg;","outputs":1,"noerr":0,"x":675,"y":313,"wires":[["69a8e49e.1adb7c","a67a1c60.187598"]]},{"id":"a67a1c60.187598","type":"wiotp out","z":"aa1ea7a8.5cac6","authType":"d","qs":"true","qsDeviceId":"a67a1c60.187598","deviceKey":"","deviceType":"","deviceId":"","event":"event","format":"json","qos":"","name":"Watson IoT","x":895,"y":409.5,"wires":[]}]



4 - Deploying the NODE-Red flow in the Quickstart mode

- Clicking the Deploy tab:










- The Debug tab displays the CPU temperature every 5 seconds:



   
- Going to the Watson IoT node the Quickstart mode triggers the IBM Watson IoT Plaftorm webpage where the series of events gathered every 5 seconds is displayed: