Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member194491
Active Participant
40,641


 

UPDATE (October 2019): SensorPhone is no longer supported and has been removed from the App Store due to recent changes in the IoT Services. Thanks for your support!

-

UPDATE (Feb. 27, 2017): SensorPhone has been upgraded and has a new icon to show for it! First, SensorPhone has been upgraded to support all iPhone screen sizes. Yes - that means your shiny iPhone 7 Plus! Second, the IoT Services form screen has been improved. We've leveraged design aesthetics from the SAP Belize theme and native iOS controls. It's now a lot easier to use and setup your iOS device to communicate with SAP Cloud Platform. Lastly, we've got rid of a few bugs that interfered with the microphone.

As you may already know, SAP Cloud Platform (SCP) allows anyone to go from sensor to visualization with the Internet of Things (IoT) service. SAP 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 SAP 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 SAP 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 SAP Cloud Platform. The app is called SensorPhone. I will show you how you can use your iPhone and the SensorPhone app with your own SAP 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 SAP Cloud Platform. Enjoy!


Before we get started, here is what you need:

  • The iOS SensorPhone client was updated to version 1.3.2 or higher 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.1 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+)

  • SAP 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 SAP 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 SCP 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 SAP Cloud Platform.


 

Enabling the IoT Service for your SAP 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 SAP 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.

 




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




You now have enabled the IoT Services for your SCP 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 SAP Cloud Platform.

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




You will now see "Deploy Message Management Service" on the bottom left tile. Click on that.

 

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.

 

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 SAP Cloud Platform Cockpit, select Java Applications and click on iotmms. This will take us to the Java Application Overview screen.

 




 

On the left hand side, select Security > Roles.

We now see the predefined IoT-MMs-User Role at the top.

 


 

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.




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 SAP 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 SAP 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 SAP 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!

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




2.1: Creating our Message Type

We will create a Message Type for the iOS device. Click on the "Message Types" tile. 
 

Click on the plus ( ) button at the bottom. Name the new Message Type (iOS Message Type) for the new device.



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).



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

 

2.2: Creating our Device Type


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



Name your device type (iOS Device), assign it (by clicking Add Message Type) with the Message Type we just created, and chose From Device for the direction. press "Create".



 

2.3: Creating our Device

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




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).


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. 



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.

 

 

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

 

Step 3: Setup your SensorPhone app to send sensor data to SAP 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 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.






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 SAP 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


 







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-...

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:

 



 

If you'd like to see the raw data in a table, you can easily do so from the IoT Service Cockpit. From your SAP 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.

 




 

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

 




 

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

 



 

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.

 




Final Thoughts


 

Now you're able to see the power and agility of the Internet of Things services within SAP 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 SCP account, the possibilities are endless.


I have a few more updates on the way for SensorPhone that will make the setup easier and the sensors configurable. Take a look at Visualizing iPhone Sensor Data with SAPUI5 by my colleague in Toronto, anthony.mcleod, that illustrates how to consume this sensor data using SAP Cloud Platform and SAPUI5. Stay tuned and thank you for playing with SensorPhone!

Follow me on Twitter and LinkedIn!

 

Patrick Colucci

Technology Solution Consultant

SAP Canada
158 Comments
former_member194491
Active Participant
0 Kudos

Hi Manikandan,

I'm sorry to hear you're having the same issue as Danny with SensorPhone. Can you also please verify that you've correctly setup your Message Type (for SensorPhone 1.3.2) with the required fields and can you also let me know your MMS version?

Best,

Pat

hiroakiadachi
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is really great and fun blog !! I must try it.

I'm looking forward to next blog that consume and view data using UI5. Also I want to send data more short period like 0.1 sec.

Thank you !!

former_member194491
Active Participant
0 Kudos

Thanks, Hiroaki!

former_member194491
Active Participant
0 Kudos

Hi Uma, SensorPhone currently only supports screens larger than 4". There will be an update to support the iPhone 4/4S.

Best,

Pat

0 Kudos

It works now! Thanks for the update Patrick.

Former Member
0 Kudos

Hi Patrick,

thank you for this nice blog!

I followed your introduction but got a problem by transferring the sensor data. It looks like the iPhone is transferring data but it doesn`t appear at the stored messages.

Thanks for your advice!

Best regards

Daniel

Former Member
0 Kudos

Hello,

fixed the problem, the fields in the message type have been only in wrong order....

But got two more questions:

1. Where are the data stored because our own HANA is not connected?

and

2. Is there a possibility to load the data in our own HANA/BW?

Thank you!

Regards

Daniel

former_member194360
Contributor
0 Kudos

I had it as well. Basically the iphone variables must match to the ones you define in HCP. In this app here you see a little window "message". And it seems to be that the variable names displayed there must match to the dataset you define in HCP.

Reasoning: The app does not create a structure in HCP, but uses http to send data to an existing structure.

Former Member
0 Kudos

Great blog. It´s working fine.

former_member194419
Participant
0 Kudos

Hi Patrick,

Nice post !!! :smile:


I have tried reproduced these steps, but I can´t see my messages:

https://iotmmss000************trial.hanatrial.ondemand.com/com.sap.iotservices.mms/

Access to the requested resource is forbidden (HTTP 403).

Do you have any idea about this issue?

Regards,

Rodrigo S.

former_member194491
Active Participant
0 Kudos

Hi Rodrigo,

Your user needs a "IoT-MMS-User" role, please follow the documentation SAP HANA Cloud Platform Internet of Things (IoT) Services

Make sure to have a new session in a browser after assignment.

Best,

Pat

tomvanrooijen
Participant
0 Kudos

On iPad2 I do not have the post button to start sending data. Does it really have to be an iPhone? Or is something else wrong.

I am also missing the sending interval input box

Thanks

Tom

Vitaliy-R
Developer Advocate
Developer Advocate
0 Kudos

I used it when traveling from Wrocław to Berlin and then back: From Wroclaw to Berlin and back with SensorPhone and SAP HCP IoT

Btw, the precision of iPhone's GPS was so good, it is ... scary :smile: You do not think about that when using the phone to navigate, but then seeing how precisely your location is known to the phone and how easy it is to share this information... makes you thinking.

tbroek
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Patrick

Thanks for making IoT even a more low barrier entry!!

Had some issues with the timestamp format, at least that's what the SensorPhone told me. Turned out that I was using an outdated MMS (Message Management Service) within HCP. Deployed the new version and everything works like a charm.

Again thanks!

Twan

ukottig
Explorer
0 Kudos

Hi,

great stuff and easy to handle, thanks!

Any Suggestion for a tutorial how to visualize the data now into nice graphs? I guess there is a Service on HCP already for that?

regards

ulf

Former Member
0 Kudos

Hi!

Great post. Works perfectly. May it be possible to share the source code of your iPhone app, especially the part, where the JSON message is constructed and then sent to the HCP?

Thanks!

Volker

harsh_satsangi
Product and Topic Expert
Product and Topic Expert
0 Kudos

Get the error "the message does not conform to the message type".

I double checked all my settings and also the message type. It is exactly how it was described.

Did anyone else face this issue? How to see the logs to see why this error happens?

former_member191567
Participant
0 Kudos

Hi Patrick, Good tutorial.

Somehow I am not able to see the data/fields in the application data screen.

Not sure what went wrong. Can you advise.

Something went wrong, probably the message type config/or device type.

Screenshot:  https://www.photobox.co.uk/my/photo/full?photo_id=9253833008'

Thanks,

Dev.

former_member194491
Active Participant
0 Kudos

Hi Vicky,

I am unable to view the photo. Could you upload the photo directly to your comment? Since HCP is a cloud platform, many minor things have changed since I last updated the blog. The steps still work, however, the UI layout on some screens may appear different.

Best,

Pat

former_member194491
Active Participant
0 Kudos

Hi Harsh, The audio sensor is very sensitive and is a common source of this problem. Please be sure you do not have any headphones plugged into your iOS device, you're not on a phone call, and allow up to 10 seconds for the SensorPhone app to retrieve the audio sensor data before your tap "POST". I hope this helps.

Best,

Pat

former_member191567
Participant
0 Kudos

Hey Patrick, I am not able to upload the image on this forum, as its giving me some authorization issues. So, uploaded the image to a diff server online.

Here is another link :http://pasteboard.co/dMUt8JpIa.png

Note: You may need to copy/paste the URL on your browser separately.

Yes, though the UI has changed, its pretty much the same. Not sure why am not able to see the fields in the application data screen page.

former_member194491
Active Participant
0 Kudos

Hi Vicky, do you receive and error when you post? Or "200 (1) message received"?

former_member191567
Participant
0 Kudos

I dont see any error. are you referring to any error on the app/iphone device? if so, I dont think there is any.. and if there is any error, msgs would not have flown all the way to the cloud platform. I know msgs are being transmitted, but not sure where they are going, as am not able to see the fields that I created, where the data should be populated.

https://www.photobox.co.uk/my/photo/full?photo_id=21269402653

former_member191567
Participant
0 Kudos

Hi Patrick , not sure if you can help, but was trying to follow up to see if you can share your inputs, enabling me to complete this cool exercise.

ReinerE
Explorer
0 Kudos

Hi Patrick,

I tried with my IPad2 to send data but there is no information after post and no data on the IoT table.

It works with test data from the IoT browser http client so settings are ok. Are there information if it works with IPad2?

former_member194491
Active Participant
0 Kudos

Hi Vicky, sorry for the delay. I saw your image and from what is visible, everything looks good. Some of the sensors on the iPhone are very sensitive and is a common source of this type of problem. Please be sure you do not have any headphones plugged into your iOS device, you're not on a phone call, and allow up to 10 seconds for the SensorPhone app to retrieve the audio sensor data before your tap "POST". Let me know if that helps.

former_member191567
Participant
0 Kudos

Patrick, first of all, thanks for the response.

Secondly, I am not sure what those msgs are, that are reflecting on my screen.

I know there are several msgs being updated every second and am not sure what those are. Also, the fields that I created during the config stage, did not reflect anywhere.

I only see that the msgs are being posted with a msg, and some msgs are being updated in diff table, which doesnt show the fields that I have created during the config..

Something is wrong for sure.. even if there is no posting of msgs from the smartphone, i should still be able to look into the fields that I have created in some table format, right?

If so, not sure where that would be..

former_member194491
Active Participant
0 Kudos

Hi Eberhard, when sending data from an external source (like your iOS device) vs. the test IoT browser client is slightly different. Please verify that your authorization field is filled out correctly. The most recent update to SensorPhone was to support the iPad 2 and up, so there shouldn't be too much of an issue.

ReinerE
Explorer
0 Kudos

Hello Patrick,

I use Bearer <Authtoken> as you described and use with other Javascript Clients to IoT.

former_member194491
Active Participant
0 Kudos

Hi Vicky, do you mind uploading a screenshot of the messages that appear on your iOS screen when you hit POST?

former_member194491
Active Participant
0 Kudos

Thanks Vicky, after you hit POST, there is a message that appears at the top of your screen briefly until it disappears. Can you send me a screenshot of that please?

former_member191567
Participant
0 Kudos

U mean the black colored msg/ kind of command prompt type msg that appears every time when a msg is being posted? if so, i am not getting it now.

I got it yesterday, and later i changed the authorization code to "iOS device token authorization code" instead of device registration token..

I just checked it again by changing it to the registration token, and no luck again..

former_member194491
Active Participant
0 Kudos

Yes the black message.

former_member191567
Participant
0 Kudos

nope, thats not appearing now..

former_member194491
Active Participant
0 Kudos

The message appears regardless of an error or a success. It displays a log message from HCP.

former_member191567
Participant
0 Kudos

in that case, no msg is being generated, which means HCP is not sending in any msgs back to the iot sensor app. any clue? if the services got shutdown/stopped etc?

former_member191567
Participant
0 Kudos

am in the IoT cockpit and wondering if I need to do anything explicitly to make the msgs display again in the iot sensor app.. 

former_member191567
Participant
0 Kudos

I got this big msg, which I thought of sharing it to you. Attached screenshots, to see what the msg is.

http://i.cubeupload.com/VlJrm7.png

http://i.cubeupload.com/r6ErWc.png

former_member194491
Active Participant
0 Kudos

That error tells me that your service is unavailable, so I assume it is off. The MMS turns off in a trial account after a specific time of inactivity.

To turn it on go to your HCP cockpit (https://account.hanatrial.ondemand.com/cockpit) > JAVA Applications > turn on "iotmms" by pressing the play button. After that turns on, your SensorPhone app will work if set up correctly.

former_member191567
Participant
0 Kudos

Ok, I noticed that the IoTmms is in "started status with green. However, I stopped the service now ( as clicking on the play button throws me a msg

"Could not start additional process for application iotmms: Application 'iotmms' is started. The application is deployed in a trial account, which provides a single process. If you need to start additional processes, deploy the application in a productive account. If you need to restart, execute restart."

,) and restarted the services again. and now its started..

Now, after restarting, the status went back to green/started- and I invoked the IoT sensor app and tried to post the msgs, but still no black msg/ displaying the log.

ReinerE
Explorer
0 Kudos

Hello Patrick,

now I was successful with sending data from IPad2 to our HCP instance.

former_member191567
Participant
0 Kudos

Patrick,

Here are the msgs I got, after I re-configured again from start.

http://i.cubeupload.com/42wp76.png

http://i.cubeupload.com/e6Jdoo.png

Also noticed on step 2.2: Creating our Message Type, there is no option to Choose the Device Type we just created in the previous step. However, able to add the fields and save. Not sure if this is creating a problem.


Shall look forward for your inputs, enabling me to complete the scenario.

Thanks,

Dev.

Former Member
0 Kudos
Hi,

Great stuff!

Any suggestion for a tutorial how to visualize the data into nice graphs?

KR,
Elena
AaronLong
Product and Topic Expert
Product and Topic Expert
Great blog!
it would be nice if the device name is as the input field. now it is always 'iOS Device' if I used ' Every x Seconds '.
thomas_pieritz3
Discoverer
Hi, great work, easy to handle.

Thank you for your effort to open the way to IOT.

Thanks
Thomas
Former Member
0 Kudos
Great Blog Patrick!

It was so easy to follow the instructions and test this first IOT app, i was able to successfully post the msgs and reviewed the posted data successfully as well. Just one questions i have is how the message content area gets updated, what i am noticing is that same values are appearing all the time. Is the Data in Message section dynamically getting updated for all the parameters?

Thank you so much all the information so far and i will continue to explore more on IOT.

Kind Regards,

Saby

 

 

 
Former Member
Hi,

I was able to complete the setup using the instructions, however, I do not get a table like T_IOT_4C0781B3FF1E7506FF77B, instead I get two tables:

  • T_IOT_CONFIG

  • T_IOT_MONITOR_LOG


Neither of these two tables contain the fields (variables) that I have defined. What could be the issue?

I am using iPhone 7.

Kind regards,

Jari
Former Member
0 Kudos
I have the same issue
Former Member
0 Kudos
Hi Patrick,

I was able to complete the setup using the instructions, however there is no new Table created in the Display stored messages and in Iphone  in the sensor app there is no response from either success (200 Ok ) or error . I have updated the iOS to the latest version 10.3.1 ...will this be a issue can you tell me after upgrade is there any issue with the Sensorphone app

 

Thanks,

Siva

 


patrick.colucci