SensorCore SDK samples

We offer you a number of different samples/tools to help you getting started with the Lumia SensorCore SDK.

Quick Start sample shows general patterns and practices on how one should use SensorCore to ensure stability and compatibility.

Note: The same essential patterns and practices are used in other samples in identical way, although they are only documented in detail in the Quick Start.

Steps is a sample application demonstrating the usage of Step Counter API. In this sample application, history data is used to display a graph of user’s steps during current day, and up to 7 days in the past. Steps sample includes a background task component that is triggered to update the live tile with user’s step count meter for the current day (i.e. today) once the user has moved at least 5 steps and at least 10 minutes have elapsed since the last step counter trigger.

Activities is a sample application demonstrating the usage of Activity Monitor API. This application shows the current activity performed by the user, as well as a graph of user’s activities during today, and up to 10 days in the past, using the recorded history data.

Places is a sample application demonstrating the usage of Place Monitor API and geofences in Windows Phone 8.1. This application shows home, work,and all the known and frequent places (geo-locations) on the map. Radius of the circles drawn around the places indicates the uncertainty of the exact location. The application also creates equal-sized geofences on those locations. The user is able to switch between the places by using the map or the application bar buttons. Additionally Places sample implements an improved flow to enable users to set the required phone settings (location and motion data) ON.

Tracks is a sample application demonstrating the usage of Track Point Monitor API. This application shows the recorded track points, as well as the approximate route the user has taken by drawing lines between the track points. Track points can be filtered to show only track points from a certain day of the last week, or track points where the user has stayed at one point for a defined amount of time.

Sense Recorder sample demonstrates how the developer can record data for later use with the simulator.

Compatibility

  • These applications require Windows Phone 8.1.
  • Tested with Lumia 635 and Lumia 1520.
  • Developed with Visual Studio 2013.
  • Requires Windows Phone 8.1 SDK and Lumia SensorCore SDK.

Lumia SensorCore SDK, and its APIs, are used in the same way in both Universal and Silverlight apps. Silverlight 8.1 framework was chosen for Sense Recorder application, because the framework allows disabling app idle detection in order to run the app under lock screen. There are no technical reasons for the chosen app framework of the other samples.

Sample Universal Silverlight
Quick Start x  
Steps   x
Activities x  
Places x  
Tracks x  
Sense Recorder   x

Steps

Steps is a sample application demonstrating the use of the Step Counter API. This is a single view application showing the user’s walking and running step amount for today, and up to 7 days in the past. Motion data service on a device is capable of storing data for 10 days period, and the application reads data from the service history. The target device may not have any history available, if the user has just recently enabled Motion data collecting or has erased Motion data lately. Steps application is not storing user data anywhere.



Steps sample includes a background task component that is triggered to update the live tile with user’s step count meter for the current day (i.e. today) once the user has moved at least 5 steps and at least 10 minutes have elapsed since last step counter trigger.

SensorCore SDK and a service on device provides this trigger and a method to query if current OS version supports it. The app will check if the trigger is supported by calling SenseHelper.GetSupportedCapabilitiesAsync() which returns an object with a parameter StepCounterTrigger to indicate if trigger is supported or not. If the OS version doesn't support the trigger, then Steps application will use normal time based trigger which is triggered every 15 minutes. When triggered, the background task updates live tile which shows a meter that indicates how many steps user has taken during the current day. The image below shows how the wide and large square live tile of the Steps sample appear with real data on the phone.

When Steps sample is started it will automatically switch to use simulation data, if it recognises that it runs in emulator environment. If simulation is running, then the sample loads simulation data from a file and passes it to StepCounterSimulator’s initialization method GetDefaultAsync. Second parameter of GetDefaultAsync is the start time of simulation. In the sample we use 12 hours in the past as a start time. If the difference between the start time and current time is longer than the length of simulation, simulation will be looped. In practice this means that if we use a simulation that has the length of 1 hour and 500 steps, simulation is repeated 12 times when the application is started and thus there will be 6000 (12*500) steps visible in the application when it starts.

The code snippet below shows how to read simulation data from a file and use it.

private async Task InitializeSimulatorAsync() 
{
    var obj = await SenseRecording.LoadFromFileAsync("simulation.txt");
    bool res = await CallSenseApiAsync(async () => { _stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); });
    if (!res)
       Application.Current.Terminate(); 
}  

Downloads

Steps project v1.1 steps-v1.1.zip

Get the app from Windows Phone store ›

This sample application is hosted in GitHub, where you can check the latest activities, report issues, browse source, ask questions, or even contribute to the project yourself.

Activities

Activities is a sample application demonstrating the use of the Activity Monitor API. The Activity Monitor API offers functionality to query the current activity performed by the user, receive notifications when the activity changes, as well as a history log containing up to 10 days of recorded activities. In this sample application history data is used to display a graph of user’s activities during the current day, and up to 10 days in the past.



The Activity Monitor API allows reading the current activity using the GetCurrentReadingAsync() method. The application can also register to receive notifications when the current activity changes, by registering an event handler for the ReadingChanged event.

Accessing the activity history data happens by calling GetActivityHistoryAsync. The Activity Monitor API returns a list of activities and their timestamp, and our example simply parses this list calculating the duration of each activity as a delta between its timestamp and that of the next activity in the list.

In order to get the full 24h activity data for each history day, the application calculates the last activity record at midnight each day, and activities from midnight onwards are calculated to the next day. The total of daily activities shown by the sample is typically within 23:57-23:59 range as only full minutes are calculated for each activity.

For more advanced use cases the applications may want to filter this data, as there is no log entry to indicate that the device was turned off in between two log entries. This means that while it may appear that the user has been running continuously for 8 hours, it is more likely that the device was turned off sometime after the activity was started.

The history data is stored for 10x24h, which means that (with full history data available) the data for oldest day is always only partial, and oldest data is being cleared out according to the current time. For a consumer application this could be misleading, and leaving out the oldest day should be considered, but in the sample it has been kept for demonstrative and testing purposes.

Downloads

Activities project v1.1 activities-v1.1.zip

Get the app from Windows Phone store ›

This sample application is hosted in GitHub, where you can check the latest activities, report issues, browse source, ask questions, or even contribute to the project yourself.

Places

Places is a sample application demonstrating the use of the Place Monitor API. This application shows home, work, and all the known and frequent places (geo-locations) on the map. Radius of the circle around them, drawn using different colour for each type of places, indicates uncertainty of the exact location. The application also creates equal-sized geofences on those locations. The user is able to switch between the places by using the map or the application bar buttons. The application also includes full screen mode.

Additionally Places sample implements an improved flow to enable users to set the required phone settings ON. Both location and motion data must be enabled on the phone settings for SensorCore to function and to collect data. If either of the settings is not ON, a dialog is shown to the user for easy access to change the setting, and when the user returns from the settings, the app is automatically switched back to active mode. Furthermore, the sample is able to detect if location or motion data were not set ON when returning from settings to the app, or if either of the settings has been disabled while the app is in use.

We can get the places from the PlaceMonitor class by querying the GetKnownPlacesAsync method. The list will include all known places, and 'home' and 'work' if they are recognised. Each place will have information related to the location, radius, and length of stay. We are using the location and radius information to create geofences at the next stage of this sample.

if (await CallSensorcoreApiAsync(async () => { app.places = await monitor.GetKnownPlacesAsync();}))
{
    foreach (var p in app.places)
    {
        System.Diagnostics.Debug.WriteLine("Place {0} radius {1} Latitude {2} Longitude {3} Length of stay {4}",p.Kind, p.Radius, p.Position.Latitude, p.Position.Longitude, p.LengthOfStay);
        ...
    }
}

Geofences

Now we will add the geofences around all the known locations. Be aware that the geofences are persistent between launches of the app, so do not try to create the geofence on each launch with the same id.

var position = new BasicGeoposition {Latitude = latitude, Longitude = longitude, Altitude = 0.0};

// the geofence is a circular region
var geocircle = new Geocircle(position, radius);

// Listen for enter geofence and exit geofence events
MonitoredGeofenceStates mask = 0;

mask |= MonitoredGeofenceStates.Entered;
mask |= MonitoredGeofenceStates.Exited;

var geofence = new Geofence(fenceKey, geocircle, mask, false);
GeofenceMonitor.Current.Geofences.Add(geofence);
GeofenceMonitor.Current.StatusChanged += EnterFence;

Apps should remove all the geofences that they do not need. Current maximum number of geofences in a Windows Phone 8.1 device is 1000.

Downloads

Places project v1.2 places-v1.2.zip

Get the app from Windows Phone store ›

This sample application is hosted in GitHub, where you can check the latest activities, report issues, browse source, ask questions, or even contribute to the project yourself.

Tracks

Tracks is a sample application demonstrating the usage of Track Point Monitor API. This application shows the recorded track points, as well as the approximate route the user has taken by drawing lines between the track points. Track points can be filtered to show only track points from a certain day of the past week, or track points where the user has stayed at one point for a defined amount of time.

With Lumia Denim firmware, when GPS has been in use on the phone, track points are being recorded in 30s/50m interval, which gives a fairly detailed and accurate description of the route the user has taken. However, in typical cases where Track Point Monitor works passively (uses cell tower and Wi-Fi base station data instead of GPS), track points are recorded at most every 5min/500m. The application also includes full screen mode.

We can get the known track points from the TrackPointMonitor class by querying the GetTrackPointsAsync method. The list will include all track points that the phone has registered within the timespan provided.

points = await tracker. GetTrackPointsAsync (selected.Day, TimeSpan.FromHours(24));
... 
foreach (var p in points) 
{ 
    Debug.WriteLine("Lat:{0} Lon:{1} Rad:{2} Time:{3} Length:{4} ", p.Position.Latitude, p.Position.Longitude, p.Radius, p.Timestamp, p.LengthOfStay);
    ... 
}

Downloads

Tracks project v1.2 tracks-v1.2.zip

Get the app from Windows Phone store ›

This sample application is hosted in GitHub, where you can check the latest activities, report issues, browse source, ask questions, or even contribute to the project yourself.

Recorder

Recorder is a sample showing how the developer can record data for all SensorCore APIs to be used later with the simulator.

The recording happens using the SenseRecorder class, which is implemented in Recording class in this sample for each instance separately. The thing to note is that you cannot record several sensors with one SenseRecorder, but you need a separate instance for each sensor.

Downloads

Sense recorder project v1.0 senserecorder-v1.0.zip

This sample application is hosted in GitHub, where you can check the latest activities, report issues, browse source, ask questions, or even contribute to the project yourself.


Last updated 15 October 2014

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×