📜 ⬆️ ⬇️

Lumia SensorCore SDK: new opportunities for developing mobile applications. Part 1: Overview



Good day to all

Today we will talk about the Lumia SensorCore SDK , which provides developers with a collection of tools for collecting and processing information of motion and location sensors . This data is useful primarily in the development of fitness applications and applications where it is necessary to process information about the user's location.
')
The main advantage of this SDK is the ability to work in the background, which optimizes the process of energy consumption.

Introduction


Using Lumia SensorCore SDK significantly reduces the load on the processor, which increases the battery life of the device. This is achieved by the fact that while the applications are hanging in the background, the SDK automatically captures the data from the sensors.

Information is stored and processed taking into account the user's privacy settings. The user independently makes a decision about connecting / disconnecting the process of collecting information about the movement and location of the user, as well as about the destruction of already collected data. The process of collecting information does not use cloud storage services, and all data is stored locally on the device.



For any SensorCore API to function, both Motion data and Location data must be enabled on the device. Therefore, when developing applications using this SDK, it is necessary to provide scenarios where these settings can be disabled or the device does not support the SensorCore capabilities at the hardware level.

It is important to note that the SensorCore SDK is available only for devices of the new generation with the Windows Phone 8.1 operating system, such as Nokia Lumia: 630, 635, 930, 730, 830, including the Nokia Lumia 1520.



Main features


Lumia SensorCore SDK contains an API for working with the following sensors:


Lumia SensorCore SDK for all APIs supports:

//  StepCounter stepCounter = await StepCounter.GetDefaultAsync(); //  if (await StepCounter.IsSupportedAsync()) … //   switch (SenseHelper.GetSenseError(failure.HResult)) //          stepCounter.ActivateAsync(); stepCounter.DeactivateAsync(); 

Let us consider in more detail the new APIs available for these scenarios.

Step Counter API


A set of tools for counting steps , provides information about how many steps the user has completed, how long and how: walked or ran.

The difference is determined not only by speed, but also by the intensity of movement, so that the type of movement is identified even if the user ran and walked at the same speed.

Basic methods:

 //  StepCounterReading currentSteps = await stepCounter.GetCurrentReadingAsync(); //      IList<StepCounterReading> steps = await stepCounter.GetStepCountHistoryAsync ( DateTime.Now.AddHours( -1 ), TimeSpan.FromHours( 1 ) ); 

Example of the Step Counter API used in the Health and Fitness Bing application :



Activity Monitor API


The tool captures information about changes in the user's physical activity , for example, determines when the walk started and when it has already ended.

In order to eliminate inaccurate data, there is a slight delay in determining the change in the type of user activity - in 5-10 seconds.

The API allows to distinguish the following types of activities :


Basic methods:

 //    ActivityMonitorReading reading = await activityMonitor.GetCurrentReadingAsync(); //    <i>ReadingChanged</I> activityMonitor.ReadingChanged += activityMonitor_ReadingChanged; //   IList<ActivityMonitorReading> activities = await activityMonitor.GetActivityHistoryAsync( DateTime.Now.AddDays( -1 ), TimeSpan.FromDays( 1 ) ); 


Place Monitor API


Using this API, you can get a list of coordinates of the places in which the user spent some time: making purchases, having dinner or standing in a traffic jam. The main function of this tool is to identify places that the user visits frequently and identify them as known .

Example of Place Monitor API used in the “ Places” application :



The device must remain in one place for at least 10 minutes in order for the place to be classified as known and added to the list. One place usually means a circular area with a radius of less than 200 meters. The radius can grow during the time the user moved around this place.

The distance between any two known places should be more than 500 meters. This means that even if two or more different places are within a radius of 500 meters from each other, the Place Monitor API will try to combine them into one known place.

All known places are defined by the Place class, which has the following attributes:


Basic methods:

 //    Place place = await placeMonitor.GetCurrentPlaceAsync(); //    PlaceChanged placeMonitor.PlaceChanged += placeMonitor_PlaceChanged; //    IList<Place> places = await placeMonitor.GetPlaceHistoryAsync (DateTime.Now.AddHours( -1 ), TimeSpan.FromHours( 1 ) 

In addition to creating a simple list of known places, the Place Monitor API independently identifies such places as “Home” and “Work”:



"House" and "Work" are determined by the following criteria:


The classification usually takes 2-3 days. It should be noted that “Home” and “Work” are only logical labels for these two places. For example, the Place Monitor will detect the school as “Work” if the school is visited in accordance with the criteria by which the place “Work” is determined.

If the owner of the device moves to a new address or changes jobs, Place Monitor will detect this within 10 days.

There are various scenarios for using the proposed in the API classifications of places like "Home" and "Work", for example:


If the application wants to track the time when the device enters and leaves the “Home” or “Work” places, the application needs to use geofing . Using PlaceMonitor, an application can get a list of known Places places and using the described attributes of the Place class (geo-coordinates and radius) to build a geo-zone around this place.

The API is designed to collect data using minimal amounts of energy and working in the background. Thus, the API uses towers of cellular operators and Wi-Fi access points to determine the location of the device.

Track Point Monitor API


Track Point Monitor API collects information about the movement of the user. It is similar to the Place Monitor API tool, but instead of specific frequently visited places it records route points . To determine the location of the device Track Point Monitor API also uses cell towers and Wi-Fi access points.

An example of the Track Monitor API used in the “ Tracks” application :



Points in the track are recorded at 5-minute intervals (API will wait 5 minutes from the last point of the track, and only then write a new one) and only when the minimum distance between the current and last points of the track is at least 500 meters . For example, if the user stays within 500 meters for a long period of time, the Track Point Monitor will record only one track point for this area.

The Track Point Monitor API provides the following Place class parameters:


Basic methods:
 //       RoutePoint routePoint = await routeTracker.GetPointAtAsync( DateTime.Now.AddHours( -1 ) ); //       IList<RoutePoint> routePoints = await routeTracker.GetRouteAsync(DateTime.Now.AddHours( -1 ), TimeSpan.FromHours( 1 ) ); 


Features of work with SensorCore SDK


Some functions of the SensorCore SDK have dependencies on other subsystems of the device. And in some cases, the functionality may not be available if the corresponding hardware is not available in the device. In other cases, functionality is improved when all sorts of ways of obtaining information are available.

Dependencies are illustrated in the following table:



As can be seen from the table, the accelerometer is crucial for the operation of the Step Counter API and Activity Monitor API.

The accuracy of determining locations also depends on environmental factors , such as the number of cell phone towers and Wi-Fi access points, ie, accuracy is maximum in densely populated areas with a large number of cell towers and Wi-Fi points. The center of a certain place may be slightly offset from the actual location within 500 meters, since known places are attached to cell towers that were used to determine the location.

In cases where the API is used for navigation applications, accuracy can be improved by using data from GPS sensors .

Conclusion


In this article about Lumia SensorCore SDK, we have listed the main features and examples of how the API works in actually functioning applications.

In the next part , we will develop an application that sends notifications in accordance with the location of the device, taking into account the recommendations of working with the new SDK, we will tell how to generate and use dummy data and API simulators.

useful links


Lumia SensorCore SDK:


Microsoft Virtual Academy (MVA) Training Courses
Windows Development Center
Download free or trial Visual Studio 2013

Source: https://habr.com/ru/post/238761/


All Articles