You will learn
- How to add a device type, message type and device to the IoT Services of SAP HANA Cloud Platform (HCP)
The idea behind this tutorial is quickly show how to add a device and capture sensor data in the clous.
This tutorial will take you through the steps at a rapid pace, if you’d like more details please contact one of our support staff.
If you have an interest in the world of IoT this first tutorial will help you get started by giving you the basics necessary for connecting any device or sensor that you decide to use.
In this tutorial, we have decided to use a Tessel 2 device.
However, you could just as easily use a Raspberry Pi, Arduino, or any number of other
micro-controller devices available on the market today.
In the left-hand navigation bar, select Services, then click on the Internet of Things (IoT) tile from the main panel.
If the Internet of Things (IoT) is not enabled, then click on Enable.
Once the service is enabled click the Go to Service link and a new browser tab will open.
With Internet of Things (IoT) enabled, you can begin the steps necessary to connect your device and enable message communication.
The first step will be to configure and deploy the Message Management Service (MMS).
Click on the Deploy Message Management Service tile.
The form should already be filled with your information like your account ID (p-number or s-number if you are SAP’s customer or partner, or i-/d-number if you are SAP employee) with the world “trial” (no space between the p-number and trial), your user name etc.
Enter your SAP HANA Cloud Platform password, then click on Deploy.
It will deploy
iotmms Java application for you in the background.
iotmms Java application is successfully deployed (created), you will need to add data binding and the required authorization for users who should use it.
The data binding allow the data you are sending from the device to the system to be stored for later access and the authorization will grant the access the data to your user.
Return to the SAP HANA Cloud Platform Cockpit, and in the left navigation bar select Applications > Java Applications.
You will see the
iotmms application you just deployed.
Click on the
iotmms link to display the IoT MMS - Overview page.
On the left navigation bar, select Configuration > Data Source Bindings.
Check that the data binding is in place which should look like something similar to pictures below.
In case your
iotmms application is missing the data binding, you will need to apply additional steps in order to manually create a new database, and then add the data source binding.
Otherwise proceed to the next step of assigning a role with required authorizations to your user.
On the left navigation bar, select Roles.
Select the IoT-MMS-User (click the empty cell next to the Name to select the row if it is not highlighted in blue).
Then under Individual Users, click Assign and enter your HCP user ID (e.g. your p-number without the word “trial” on the end).
Once your user is assigned to the role, stop then start
Click on Overview in the left navigation bar.
Click Stop, then when the process completes, you can click on Start.
From here you will need to go back to the IoT Service Cockpit from where you deployed the Message Management Service .
Now that your version is up to date you will need to go to Message Type and create a new message type.
The “Message Type” defines the table to hold your data that you are collecting.
Pay close attention to your field names, both in spelling, case sensitive and type as you will not be able to alter these after creation.
And the following fields:
Please note down the created Message Type id displayed here as you will be using it later.
Once the Message Type is created, you will need to create a new Device Type and assign the Message Type to it.
Now that you have your Message Type and Device Type created, you will need to add your Device.
Be sure to save this Device token that is generated as you will need it later.
If you lose it you will need to generate a new one.
Please note down the created Device id displayed here as you will be using it later.
If you are with us at TechEd in the
AppSpace, your device is the physical Tessel device next to you.
If you are with us at TechEd in the
AppSpace, the file is already available in the following directory:
C:\teched2016\te16 - Original.js. Please make a copy of the file for your own use
C:\teched2016\te16.js and the convenience of the next attendee.
If you are doing this on your own machine, you can download the file
te16_js.txt, and rename it to
te16.js on your machine.
Modifying the code provided in the file now called
te16.js, you will need to add in your Message Type id, Device id, etc.
The lines in particular you will need to modify are the following:
var hostIoT = 'iotmms<HCP Account User ID>trial.hanatrial.ondemand.com'; var authStrIoT = 'Bearer <generated token from step 8>'; var deviceId = '<generated device id from step 8>'; var messageTypeID = '<generated message type id from step 6>';
You will modify:
hostIoT line to add your own HCP Account User ID which starts with either an
S or a
authStrIoT line contains the token you received in the pop-up window after creating your device
deviceId is the ID of the device you created, not to be confused with the
messageTypeID is the ID of the message type you created
Once you have saved your file, you will deploy and execute it from the command line.
Open a “command” window, and run the following two commands:
t2 run te16.js
If you now go back to the IoT Services Cockpit in HCP you can see those newly created entries.
Click on Send and view messages, or perform other actions.
Click on Display stored messages.
The table with your data will match the Message Type id generated earlier.