This API is used via wx.stopBluetoothDevicesDiscovery(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Error code | Error Message | Description |
0 | ok | Normal |
-1 | already connect | Connected |
10000 | not init | Bluetooth Adapter Not Initialized |
10001 | not available | The current Bluetooth adapter is unavailable. |
10002 | no device | Specified Device Not Found |
10003 | connection fail | Connection failed. |
10004 | no service | Specified Service Not Found |
10005 | no characteristic | Specified characteristic not found |
10006 | no connection | The current connection has been disconnected. |
10007 | property not support | The current characteristic does not support this operation. |
10008 | system error | Exceptions Reported by All Other Systems |
10009 | system not support | Exclusive to Android system, and BLE is not supported on versions earlier than 4.3. |
10012 | operate time out | Connection timeout |
10013 | invalid_data | The connection deviceId is either null or incorrectly formatted. |
wx.stopBluetoothDevicesDiscovery({success (res) {console.log(res)}})
This API is used via wx.startBluetoothDevicesDiscovery(Object object).
Attribute | Type | Default value | Required | Description |
services | Array.<string> |
- | No | The list of UUIDs for the primary services of the Bluetooth devices to be searched (supporting 16/32/128 bit UUIDs). Some Bluetooth devices will broadcast their primary service's UUID. If this parameter is set, only Bluetooth devices broadcasting a primary service with the corresponding UUID will be searched. It is recommended to use this parameter to filter out other surrounding Bluetooth devices that do not need to be processed. |
allowDuplicatesKey | boolean | false | No | If or not allow to report the same device more than once. If repeat reporting is allowed, the wx.onBluetoothDeviceFound method will report the same device multiple times, but with different RSSI values. |
interval | number | 0 | No | Interval for reporting devices, in ms. 0 means that new devices are found and reported immediately, other values are reported according to the incoming interval. |
powerLevel | string | medium | No | The scanning mode. The higher the mode, the faster the scan and the greater the power consumption. Only Android host clients in V 7.0.12 and later versions support this, with valid values being: Low: Low power Medium: Moderate power High: High power |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Error code | Error Message | Description |
0 | ok | Normal |
-1 | already connect | Connected |
10000 | not init | Bluetooth Adapter Not Initialized |
10001 | not available | The current Bluetooth adapter is unavailable. |
10002 | no device | Specified Device Not Found |
10003 | connection fail | Connection failed. |
10004 | no service | Specified Service Not Found |
10005 | no characteristic | Specified characteristic not found |
10006 | no connection | The current connection has been disconnected. |
10007 | property not support | The current characteristic does not support this operation. |
10008 | system error | Exceptions Reported by All Other Systems |
10009 | system not support | Exclusive to Android system, and BLE is not supported on versions earlier than 4.3. |
10012 | operate time out | Connection timeout |
10013 | invalid_data | The connection deviceId is either null or incorrectly formatted. |
// Taking the Bluetooth smart light of the host client's hardware platform as an example, the UUID of the main service is FEE7. By passing in this parameter, only devices with a main service UUID of FEE7 will be searched for.wx.startBluetoothDevicesDiscovery({services: ['FEE7'],success (res) {console.log(res)}})
This API is used via wx.openBluetoothAdapter(Object object).
mode
should be specified.Attribute | Type | Valid Values and Descriptions | Default value | Required | Description |
mode | string | central: Host mode peripheral: Replica (peripheral device) mode | central | No | Bluetooth mode, which can function as a host/replica device, only required for iOS. |
success | function | - | - | No | Callback Function of Successful Interface Call |
fail | function | - | - | No | Callback Function of Failing Interface Call |
complete | function | - | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Error code | Error Message | Description |
0 | ok | Normal |
-1 | already connect | Connected |
10000 | not init | Bluetooth Adapter Not Initialized |
10001 | not available | The current Bluetooth adapter is unavailable. |
10002 | no device | Specified Device Not Found |
10003 | connection fail | Connection failed. |
10004 | no service | Specified Service Not Found |
10005 | no characteristic | Specified characteristic not found |
10006 | no connection | The current connection has been disconnected. |
10007 | property not support | The current characteristic does not support this operation. |
10008 | system error | Exceptions Reported by All Other Systems |
10009 | system not support | Exclusive to Android system, and BLE is not supported on versions earlier than 4.3. |
10012 | operate time out | Connection timeout |
10013 | invalid_data | The connection deviceId is either null or incorrectly formatted. |
Status code | Description |
0 | Unknown |
1 | Resetting |
2 | Not supported |
3 | Not authorized |
4 | Not enabled |
wx.openBluetoothAdapter({success (res) {console.log(res)}})
This API is used via wx.getConnectedBluetoothDevices(Object object).
Attribute | Type | Default value | Required | Description |
services | Array. | - | Yes | List of primary service UUIDs for the Bluetooth device (supporting 16/32/128 bit UUIDs) |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
devices | Array. | List of located devices |
Structure attributes | Type | Description |
name | string | Bluetooth device name, which may not be available for some devices. |
deviceId | string | Identifier used to distinguish devices |
Error code | Error Message | Description |
0 | ok | Normal |
-1 | already connect | Connected |
10000 | not init | Bluetooth Adapter Not Initialized |
10001 | not available | The current Bluetooth adapter is unavailable. |
10002 | no device | Specified Device Not Found |
10003 | connection fail | Connection failed. |
10004 | no service | Specified Service Not Found |
10005 | no characteristic | Specified characteristic not found |
10006 | no connection | The current connection has been disconnected. |
10007 | property not support | The current characteristic does not support this operation. |
10008 | system error | Exceptions Reported by All Other Systems |
10009 | system not support | Exclusive to Android system, and BLE is not supported on versions earlier than 4.3. |
10012 | operate time out | Connection timeout |
10013 | invalid_data | The connection deviceId is either null or incorrectly formatted. |
wx.getConnectedBluetoothDevices({services: ['FEE7'],success (res) {console.log(res)}})
This API is used via wx.getBluetoothDevices(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
devices | Array.<Object> | List of devices connected corresponding to the UUID |
Structure attributes | Type | Description |
name | string | Bluetooth device name, which may not be available for some devices. |
deviceId | string | Bluetooth Device ID |
RSSI | number | Signal strength of the current Bluetooth device, measured in dBm. |
advertisData | ArrayBuffer | ManufacturerData segment in the broadcast data segment of the current Bluetooth device |
advertisServiceUUIDs | Array.<string> | ServiceUUIDs data segment in the broadcast data segment of the current Bluetooth device |
localName | string | LocalName data segment in the broadcast data segment of the current Bluetooth device |
serviceData | Object | ServiceData segment in the broadcast data segment of the current Bluetooth device |
connectable | boolean | Connectivity status of the current Bluetooth device (not supported on Android 8.0 and earlier Android versions) |
// ArrayBuffer to 16 progress string examplefunction ab2hex(buffer) {var 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))}}})
This API is used via wx.getBluetoothAdapterState(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
discovering | boolean | Is search for device in progress? |
available | boolean | Whether the Bluetooth adapter is available. |
Error code | Error Message | Description |
0 | ok | Normal |
-1 | already connect | Connected |
10000 | not init | Bluetooth Adapter Not Initialized |
10001 | not available | The current Bluetooth adapter is unavailable. |
10002 | no device | Specified Device Not Found |
10003 | connection fail | Connection failed. |
10004 | no service | Specified Service Not Found |
10005 | no characteristic | Specified characteristic not found |
10006 | no connection | The current connection has been disconnected. |
10007 | property not support | The current characteristic does not support this operation. |
10008 | system error | Exceptions Reported by All Other Systems |
10009 | system not support | Exclusive to Android system, and BLE is not supported on versions earlier than 4.3. |
10012 | operate time out | Connection timeout |
10013 | invalid_data | The connection deviceId is either null or incorrectly formatted. |
wx.getBluetoothAdapterState({success (res) {console.log(res)}})
This API is used via wx.closeBluetoothAdapter(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Error code | Error Message | Description |
0 | ok | Normal |
-1 | already connect | Connected |
10000 | not init | Bluetooth Adapter Not Initialized |
10001 | not available | The current Bluetooth adapter is unavailable. |
10002 | no device | Specified Device Not Found |
10003 | connection fail | Connection failed. |
10004 | no service | Specified Service Not Found |
10005 | no characteristic | Specified characteristic not found |
10006 | no connection | The current connection has been disconnected. |
10007 | property not support | The current characteristic does not support this operation. |
10008 | system error | Exceptions Reported by All Other Systems |
10009 | system not support | Exclusive to Android system, and BLE is not supported on versions earlier than 4.3. |
10012 | operate time out | Connection timeout |
10013 | invalid_data | The connection deviceId is either null or incorrectly formatted. |
wx.closeBluetoothAdapter({success (res) {console.log(res)}})
This API is used via wx.onBluetoothDeviceFound(function listener).
Attribute | Type | Description |
devices | Array.<Object> | List of newly located devices |
Structure attributes | Type | Description |
name | string | Bluetooth device name, which may not be available for some devices. |
deviceId | string | Bluetooth Device ID |
RSSI | number | Signal strength of the current Bluetooth device, measured in dBm. |
advertisData | ArrayBuffer | ManufacturerData segment in the broadcast data segment of the current Bluetooth device |
advertisServiceUUIDs | Array.<string> | ServiceUUIDs data segment in the broadcast data segment of the current Bluetooth device |
localName | string | LocalName data segment in the broadcast data segment of the current Bluetooth device |
serviceData | Object | ServiceData segment in the broadcast data segment of the current Bluetooth device |
connectable | boolean | Connectivity status of the current Bluetooth device (not supported on Android 8.0 and earlier Android versions) |
// Example of converting ArrayBuffer to hexadecimal stringfunction ab2hex(buffer) {var hexArr = Array.prototype.map.call(new Uint8Array(buffer),function(bit) {return ('00' + bit.toString(16)).slice(-2)})return hexArr.join('');}wx.onBluetoothDeviceFound(function(res) {var devices = res.devices;console.log('new device list has founded')console.dir(devices)console.log(ab2hex(devices[0].advertisData))})
This API is used via wx.offBluetoothDeviceFound()
wx.offBluetoothDeviceFound()
This API is used via wx.onBluetoothAdapterStateChange(function listener).
Attribute | Type | Description |
available | boolean | Whether the Bluetooth adapter is available. |
discovering | boolean | Whether the Bluetooth adapter is in search mode. |
wx.onBluetoothAdapterStateChange(function (res) {console.log('adapterState changed, now is', res)})
This API is used via wx.offBluetoothAdapterStateChange().
wx.offBluetoothAdapterStateChange()
This API is used via wx.makeBluetoothPair(Object object).
Attribute | Type | Default value | Required | Description |
deviceId | string | - | Yes | Bluetooth Device ID |
pin | string | - | Yes | Pin code, in Base64 format. |
timeout | number | 20000 | No | Timeout duration, measured in milliseconds (ms). |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This API is used via wx.isBluetoothDevicePaired(Object object).
Attribute | Type | Default value | Required | Description |
deviceId | string | - | Yes | Bluetooth Device ID |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Was this page helpful?