Welcome,

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.

 

Configuration:

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:

 

[FIELD]
FIELD(1).NAME="TimeStamp"
FIELD(1).TYPE="DateTime"
FIELD(1).FORMAT="yyyyMMdd_hhmmss"
FIELD(2).NAME="Latitude"
FIELD(2).TYPE="Number"
FIELD(3).NAME="Longitude"
FIELD(3).TYPE="Number"
FIELD(4).NAME="AccelX"
FIELD(4).TYPE="Number"
FIELD(5).NAME="AccelY"
FIELD(5).TYPE="Number"
FIELD(6).NAME="AccelZ"
FIELD(6).TYPE="Number"
FIELD(7).NAME="MagX"
FIELD(7).TYPE="Number"
FIELD(8).NAME="MagY"
FIELD(8).TYPE="Number"
FIELD(9).NAME="MagZ"
FIELD(9).TYPE="Number"

[MSG]
MSG(1).NAME="Data"


[Data]
Data.FILTER=C1=="*"
TimeStamp=["*=(*)%2C*%2C*%2C*%2C*%2C*%2C*%2C*%2C*"]
Latitude=["*=*%2C(*)%2C*%2C*%2C*%2C*%2C*%2C*%2C*"]
Longitude=["*=*%2C*%2C(*)%2C*%2C*%2C*%2C*%2C*%2C*"]
AccelX=["*=*%2C*%2C*%2C(*)%2C*%2C*%2C*%2C*%2C*"]
AccelY=["*=*%2C*%2C*%2C*%2C(*)%2C*%2C*%2C*%2C*"]
AccelZ=["*=*%2C*%2C*%2C*%2C*%2C(*)%2C*%2C*%2C*"]
MagX=["*=*%2C*%2C*%2C*%2C*%2C*%2C(*)%2C*%2C*"]
MagY=["*=*%2C*%2C*%2C*%2C*%2C*%2C*%2C(*)%2C*"]
MagZ=["*=*%2C*%2C*%2C*%2C*%2C*%2C*%2C*%2C(*)%*"]

 

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

 

Also:

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

 

Attachment:

Android installer package for OGRE version 1.0

 

Edit:

Configuration of OGRE: June 28th