IoT: Retrieving sensor data from Android Smartphones

Blog Post created by mfoerster Employee on Jun 27, 2016


In this blog I will introduce and show how to use "OGRE for Android" to retrieve sensor data measured by the hardware sensors of a device running Android, and sending this data to PI.


Lets first get an overview about the desired data flow:



The device bearing the sensors is running Android API (>level 15) and OGRE, the "O. Genuine Realtime-Data Engine", an app for Android.

The app will put the current sensor data into a string and attach the current timestamp. This string will be sent as a HTTP Post request via the internet to the REST endpoint. This endpoint is represented by the UFL Connector listening. Once the string is received by the PI UFL connector, it will be parsed and the sensor data will be stored in the PI System, with the timestamp provided in the string.



We will now walk through the configuration required on both ends. Let us first have a glance at the GUI of the mobile App:


After installing the .apk and starting the App on the Android device this opening screen will pop up. After hitting continue we are guided to the configuration page

The configuration page offers various options:


PI Symbol: Calls Techsupport

Start Service: Starts background service that collects sensor data, stores this data in a string and sends this string via a http POST request to the defined URL.

Stop Service: Stops this background service.

Bind Service: The GUI of this app is an application running independently from the background service. This button will make the GUI application listen to the data that is being collected.

Unbind: Stops listening.

Change Scanclass: Changes the time period between the http Post requests to the specified time in seconds. Possible intervals: 1s - 20s

Submit: Stores the Basic Authentication credentials, as well as the Host URL specified. (Service cannot be started without)


Let us now have a look at the configuration of our REST endpoint, as we need the URL, as well as the Basic authentication credentials.


UFL Connector Configuration:

In the installation of the PI UFL Connector, the listening port of the UFL Connector has to be specified. By default it is port 5460.

  • Please make sure that the firewall is not blocking that port.

The data source can be configured in the UI of the UFL Connector that is available under https://localhost:5460/admin/ui/DatasourceList


Choose to configure or add a new data source:

  • Set "Data Source Type" as REST and enter a "User Name" and "Password" that you want the data source to authenticate with to the PiI UFL Connector.
  • Choose the .ini file that contains the information on how to parse the received string.


The .ini configuration file:



A sample string sent by OGRE v. 1.0 will look like that, and contains timestamp, latitude, longitude, Acceleration in X-, Y-, Z-direction, magnetic field strength in micro Tesla: X- ,Y-, Z-component:

' message=20160525_151731%2C0.0%2C0.0%2C0.0%2C9.77622%2C0.813417%2C0.0%2C0.0%2C0.0%0A&


In order to parse that string the .ini file needs to look like that:






' Create the point and forward event
StoreEvent("Android:Latitude", , Timestamp, Latitude )
StoreEvent("Android:Longitude", , Timestamp, Longitude )
StoreEvent("Android:AccelX", , Timestamp, AccelX )
StoreEvent("Android:AccelY", , Timestamp, AccelY )
StoreEvent("Android:AccelZ", , Timestamp, AccelZ )
StoreEvent("Android:MagX", , Timestamp, MagX )
StoreEvent("Android:MagY", , Timestamp, MagY)
StoreEvent("Android:MagZ", , Timestamp, MagZ )


After saving the configuration in the UI of the PI UFL Connector, and starting the Connector, we need to configure OGRE.


Configuring OGRE:


  • Open the configuration site in OGRE
  • Enter the same Username and Password, that you have specified in the configuration of the data source in the UI of the PI UFL Connector
  • Check the URL that is displayed under "Address" after saving the changes in the configuration page of the data source in the UI of the PI UFL Connector
  • Hit "Submit" in OGRE


OGRE now is configured. The credentials and the URL have been stored.


Starting the data collection:


The service can now be started by hitting "Start Service".

In order to listen to the data that is being sent, we can hit "Bind Service" and the currently send string will be displayed in the bottom of the configuration page.


Additional Information:


I have tested the operation successfully with a trusted certificate for the endpoint. I will start testing with a self signed certificate in a bit.


OGRE version 1.0 gathers data from these sensors: GPS Sensor, Acceleration Sensor, Magnetic Field Sensor

I will extend it to all sensors, if someone requires it.



  • In order to retrieve data from the GPS Sensor, this must be enabled in the Android app settings for this app (OGRE). Otherwise the app will not respond.
  • In order to install this app (.apk) "installation from unknown sources" must be enabled in the Android settings, as the app is not yet published in Google Play Store.



Android installer package for OGRE version 1.0



Configuration of OGRE: June 28th