×

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: Please note that 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. The combination of history data and real-time step count is used to calculate the number of total steps, and the number of walking and running steps.

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 the last 24 hours 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 all the known places on the map, draws a circle of known radius around them, and creates equal-sized geofences on those locations. The user is able to switch between the known places by using the map or the application bar buttons.

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 Blue SDK and Lumia SensorCore SDK.

Lumia SensorCore SDK, and its APIs, are used in the same way in both XAML 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 XAML Silverlight
Quick Start x 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 amounts for today, and a graph of cumulative steps. Step count information is updated every 5 seconds.



Steps sample application will automatically switch to use simulation data, if it recognises that it runs in emulator environment. Switch between the use of simulated data and real sensor data can also be done while the application is running on device by selecting “Use simulation” from application menu.

If simulation is chosen, then the sample loads the simulation data from a file and passes it to StepCounterSimulator’s initialization method GetDefaultAsync. Second parameter of the 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 is 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.0 steps-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.

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 well as a history log containing up to 10 days or recorded activities. In this sample application history data is used to display a graph of user’s activities during the last 24 hours.



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.

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 use has been running continuously for 8 hours, it is more likely that the device was turned off sometime after the activity is started.

Downloads

Activities project v1.0 activities-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.

Places

Places is a sample application demonstrating the use of the Place Monitor API.

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;

Downloads

Places project v1.0 places-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.

Tracks

Tracks is Track Point Monitor API sample focusing on visualising the routes on the screen.

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

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 30 June 2014

Back to top

×