Appearance
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 using the usePPGDeviceScanner
hook. In the following sample, a scanner, searching for PPGDeviceType.POLAR
, is created.
TypeScript
import {
usePPGDeviceScanner
} from 'binah-react-native-sdk';
const {startScan, stopScan, isScanning, discoveredPPGDevice} = usePPGDeviceScanner(PPGDeviceType.POLAR);
Starting a scan for PPG Devices
To initiate a scan, call the startScan
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 startScan
will first stop the current scan before starting a new one.
When a scan is finished or stopped, the state of isScanning
, which is returned from the usePPGDeviceScanner
hook, will change to false
In the following example, startScan
is called with a timeoutDuration
of 30 seconds.
TypeScript
import {
usePPGDeviceScanner
} from 'binah-react-native-sdk';
const {
startScan,
stopScan,
isScanning,
discoveredPPGDevice
} = usePPGDeviceScanner(PPGDeviceType.POLAR);
const startScanClicked = useCallback(() => {
const scanTimeout = 30;
startScan(scanTimeout);
}, [])
Receiving results during a scan
To receive PPGDevice
objects, the application should watch the state of discoveredPPGDevice
, which is returned from the usePPGDeviceScanner
hook.
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.
TypeScript
import {
usePPGDeviceScanner
} from 'binah-react-native-sdk';
const {
startScan,
stopScan,
isScanning,
discoveredPPGDevice
} = usePPGDeviceScanner(PPGDeviceType.POLAR);
React.useEffect(() => {
if (!discoveredPPGDevice) {
console.log(`PPG Device discovered ${discoveredPPGDevice.deviceId}`)
}
}, [discoveredPPGDevice]);
Note
Please note that devices found during the scan do not guarantee a successful session establishment. Certain factors, such as the device having a version lower than the allowed minimum in the SDK, can cause a session to fail.
For more information on potential errors during session establishment, refer to the Alerts List.
Stopping a scan for PPG Devices
A scan will automatically stop when the timeout period ends. Additionally, the application can manually stop the scan by calling the stopScan
method, which is returned from the usePPGDeviceScanner
hook.
TypeScript
import {
usePPGDeviceScanner
} from 'binah-react-native-sdk';
const {
startScan,
stopScan,
isScanning,
discoveredPPGDevice
} = usePPGDeviceScanner(PPGDeviceType.POLAR);
const stopScanClicked = useCallback(() => {
stopScan();
}, [])
When a scan is finished or stopped, the state of isScanning
, which is returned from the usePPGDeviceScanner
hook, will change to false
TypeScript
import {
usePPGDeviceScanner
} from 'binah-react-native-sdk';
const {
startScan,
stopScan,
isScanning,
discoveredPPGDevice
} = usePPGDeviceScanner(PPGDeviceType.POLAR);
React.useEffect(() => {
if (!isScanning) {
console.log(`PPG Device discovery completed`)
}
}, [isScanning]);