How to use IoT in Bluemix

How to use IoT in
Bluemix
LEONARD WALLETZKÝ
Introducing IoT in
BlueMIx

http://discover-iot.eu-gb.mybluemix.net/
Smartphone as sensor

Enter your Device ID and email

Accept the conditions

Click Next
How to use your device data in
your app?

Example – how to use simulated GPS device in the BlueMix

First we need to create a new IoT application, simulating sensor

In your dashboard, click to Create App

Select IoT Platform Starter

Name your app and click Create

Wait for Node Red ready
Simulated sensor

Select all nodes and delete

In IS open the file IoTsensor.txt and select
Import > Clipboard

Copy the content of the file into the text
frame

Place the new flow

Leave Node Red open and return to
Dashboard
Connection to API

Your application cannot communicate with sensor directly

You need to create interface – to be able to communicate with
more devices and prevent the attacks

In the list of services find IoT Platform for your device
Watson IOT Board

Remember your organization ID

Click on Devices

You need to create new device to be connected with your sensor

Click Add Device

Click on Create device type

Click on Create device type again

Enter name for the type – like Simulated_device and click Next

Leave template and metadata blank by clicking Next and click
Create
Create your device
connection

Select your type and click Next

Add the name for the device

Provide some simple token (12345678)

Click Add

After viewing the summary, you will
see your device
Generating API connections

Click on Apps

Delete API Key

Create new API Key

Copy and save Authentication Token!!!!

Click Generate
Connecting the device

Go back to your Node Red editor

DoubleClick on Publish to IoT node

Click to Server

To Server write:
<your organization>.messaging.internetofthings.ibmcloud.com

To Client ID:
d:<your organization>:<device type>:<device name>
Connecting the device

To Security part

To username:
use-token-auth

To password copy your generated token for the device

Press Update

Press Done

Press Deploy
Connecting the device

Go to Watson IoT platform dashboard

If you were successfull, you should see something like this
Creating the application

Create New App

From IS download phpmqtt library and put into your repository

From IS download IoT_example.php

Modify source code in IoT_example.php using your credentials

Start your application
More sources

How to make a sensor from your mobile phone
https://www.ibm.com/developerworks/opensource/library/iot-phpapp-iot-foundation-bluemix/index.html

To debug MQTT connections
http://mqtt-helper.mybluemix.net/

IoT tutorials
https://developer.ibm.com/recipes/tutorials/category/internet-ofthings-iot/
API to services

How can I see all services
connected to my app?

How can I get their credentials?

In Dashboard, click on App name
and then to Connections

Under each you can click to View
Credentials
Variable VCAP_SERVICES

All credentials are available via $ENV[„VCAP_SERVICES“]

For of its usage see db.php in our previous MySQL example

To see all credentials in command line use
cf env <name of your app>
Get familiar with API

Each service has detailed documentation of API
API Explorer

https://watson-api-explorer.mybluemix.net/
Language Translator
Translator - example

Click on GET
/v2/translate

Fill the form

And click Try it out!
To use Translator

Folloow the tutorial

https://www.ibm.com/developerworks/library/cc-watson-languagetranslation-aps-bluemix-trs/index.html

Or for php

http://blog.softlayer.com/watson-bluemix-language-translation