dlt.onBluetoothDeviceFound(function listener)
Introduction
Add a listener for the discovery of Bluetooth devices.
Usage Restrictions
This function must be registered before calling dlt.startBluetoothDevicesDiscovery.
Parameters
function listener
The listener function for Bluetooth devices being discovered.
Parameters
Object res
Property | Type | Description |
---|---|---|
address | string | The MAC address of the Bluetooth device |
name | string | The name of the Bluetooth device; some devices may not have a name |
RSSI | string | The received signal strength indication (RSSI) |
system_code | number | Returns when scanning fails |
Explanation of system_code
system_code | Description |
---|---|
1 | Fails to start scanning because a BLE scan with the same settings is already started by the app. |
2 | Fails to start scanning because the app cannot be registered. |
3 | Fails to start scanning due to an internal error. |
4 | Fails to start a power-optimized scan because this feature is not supported. |
5 | Fails to start scanning because it is out of hardware resources. |
6 | Fails to start scanning because the application tries to scan too frequently. |
Sample Code
dlt.onBluetoothDeviceFound(function (res) {
console.log(res);
});
In the sample code provided, dlt.onBluetoothDeviceFound
is used to add a listener for the discovery of Bluetooth devices. When a Bluetooth device is discovered, the provided listener function is called, and it logs information about the discovered device to the console.