From Wroclaw to Berlin and back with SensorPhone and SAP HCP IoT
Last week I visited Berlin. I went by car, and decided it would be great to finally test SensorPhone app on iPhone. Patrick Colucci claimed his app had been The Easiest Way to Stream your iPhone’s Sensor Data to HANA Cloud Platform. And just that same morning he made an importnat update to the app allowing to save parameters within the SensorPhone. So, I had no excuse not to try it out.
The SensorPhone app reads some iPhone sensors and posts their valuesto SAP HANA Cloud Platform using its IoT Service. If you are not familiar with SAP HCP’s IoT, then have a look at recently updated tutorials:
- Internet of Things (IoT) Explore the SAP HCP IoT Services | SAP
- Internet of Things (IoT) Adding a new device to the IoT Services | SAP
Unfortunately only upon arrival to a hotel in Berlin I realized that IoT Service in my HCP Trial account was not configured to save collected data to my own SAP HANA instance, and therefore I did not have access to run SQL queries directly on the table.
The good thing though, is that Message Management Service (MMS) in SAP HCP IoT provides an OData V2-compatible API that can be used to browse all created tables as well as to consume messages stored by MMS. The OData service document can be retrieved through the endpoint:
Eg. in my i076835trial account in SAP HCP the message type id for data collected from iPhone via SensorPhone app is A7B01790F3E80BC544A3, and therefore can be retrieved from the endpoint
Important thing to note is that this endpoint returns only 100 records by default. I wanted to retrieve all 426 records collected during the trip from my home town of Wrocław to Berlin, and therefore needed to use a trick of adding OData’s $top query parametr to the URL, like this:
Having all records in JSON notation, it was pretty straightforward then to convert values to CSV, select only columns with GPS data and then use GPS Visualizer to convert data to GPX format and to visualize the way I drove:
and elevations on the way:
In the SensorPhone application I set the opion to post new data every 10 seconds. You will immediately spot straight lines at both charts above. It obviously happened when I crossed the border between Poland and Germany and my phone switched to roaming. The message at the bottom of the error displayed at that time on the phone says it all.
The data roaming was not active by default in my phone, so only a few data points were collected during times when I turned data roaming on and posted current sensors values. I did the similar thing with data collected on my way back to Wrocław and you may see that I turned data roaming a bit more often and that I took a different road that time:
But on the way back I configured as well MMS service to persist the data in my SAP HANA instance, so that I could do some calculations and analysis using SQL. But first let me use OData with SAP Lumira.