HomeDocs
Skip to main content

dlt.startBluetoothDevicesDiscovery

Introduction

Start scanning for Bluetooth devices.

Usage Restrictions

  1. Prerequisite: Initialize the Bluetooth module using dlt.openBluetoothAdapter.
  2. After discovering devices, call dlt.stopBluetoothDevicesDiscovery to stop the scan.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
serviceUUIDSstring[]YesA list of UUIDs of the main services of Bluetooth devices to search for (supports 16/32/128-bit UUIDs). Some Bluetooth devices broadcast the UUID of their main service. If you set this parameter, the scan will only search for Bluetooth devices that advertise the specified UUIDs in their broadcast packets. It is recommended to use this parameter to filter out other Bluetooth devices that do not need to be processed.
powerLevelnumberNoScanning level. The higher the level, the more frequently the scan occurs, and the more power is consumed.
successfunctionNoThe callback function for a successful API call.
failfunctionNoThe callback function for a failed API call.
completefunctionNoThe callback function that is called when the API call ends (whether it succeeds or fails).

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue - Success

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
successstringfalse - Failure
errCodestringError code

Explanation of Error Codes

Error CodeDescription
-1Failed
0Normal
10000Bluetooth adapter uninitialized
10001Bluetooth not available
10002Device not found
10003Connection failed
10004Already connected
10005Characteristic not found
10006Descriptor not found
10007Location access required
10008System reports an exception
10013Invalid data
10014Permission not granted
10015Adapter already initialized

Sample Code

dlt.startBluetoothDevicesDiscovery({
serviceUUIDS: [],
powerLevel: 1,
success: function (res) {
console.log('success', res);
dlt.stopBluetoothDevicesDiscovery();
},
});

In the sample code provided, dlt.startBluetoothDevicesDiscovery is used to start scanning for Bluetooth devices. It specifies an empty array for serviceUUIDS, meaning it will scan for all Bluetooth devices. When the operation is successful, the success callback function is called, and it logs the result to the console. It also calls dlt.stopBluetoothDevicesDiscovery to stop the scan when the operation succeeds.

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.