# wx.getBluetoothDevices(Object object)
Start from base library version 1.1.0. Please remaining backward compatible.
with Promise style call: Supported
Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6
Gets all Bluetooth devices searched for while the Bluetooth module is active. Includes devices that are already connected to the machine.
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
success | function | no | Interface calls the successful callback function | |
fail | function | no | Interface calls failed callback functions | |
complete | function | no | Interface calls the end of the callback function (call success or failure will be executed) |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
devices | Array.<Object> | UUID List of connected devices |
res.devices Structure
attribute | type | Introductions |
---|---|---|
name | string | Bluetooth device name, which some devices may not have |
deviceId | string | Bluetooth Device id |
RSSI | number | Current Bluetooth Device Signal Strength, Unit dBm |
advertisData | ArrayBuffer | In the broadcast data segment of the current bluetooth device ManufacturerData Data segment. |
advertisServiceUUIDs | Array.<string> | In the broadcast data segment of the current bluetooth device ServiceUUIDs data segment |
localName | string | In the broadcast data segment of the current bluetooth device LocalName data segment |
serviceData | Object | In the broadcast data segment of the current bluetooth device ServiceData data segment |
# error
Error code | Error message | Introductions |
---|---|---|
0 | ok | normal |
-1 | already connect | Connected |
10000 | not init | Uninitialized Bluetooth adapter |
10001 | not available | The current Bluetooth adapter is not available |
10002 | No device | Specified device not found |
10003 | connection fail | Connection failure |
10004 | No service | Specified service not found |
10005 | No characteristic | Did not find the specified signature. |
10006 | No connection | Current connection disconnected |
10007 | property not support | Current feature does not support this operation |
10008 | system error | All other system reported anomalies |
10009 | system not support | Android System specific, system version below 4.3 Not supported WAS |
10012 | operate time out | Connection Timeout |
10013 | invalid_data | Connect deviceId Is empty or incorrectly formatted |
# sample code
// ArrayBuffer 16 Progress String Example
function ab2hex(buffer) {
where hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function(bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join('')
}
wx.getBluetoothDevices({
success: function (res) {
console.log(res)
if (res.devices[0]) {
console.log(ab2hex(res.devices[0].advertisData))
}
}
})
# Be careful
- The list of devices retrieved by this interface isAll Bluetooth devices searched during Bluetooth module active periodIf the process of using the Bluetooth module is not called in time wx.closeBluetoothAdapter Release the resources, there will be called the interface will return the previous Bluetooth use process to search the Bluetooth device, the device may not be around the user, can not be connected.