The Easiest Way to Stream your iPhone’s Sensor Data to HANA Cloud Platform

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

As you may already know, SAP’s HANA Cloud Platform (HCP) allows anyone to go from sensor to visualization with the Internet of Things (IoT) service. HANA Cloud Platform’s IoT service provides the ability to quickly develop, deploy, and manage real-time IoT and machine-to-machine (M2M) and remote data sync applications. The possibilities are nearly endless; you can setup and manage connected remote devices, get real-time predictive analysis to improve intelligence and decision-making at the edge of the network, and optimize business processes at the core of your business.

That sounds great on paper, but how can we see the power and agility of HANA Cloud Platform without the need to build and setup extensive demos for the Internet of Things? Not everyone has access to the hardware needed to build out the desired IoT demo we all dream about (and see at SAP’s trade shows). However most of us have a smartphone. In fact, you may be reading this on that very smartphone. Our smartphones are packed with almost a dozen different sensors which we can leverage to see the power and agility of HANA Cloud Platform.

There’s a very good chance that your smartphone is an iOS device like an iPhone. With this in mind, I developed an iOS application that taps into your iOS device’s sensors (like the gyroscope, accelerometer, barometer, GPS, and audio), and neatly packages it into JSON format, then seamlessly feeds it to the IoT Service within HANA Cloud Platform. The app is called SensorPhone. I will show you how you can use your iPhone and the SensorPhone app with your own HANA Cloud Platform account.

I’ve made this extremely simple for anyone to setup and use. This blog post is broken down into three main steps.

Step 1: Internet of Things Service Setup.

Step 2: Adding your iOS Device in the Internet of Things Cockpit, and finally.

Step 3: Setup the SensorPhone app to send data to HANA Cloud Platform.

Before we get started, here is what you need:

  • The iOS SensorPhone client was updated to version 1.3.2, in order to support an improved data model. if you setup your IoT Services within HANA Cloud Platform before April 10, 2016, then please see Step 2.2 to create a new Message Type. If you do not create a new Message Type, you will be unable to continue using SensorPhone (v1.3.2).
  • iPhone with the SensorPhone app (Requires iOS 7.0 or later, iPhone 5 and newer models. However, SensorPhone is compatible with iPad and iPod touch, 3.5″ screen+)
  • HANA Cloud Platform account (If you don’t have one, you can sign up for a trial account for free here)

Step 1: Internet of Things Service Setup
This is a very quick and simple walkthrough to setup your Internet of Things Service within your HANA Cloud Platform account, if you haven’t already done so. If you have, you may skip to Step 2: Adding your iOS Device in the Internet of Things Cockpit.

The IoT services in HCP is comprised of two main areas:

  1. Remote Device Management Service (RDMS) – this is used to onboard new devices, like our iPhone.
  2. Message Management Service (MMS) – this is used to manage messages between device, cloud platform and business applications. This is also where we will see the sensor data stored in HANA Cloud Platform.

Enabling the IoT Service for your HANA Cloud Platform Account

This will give you access to the Internet of Things Cockpit which leads you to the Remote Device Management Service.

First go to your HANA Cloud Platform Account and select Services from the side menu.
Note: Make sure you are at the account level at the top. Then on you may see the Services in the left menu.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Scroll down until you see, Internet of Things Services and then click “Enable”.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

You now have enabled the IoT Services for your HCP account. The “IoT-User” role has now been assigned to you. Next we will install the Message Management Service (MMS).

Deploying the Message Management Service (MMS)

As mentioned above, this is used to manage messages between your iPhone, the platform, and business applications. This is also where we will see the sensor data stored in HANA Cloud Platform.

From your HANA Cloud Platform Cockpit, lets go back to the Internet of Things Service. We will enter the IoT Service Cockpit by clicking “Go to Service”.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform
You will now see “Deploy Message Management Service” on the bottom left tile. Click on that.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Enter your account ID, username, and password.
Note: Your account ID is likely your (i/d/p) number or email address with the word “trial” on the end. Your User Name is likely to be your (i/d/p) number or email address itself.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

We now have deployed the IoT Services application and the Message Management Service (MMS). Lastly, we need to add the IoT-MMS-User Role to our UserID.

Adding the IoT-MMS-User Role to your User ID

From the HANA Cloud Platform Cockpit, select Java Applications and click on iotmms. This will take us to the Java Application Overview screen.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

On the left hand side, select Roles.
We now see the predefined IoT-MMs-User Role at the top.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Verify that the IoT-MMS-Role is selected. Then below, click on “Assign”

Add in your User ID and select “Assign”.
Note: Your User ID is not your account name. The user ID doesn’t not include the word “trial” on the end.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Now we have added the Internet of Things Service, installed the MMS, and assigned our user to the IoT-MMS-User Role. Next we will add our iOS Device!

Step 2: Adding your iOS Device in the Internet of Things Cockpit

From your HANA Cloud Platform Cockpit, lets go back to the Internet of Things Service. We will enter the IoT Service Cockpit by clicking “Go to Service”. We are launching the Internet of Things Cockpit, within HANA Cloud Platform. The Internet of Things Services cockpit is the main interface for users to interact with the Remote Device Management Service (RDMS). It can be used to register new Devices (like our iOS device), to define the schema of messages (Device Types and Message Types) they can send and/or receive, as well as to establish the necessary trust relationship needed by devices to interact with Message Management Service (MMS).

As mentioned above, in order for our iOS device to successfully communicate with HANA Cloud Platform, there are a few prerequisites. The internet of Things Service requires a specific syntax used to register new devices in the device registry. We will need to create 3 entities:

  1. Device Type: A device type specifies a group of devices that share the same specification. In the IoT services, this specification is interpreted as the capability of sending, receiving and processing certain types of messages from our iOS Device.
  2. Message Type: A message type defines the type of data contained in a message that is sent or received by a device. Message types are specified for device types. For example, we will need to create a Message Type with the following attributes: sensor, value, and timestamp.
  3. Device: A device is a physical object that can be registered with IoT services. After successful registration it is able to send or receive messages. This is of course our iOS device itself.

So lets begin!

2.1: Creating our Device Type

From your HANA Cloud Platform Cockpit, lets go back to the Internet of Things Service. We will enter the IoT Service Cockpit by clicking “Go to Service”.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Click on the “Device Types” tile. Then click on the Plus (+) symbol at the bottom to add a new device type.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Name your device type (iOS Device) and press “Create”.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

2.2: Creating our Message Type

Now we will create a Message Type from the new device. Click on the back arrow (top left) and then select the “Message Types” tile.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Click on the plus (+) button at the bottom. Name the new Message Type (iOS Message Type) for the new devie. Choose the Device Type we just created, and chose From Device for the direction.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

For the Fields, click the plus button to add more messages types (to have 12 in total) and data types.

timestamp: date
device: string
gyroscopex: string
gyroscopey: string
gyroscopez: string
accelerometerx: string
accelerometery: string
accelerometerz: string
altitude: string
longitude: string
latitude: string
audio: string

Then press “Create” (bottom right corner).

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Please note your Message Type ID. I recommend you copy/paste somewhere for easy access later on when we need it.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

2.3: Creating our Device

Press the back arrow (top left) to return to the IoT Sevices Cockpit. Then press the “Devices” tiles.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Once again, press the plus button on the bottom to create a new device. Give it a name (iOS Device), select the Device Type we created earlier (iOS Device Type) and the press “Create” (bottom right).

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Important: After you create the device, a pop up will appear with a token value. Copy/Paste this as well because we need this to input into our SensorPhone app. If you lose it, click into the Authentication tab and you may generate a new token.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Also, please note your Device ID after you click “Close”. You will see the “ID” listed under your “Device Type” on your “Device Page”.I recommend you copy/paste somewhere for easy access later on when we need it. This will be needed to build your URL endpoint in the next step.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

We now have everything setup to use our SensorPhone app with HANA Cloud Platform!

Step 3: Setup your SensorPhone app to send sensor data to HANA Cloud Platform

Now that all of the heaving lifting is out of the way, lets have fun with the SensorPhone app. SensorPhone is an iOS client that allows you to visualize your iPhone’s sensor data in real-time. SensorPhone allows you to stream this sensor data to the Internet of Things service within SAP’s HANA Cloud Platform (via HTTP POST). If you haven’t already, download the app here from the App Store.

Once you download and open SensorPhone, it is extremely important that you Allow all the permissions (as shown below). This is vital to access and send the sensor data.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

SensorPhone app is comprised of two different screens. The first screen is on the “Live” tab. The Live tab visualizes your iOS’ sensor data in real-time. It displays the movements of the accelerometer and the gyroscope. It displays your GPS coordinate, and your magnetic heading along with your altitude. SensorPhone also displays your audio levels around your iOS device, as fed from the primary microphone.

The second screen is the “IoT Service” tab. This tab is the most important because it allows you to enter your HANA Cloud Platform/IoT Service credentials into the provided form to seamlessly stream your sensor data in real-time. The form is comprised of URL, mode, messageType, and messages. You will also notice header values with two fields: Content-Type and Authorization. This is needed to send data to the IoT service from an external source like our iOS device, outside of the authorized network. I’ve also added a drop down menu that allows you to constantly send your updated sensor data in intervals of Just Once, Every 2 Seconds, Every 5 Seconds, and/or Every 10 Seconds. Let’s dig deeper into the form below.
What to enter in the “IoT Service” Form

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Your form’s inputs should look something similar to mine below. At the moment you have to enter this manually so I suggest you put your information into an email and send it to your iOS device. This will allow you to easily copy/paste the information to the appropriate fields.

URL: https://iotmmsi840337trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/74b90c1d-3492-499c-9757-505ce4756bff
mode: sync
messageType: 4c0781b3ff1e7506f77b
messages: *automatically generated*
Header
Content-Type: application/JSON;charset=utf-8
Authorization: Bearer *insert authorization token here*

Note: It is extremely important to add the word “Bearer” and a space before your device’s authorization token.

Watch the data stream!

After you have successfully setup your SensorPhone app, tap POST and you will see a response from HANA that looks something like this:

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

If you’d like to see the raw data in a table, you can easily do so from the IoT Service Cockpit. From your HANA Cloud Platform Cockpit, lets go back to Services, and select the Internet of Things Service. We will enter the IoT Service Cockpit by clicking “Go to Service”. You will now see the IoT Services Cockpit.

Screen+Shot+2016-03-28+at+9.30.31+AM

Select the “Select and view messages, or perform other actions” tile (in the bottom right-hand side).

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Select the “Display Stored Messages” tile (in the top left-hand corner).

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Locate the newly created table by looking for your Message Type (Example: The table would look something like T_IOT_4C0781B3FF1E7506F77B. The long part after the second underscore would be your message type). Then select your table and you will see the messages being sent! Refresh the page to see the new data being fed in.

The Easiest Way to Stream your iPhone's Sensor Data to HANA Cloud Platform

Final Thoughts

Now you’re able to see the power and agility of the Internet of Things services within HANA Cloud Platform. But most importantly, you’re able to leverage this generic demo to build your own personalized demonstration around a particular use case. Your iOS device can a send large amount of data in real-time to your HCP account, the possibilities are endless.

Leave a Reply

Your email address will not be published. Required fields are marked *