a step by step guide to develop temperature sensor io t application using ibm bluemix

55
www.azilen.com 02 A Step by Step Guide to Develop Temperature Sensor IoT Application Using IBM Bluemix

Upload: azilen-technologies-pvt-ltd

Post on 21-Jan-2018

201 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

A Step by Step Guide to Develop Temperature Sensor IoT Application Using IBM Bluemix

Page 2: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

What is IBM Blue-mix?

IMB Bluemix provides readily available environment for applications, infrastructure and services. Integrated with IBMWatson, it offers possibilities of cognitive services as well.We have developed an IoT application using IBM Bluemix, Raspberry PI – 3 and a virtual device that sends email notifications to user as and when there is a fluctuation in temperature.

Process flow: Virtual device will be placed at desired location >> If temperature at that location rise more than 21 degree centigrade, the user will simply get notification about it by email.

This blog is a step by step guide to develop temperature sensor IoT application and it includes:• Virtual device & Raspberry PI integration with IBM Blue-mix• Register Virtual Device and analyze the device data• Register Raspberry PI – 3 and analyze the device data• Linking Raspberry PI with our device through IBM Bluemix

Page 3: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com

Virtual device & Raspberry PI integration

with IBM Blue-mix

Page 4: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

You register Raspberry PI – 3 with Blue Mix. Up to scertain extent the process of registering and adding Raspberry PI – 3 will be quite similar to registering and adding virtual device that you have gone through in first phase of this blog.

Page 5: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 01

Step by Step Virtual device & Raspberry PI integration with IBM Blue-mix

1. Open www.bluemix.net

2. Create free trail account in blue-mix

3. Once the registration & email verification process gets completed, you

can login in to blue-mix.

Page 6: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

4. While you log in for the first time, you need to complete several formalities such as

• Provide your organization name / create your organization• Create Space (The spac where you can manage your applications and services)

Page 7: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 04

5. Then, click on ‘Catalog’ and it will display the list of services provided by IBM Blue-mix.

Page 8: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 05

6. You need to follow the path: Services >> Internet of things >> Internet of Things Platform.

7. Write down the name of service you are trying to create in the field Service Name and click the Create button

Page 9: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 06

8. Once your service has been created, you will be able to see ‘Launch’ button that will navigate you to IoT service dashboard

9. From this IoT service dashboard you can manage your devices, schema, charts etc. We will start with registering our virtual devices and analyzing the data.

Page 10: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com

Register Virtual Device and analyze the device data

Page 11: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 06

You register Raspberry PI – 3 with Blue Mix. Up to ascertain extent the process of registering and adding Raspberry PI – 3 will be quite similar to registering and adding virtual device that you have gone through in first phase of this blog.

Page 12: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 01

1. From the dashboard, go to Device and click on Add Device. You need to choose your device type there from a dropdown list. If you have not defined any device, click on Create Device Type button to define it.

Page 13: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

2. Once you have defined device type through Create Device Type, you will able to see device type in the drop-down.

Page 14: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 03

3. Then you need to provide Device ID, which can be any friendly name.

Page 15: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 04

4. Once the device is created, IBM will provide your device credentials. Please save it in safer place.

Page 16: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 05

5. Once your device has been added, you’ll see your device in listing panel.

Page 17: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 06

6. Your device status will be displayed as disconnected. To connect your

virtual device to IoT platform, use the url below, which is the IBM virtual

simulator.

http://watson-iot-sensor-simulator.mybluemix.net/?cm_sp=dw-bluemix-_-

recipes-_-devcenter

Page 18: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 07

7. You need to key in the device credentials here which are provided to you by IBM.

Page 19: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 08

For example:

Organization ID : rri9kn

Device Type : virtualdevice

Device ID : virtualdevice123

Authentication Method : token

Authentication Token : eOTP?4zGr-LYo&Rmn8

Page 20: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 09

8. Now IoT sensor simulator will try to connect with IBM blue-mix

(You can see that in device listing panel your device status has been updated as Connected with IBM blue-mix in device listing panel.)

Page 21: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 10

9. Click on device to view json data received by IBM blue-mix from “Recent Events” tab.

Page 22: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 11

10. Now go to Boards >> Create one board.

Page 23: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 12

11. Click on add chart.

Page 24: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 13

12. Click on Donut chart >> Select your device and add data set.

Page 25: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 14

13. Now you’ll able to see donut chart on your dashboard.

Page 26: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 15

14. Now, if you change the temperature in simulator, you will be able to see

the changes in charts as well.

15. If there is requirement to perform any actions based on data analysis of

collected data, there is flexibility to define relevant notifications settings in

Blue-mix. It means, we can get notifications by mail or by phone in

accordance with settings.

16. For notifications settings, you need to create schema first. For that

follow the path: Device >> Manage Schema Tab >> Create Schema

Page 27: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 16

Select details for device and move to next

Page 28: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 17

17. Now, you need to add properties to schema, hence, click on Add property. Please note that, you need to design our schema based on json we are getting from the device.

For example : {"d":{"name":"virtualdevice123","temperature":19,"humidity":57,"objectTemp":23}}

Page 29: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 18

18. First we will add “d” as parent property based on our json, and then we will add child properties.

19. Click on “Finish” to add schema.

Page 30: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 19

20. Now go to Rules >> Create Cloud Rule

Page 31: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 20

21. Click on “Next” to create cloud rule.

Page 32: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 21

22. Click on Edit condition to set cloud condition. Then select Temperature property from drop-down and provide static value as 21.

Page 33: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 22

23. Follow the path: Edit action >> Add action

24. Click on Activate to add & activate the rule.25. Now go to simulator and change device temperature to 21 to get email alert.

Page 34: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 23

26. Go to Boards >> Rule-Centric Analytics

Alert details will be displayed here in different boards

Page 35: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com

Register Raspberry PI - 3 and analyze the

device data

Page 36: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

1. Dashboard >> Device >> Add Device >> Create Device Type >> IBM will share

credentials for the Raspberry PI – 3 device >> Raspberry PI – 3 device will be

displayed in device listing with disconnected status >> Connect the

Raspberry PI – 3 device

2. In the list you can see our Raspberry PI device status is disconnected.

Page 37: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 03

3. Setting up Watson IoT on Raspberry PI

To setup Watson IoT platform, you need to download Watson IoT platform

installer from IBM’s Github. Run below command in Raspberry PI terminal

to download Watson IoT platform installer.

curl -LO

https://github.com/ibm-messaging/iot-

raspberrypi/releases/download/1.0.2.1/iot_1.0-2_armhf.deb

4. Once installer has been downloaded, run below command to install it.

sudo dpkg -i iot_1.0-2_armhf.deb

Page 38: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 03

5. Run below command to verify iot service status.

service iot status

6. If you can see message as shown below, you’re good to go.

iot.service - LSB: IoT service

Loaded: loaded (/etc/init.d/iot)

Active: active (running) since Fri 2017-05-26 21:42:09 IST; 51s ago

CGroup: /system.slice/iot.service

└─2730 /opt/iot/iot /dev/null

Page 39: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com

Linking Raspberry PI with our device through

IBM Bluemix

Page 40: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 01

1. To link the Raspberry PI with your virtual device in IBM Bluemix, first of

all you need to IoT service running in Raspberry pi. Run the below

command to stop it.

sudo service iot stop

2. Type the below command to device configuration file.

sudo nano /etc/iotsample-raspberrypi/device.cfg

Page 41: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

3. Copy and paste the device information to device.cfg file. You have received this

information while getting registered with IBM Bluemix.

#Device configuration file

org = p29vg0

type = RaspberryPI3

id = PiBrain

auth-method = token

auth-token = 3*)DPXWa+NFQl&Zgjs

#End of Configuration file

Page 42: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 02

4. The newer version of Raspberry PI has already come up with Node-RED and

Watson IoT. If you are using the newer version, run following command to update

Raspberry PI

sudo apt-get update

sudo apt-get dist-upgrade

5. Type below command to start Node-RED.

node-red

Page 43: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 03

6. Once your node-red server has started, you can see it from below url.

Page 44: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 04

7. IBM offers set of nodes that we can use potentially. Open below url and

copy JSON from it.

https://raw.githubusercontent.com/ibm-messaging/iot-device-

samples/master/node-red/device-sample/quickstart.json

Page 45: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 05

8. In Node-RED editor go to Menu >> Import >> Clipboard

Page 46: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 06

9. Paste JSON value to import nodes

Page 47: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 07

10. Double click on Event node

Page 48: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 08

11. A pop-up will appear, select “Registered” radio button and click on edit button.

Page 49: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 09

12. Add the data which have configured in our device.cfg file.

Page 50: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 10

13. Click on “Add” button to save the data which help to connect toIBM Bluemix.14. Click on “Deploy” button to connect your device with IBM.

Page 51: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 11

15. Now your device is connected.

Page 52: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 12

You can conform the connection status through device listing

Page 53: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 12

Now as your Raspberry PI is connected to IBM bluemix, you can create your charts, schemas and rules as we have created for the virtual device.

In fact, if cleverly utilized, IBM Bluemix can be the enabler of more than 150 different services being offered by IBM, other service and software providers and several communities. Due to its ‘Composable Service Approach’ and support to virtual machine deployments, there are unlimited possibilities to explore its potential for development of innovative IoT products. As a programmer, I see it as a next big thing.

Page 54: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 12

Original Source : http://www.azilen.com/blog/step-by-step-guide-to-develop-iot-application-using-ibm-bluemix/

Originally Published @ www.azilen.com

Page 55: A step by step guide to develop temperature sensor io t application using ibm bluemix

www.azilen.com 12

Thanks Youwww.azilen.com

Let us know if you have any Question!