Polar BLE SDK

repository·master·Indexed 20 days ago

https://github.com/polarofficial/polar-ble-sdk

A cross-platform SDK for Android (minSdk 24) and iOS (14.0+) that provides an interface for interacting with Polar Bluetooth LE sensors and smartwatches. It enables real-time biometric data streaming, including heart rate, ECG, accelerometer, and PPG, utilizing ReactiveX for asynchronous operations. Supported devices include Polar H10, H9, Verity Sense, OH1, and various Polar watches such as Vantage V3 and Pacer Pro.

Tokens
21.6K
Snippets
40
Records
97
Agent score
71%

What's inside Polar BLE SDK

  1. Overview of Polar BLE SDK

    master

    The Polar BLE SDK is the official library for connecting to Polar sensors and watches via Bluetooth LE on Android (minSdk 24) and iOS (14.0+). It allows developers to stream real-time data such as heart rate, ECG, accelerometer, and PPG.

    Key Technical Detail: The SDK API utilizes ReactiveX for handling asynchronous operations.

  2. Features available for Polar OH1 Optical heart rate sensor

    master

    The Polar OH1 optical heart rate sensor provides the following data streams via the SDK:

    • Heart rate: Measured in beats per minute (BPM).
    • Heart rate broadcast: Standard BLE heart rate broadcasting.
    • Photoplethysmography (PPG): Raw PPG values.
    • PP interval: Cardiac pulse-to-pulse interval (in milliseconds) extracted from the PPG signal.
    • Accelerometer data: 3-axis acceleration data with a 50Hz sampling rate and an 8G range. Axis-specific acceleration is provided in mG.
  3. Available data for Polar Verity Sense

    master

    The Polar Verity Sense SDK supports online streaming and offline recording (from version 2.1.0 onwards) of the following data types:

    Sensor Data

    • Heart rate: Beats per minute (BPM).
    • Photoplethysmography (PPG): Raw PPG values.
    • PP interval (PPI): Cardiac pulse-to-pulse interval in milliseconds, extracted from the PPG signal.
    • Accelerometer: 52Hz sample rate, 8G range, axis-specific data in mG.
    • Gyroscope: 52Hz sample rate, 2000deg/sec range, axis-specific data in deg/sec.
    • Magnetometer: Sample rates of 10Hz, 20Hz, 50Hz, and 100Hz, +/-50 Gauss range, axis-specific data in Gauss.

    Device Management

    • Time management (Get/set time).
    • Disk space queries.
    • Power control (Turn off, Restart, Factory reset).
    • Firmware updates.
    • SDK mode configuration.
    • Physical data management (Set gender, birth date, height, weight, max HR, resting HR, VO2max, training background level, typical daily activity level, sleep goal).
    • Data deletion from the device.
  4. Supported features for Polar H9 Heart rate sensor

    master

    The Polar H9 heart rate chest strap provides the following features through the Polar BLE SDK:

    • Heart rate: Available as beats per minute (BPM) and RR Interval in milliseconds (ms).
    • Heart rate broadcast: Supports heart rate broadcasting.
    NOTE

    Unlike the Polar H10, the Polar H9 does not support streaming over the BLE Polar Measurement Data (PMD) service.

  5. Features available for Polar 360 and Polar Loop

    master

    The Polar BLE SDK provides extensive data access and device management for Polar 360 and Polar Loop wearables.

    Online Streaming and Offline Recording

    • Heart rate: Beats per minute (BPM).
    • Acceleration: 50Hz, 16-bit resolution, 8G range.
    • PP interval: Cardiac pulse-to-pulse interval extracted from PPG.
    • Skin temperature: 1Hz, 2Hz, or 4Hz options, 32-bit resolution.
    • Photoplethysmography (PPG): 22Hz, 24-bit resolution (Green channels).
    • Offline recording: Supported for various data types.

    Data Export

    • Sleep data: Available via PolarSleepApi (iOS/Android).
    • Training sessions: Available via PolarTrainingSessionApi (iOS/Android).
    • Activity data: Available via PolarActivityApi (iOS/Android), including:
      • getSteps: Daily accumulated step count.
      • getActiveTime: Daily active time.
      • getCalories: Activity, training, and BMR calorie data.
      • get247HrSamples: 24/7 HR samples (5 min averages for low/moderate activity; 60 samples/min for high activity).
      • get247PPiSamples: 24/7 PPi samples in milliseconds.
      • getSkinTemperature: 24/7 skin temperature at 5 min intervals.
      • getNightlyRecharge: Nightly recharge data.
      • getActivitySampleData: Step count (1 min interval) and MET samples (30 sec interval).
  6. What is SDK Mode and when to use it

    master

    SDK Mode is a device state that provides access to a wider range of raw stream capabilities, such as higher sampling rates and adjustable sensor ranges.

    Important Trade-offs:

    • Algorithms Disabled: When SDK Mode is enabled, all on-device algorithms are disabled. You will no longer receive computed data like heart rate, PP intervals, or RR intervals.
    • Passive Data Disabled: Passive data gathering, such as activity or sleep tracking, is suspended.
    • Sensor Management: All sensors (accelerometer, gyroscope, PPG, etc.) are shut down by default when entering SDK Mode. They are only enabled when you explicitly request them for streaming or offline recording.
    • Battery Life: Using SDK Mode with low sampling rates for specific sensors can be a way to extend device lifetime.
  7. Configure SDK Mode for Polar Verity Sense

    master

    Polar Verity Sense supports SDK mode (from firmware version 1.1.5 onwards), which provides expanded sampling rate and range options compared to the default mode.

    When using SDK mode, you can select specific sampling rates and ranges for sensors. If a value is bolded in the table below, it represents the default option.

    DataOperation ModeSampling RateRange (+-)Resolution
    AccOnline streaming26Hz, 52Hz, 104Hz, 208Hz, 416Hz2g, 4g, 8g, 16g16
    AccOffline recording13Hz, 26Hz, 52Hz2g, 4g, 8g, 16g16
    GyroOnline streaming26Hz, 52Hz, 104Hz, 208Hz, 416Hz250, 500, 1000, 2000 deg/sec16
    GyroOffline recording13Hz, 26Hz, 52Hz250, 500, 1000, 2000 deg/sec16
    MagnetometerOnline streaming10Hz, 20Hz, 50Hz, 100Hz50 Gauss16
    MagnetometerOffline recording10Hz, 20Hz, 50Hz50 Gauss16
    PPGOnline streaming28Hz, 44Hz, 55Hz, 135Hz, 176Hz-22
    PPGOffline recording28Hz, 44Hz, 55Hz-22

    Note on PPI and HR in SDK Mode:

    • PPI (PP interval) online streaming and offline recording are not supported in SDK mode.
    • HR (Heart Rate) online streaming and offline recording are not supported in SDK mode.
  8. Understand the iOS Communications library structure

    master

    The iOS Communications library provides three distinct levels of functionality for interacting with Polar devices over Bluetooth LE:

    1. iOS Communications: The base layer providing core connection and communication logic. Used primarily by Polar's own applications.
    2. Polar BLE SDK: A wrapper around the base library designed specifically for 3rd party developers. This is the primary entry point for most external integrations. It includes targets for both iOS (PolarBleSdk) and watchOS (PolarBleSdkWatchOs).
    3. Polar BLE SDK PROPRIETARY: An internal-only version for Polar development, maintained on a separate branch (sdk-proprietary).

    Note that the PolarBleSdk and PolarBleSdkWatchOs targets depend on the iOSCommunications base target.

  9. Understanding PPI Data and its limitations

    master

    Pulse-to-Pulse interval (PPI) is the signal between two main peaks of the Photoplethysmography (PPG) signal obtained from optical heart rate sensors (e.g., Polar wrist devices, Verity Sense, OH1).

    Key Differences from ECG (R-R intervals):

    • PPI is derived from optical PPG signals, whereas R-R intervals are derived from ECG (e.g., H9/H10).
    • PPI is significantly more sensitive to noise such as movement or light leaking.

    Critical Usage Constraint: PPI cannot be measured accurately during activity. It should only be used when the user is at complete rest.

  10. Handle Threading and Dispatchers

    master

    Replace RxJava Schedulers with Kotlin Coroutine Dispatchers. While the SDK handles much of its own threading, you should use Dispatchers.Main for UI updates and withContext(Dispatchers.IO) or .flowOn(Dispatchers.IO) for background work.

    // Launch on Main for UI
    lifecycleScope.launch(Dispatchers.Main) {
        // Switch to IO for background work
        withContext(Dispatchers.IO) {
            // background task
        }
    }
    
    // Using flowOn for Flows
    flow.flowOn(Dispatchers.IO)
        .collect { /* runs on caller's dispatcher */ }
  11. Concurrency and device interaction constraints

    master

    When interacting with Polar devices via the SDK, adhere to these architectural constraints to prevent communication errors:

    • Sequential API Calls: Polar devices are designed to process underlying communication operations (reads and writes) sequentially. Do not call multiple SDK methods for the same device from multiple threads simultaneously. Ensure control is returned to your application code before executing the next SDK API method call for a specific device.
    • Single Device Interaction: While the SDK can interact with multiple Polar devices over BLE at once, parallel operations across different devices have not been extensively tested. It is currently recommended to interact with only one device at a time.
    • Background Syncing: Sync activities can be performed in the foreground or background. Developers must follow the respective platform guidelines (iOS BackgroundTasks or Android Background Work) to implement background processes correctly.
  12. Monitor Polar 360 battery and charging status

    master

    Polar 360 battery levels dictate available functionality:

    ModeBattery LevelOperations
    Normal100% – 5%All functionalities available
    Critical5% – 2%All functionalities disabled; only BLE remains active
    Hibernate2% – 0%BLE turned off; maintains timekeeping for ~1 week

    Charging Events (Firmware 2.0.8+, SDK 6.4.0+):

    • CHARGING: Device is connected to a power source and charging.
    • DISCHARGING ACTIVE: Device is operating and discharging.

    Note on Storage Mode: When the device is turned off, it enters storage mode where the battery circuit is disconnected. Timekeeping is disabled in this mode. It is recommended to sync with the app and reset the time when the device is turned back on.