Skip to content
On this page

PPG Device Scanner

The SDK provides an API to scan for nearby PPG devices, based on a specified PPGDeviceType. The results obtained during the scan can be utilized later to create PPG Device sessions with any device from the list.

Creating a PPG Device Scanner

Scanning for PPG Devices is done by creating a PPGDeviceScanner object. In the following sample, a scanner, searching for PPGDeviceType.POLAR, is created, with this as the PPGDeviceScannerListener.

Dart
PPGDeviceScanner scanner = PPGDeviceScanner(PPGDeviceType.POLAR, this);

Starting a scan for PPG Devices

To initiate a scan, call the start method. If the method is called without a timeoutDuration parameter, or with a value of 0 or below, the default timeout of 60 seconds is used. The timeout duration should be specified in seconds.

If a scanner is already performing a scan, calling start will first stop the current scan before starting a new one.

In the following example, scanner.start is called with a timeoutDuration of 30 seconds.

Dart
try {
    var timeoutDuration = 30;
    scanner.start(timeoutDuration);
} on HealthMonitorException catch(e) {
    print("Received Error. Domain: ${e.domain} Code: ${e.code}");
}

Receiving results during a scan

To receive PPGDevice objects, the application should implement the onPPGDeviceDiscovered method as part of PPGDeviceScannerListener.

The PPGDevice objects obtained through this method represent nearby PPG devices found by the scanner during the scan. These devices are potential candidates for establishing a session later, utilizing their deviceId field.

Dart
@override 
void onPPGDeviceDiscovered(PPGDevice ppgDevice) {
    // ppgDevice.deviceType -      The PPGDeviceType of the found device
    // ppgDevice.deviceId   -      The ID to use later when creating a PPG Device Session
}

@override
void onPPGDeviceScanFinished() {
    // Called when a scan is finished or stopped
}

Stopping a scan for PPG Devices

During a scan, it will automatically stop when the timeout period ends. Additionally, the application can manually stop the scan by calling the stop method.

Dart
scanner.stop();

When a scan is finished or stopped, the method onPPGDeviceScanFinished (part of PPGDeviceScannerListener) is called.

Dart
@override
void onPPGDeviceDiscovered(PPGDevice ppgDevice) {
    // ppgDevice.type     -      The PPGDeviceType of the found device
    // ppgDevice.deviceID -      The ID to use later when creating a PPG Device Session
}

@override 
void onPPGDeviceScanFinished() {
    // Called when a scan is finished or stopped
}