Lumia SensorCore SDK: New Features for Mobile Application Development. Part 1: Overview



    Good day everyone,

    Today we’ll talk about the Lumia SensorCore SDK , which provides developers with a collection of tools for collecting and processing information from motion sensors and location . 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 energy consumption process.

    Introduction


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

    Storage and processing of information takes into account the user's privacy settings. The user independently makes a decision on connecting / disconnecting the process of collecting information about the user's movement and location, as well as on the destruction of already collected data. In the process of collecting information, cloud storage services are not used, and all data is stored locally on the device.



    For any of the SensorCore APIs to function, both Motion Data settings(Motion data) and location (Location data) should necessarily be included in the device. Therefore, when developing applications using this SDK, it is necessary to provide scenarios when these settings can be disabled or the device does not support SensorCore capabilities at the hardware level.

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



    Key features


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

    • Pedometer;
    • Activity monitor;
    • Location sensor;
    • Tracker routes.

    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's take a closer look at the new APIs available for these scenarios.

    Step Counter API


    A set of tools for counting steps provides information on how many steps a user has taken, how long and how: walked or ran.

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

    The main methods:

    // чтение
    StepCounterReading currentSteps = await stepCounter.GetCurrentReadingAsync();
    // получение событий за последний час
    IList steps = await
    stepCounter.GetStepCountHistoryAsync ( DateTime.Now.AddHours( -1 ), TimeSpan.FromHours( 1 ) );
    

    An 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 a walk has begun and when it has already completed.

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

    The API allows you to distinguish between the following types of activities :

    • The device is in standby mode (without user);
    • The device is with the user, but the user does not move;
    • User walks;
    • The user is running;
    • The user moves, but Active Monitor cannot identify the type of movement, in which case the type of activity is classified as Move .

    The main methods:

    // чтение текущей активности
    ActivityMonitorReading reading = await activityMonitor.GetCurrentReadingAsync();
    // регистрация обработчика события ReadingChanged 
    activityMonitor.ReadingChanged += activityMonitor_ReadingChanged;
    // получение активностей
    IList activities = await 
    activityMonitor.GetActivityHistoryAsync( DateTime.Now.AddDays( -1 ), TimeSpan.FromDays( 1 ) );
    


    Place Monitor API


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

    An example of the 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, as a rule, means a circular area with a radius of less than 200 meters. The radius can grow during the time that the user moved around this place.

    The distance between any two famous places should be more than 500 meters. This means that even if two or more different places are within a radius of 500 meters of 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:

    • ID - a unique identifier for the place;
    • Kind : famous , home, work;
    • Position - the geographical position of the place;
    • Radius - A circular zone around the intended location.

    The main methods:

    // получение текущего места
    Place place = await placeMonitor.GetCurrentPlaceAsync();
    // регистрация обработчика события PlaceChanged 
    placeMonitor.PlaceChanged += placeMonitor_PlaceChanged; 
    // получение зафиксированных мест
    IList 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”:



    “Home” and “Work” are determined by the following criteria:

    • How often the device moved and how the type of activity the user demonstrated;
    • How actively the device was used;
    • Did the phone connect to the charger.

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

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

    There are various scenarios for using the classifications of places proposed in the API as “Home” and “Work”, for example:

    • Creation in applications of more significant UX. For example, a navigation application may use the values ​​of these “Home” labels to automatically create a route from home to work;
    • You can also use the Home classification to create a geo-zone around this place, and then use this geofence to calculate how long the device has been at Home or how many times the device has left the House.
    • An application can use 'Home' to create a geo-zone around the house and use this geo-zone to bring out some functionality in the device. Or the application may send a message to parents that their child has arrived home.

    If the application wants to track the moment of entry and exit of the device from the places "Home" or "Work", the application must use geofencing . Using PlaceMonitor, the application can get a list of known Places and use 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 the minimum amount of energy and working in the background. Thus, to determine the location of the device, the API logic uses towers of mobile operators and Wi-Fi access points .

    Track Point Monitor API


    Track Point Monitor API collects user movement information. It is similar to the Place Monitor API tool, but instead of specific frequently visited places it fixes waypoints . The Track Point Monitor API also uses cell towers and Wi-Fi access points to find out the location of the device.

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



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

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

    • LengthOfStay - tells how long the device has been in this place.
    • Position - the geographical position of the track point.
    • Radius is the estimated radius of the circular region around the place. The accuracy of this value depends on various factors, for example, how the device is used and environmental factors such as the presence of cell towers and Wi-Fi access points.
    • Timestap - time to fix the track point (provided with an accuracy of 5 minutes).

    The main methods:
    // получение позиции пользователя в определенное время
    RoutePoint routePoint = await routeTracker.GetPointAtAsync( DateTime.Now.AddHours( -1 ) );
    // получение маршрута пользователя за определенный интервал
    IList routePoints = await 
      routeTracker.GetRouteAsync(DateTime.Now.AddHours( -1 ), TimeSpan.FromHours( 1 ) );
    


    Features of working with SensorCore SDK


    Some SensorCore SDK features are dependent on other device subsystems. And in some cases, the functionality may not be available if the appropriate equipment in the device is not available. In other cases, functionality improves when all sorts of ways to obtain information are available.

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

    Location accuracy also depends on environmental factors.such as the number of towers of mobile operators and Wi-Fi access points, i.e. accuracy is maximum in densely populated areas with a large number of cell towers and Wi-Fi points. The center of a certain place can be slightly offset from a real location within 500 meters, since known places are tied to the cell towers that were used to determine the location.

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

    Conclusion


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

    In the next part , we will develop an application that sends notifications according to the location of the device, taking into account the recommendations for working with the new SDK, we will tell you 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

    Also popular now: