# wx.writeBLECharacteristicValue(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
Writes binary data to a Bluetooth low-power device characteristic value. Note: Features of the device must support write Before it can be successfully invoked.
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
deviceId | string | yes | Bluetooth Device id | |
serviceId | string | yes | Bluetooth Feature Corresponding Service UUID | |
characteristicId | string | yes | Bluetooth characteristic UUID | |
value | ArrayBuffer | yes | Binary Values for Bluetooth Device Features | |
success | function | no | Interface calls the successful callback function | |
fail | function | no | Interface calls failed callback functions | |
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# 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. |
初始值 | 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 |
# Be careful
- Multiple parallel calls have the possibility of write failure.
- Mini Programs do not limit the size of the packet to be written, but the system and Bluetooth devices will limit Bluetooth 4.0 Single transmission data size, more than the maximum number of bytes will occur after the write error, it is recommended that each write no more than 20 Bytes.
- If a single write of data is too long, iOS There are situations on the system where there will be no callbacks (including error callbacks).
- On Android, after calling wx.notifyBLECharacteristicValueChange This interface is invoked immediately after success, which can occur on some models 10008 System error
# sample code
// Send a 0x00 hexadecimal data to a Bluetooth device
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 0)
wx.writeBLECharacteristicValue({
// Here. deviceId Need to getBluetoothDevices or onBluetoothDeviceFound Get in interface
deviceId,
// Here. serviceId Need to getBLEDeviceServices Get in interface
serviceId,
// Here. characteristicId Need to getBLEDeviceCharacteristics Get in interface
characteristicId,
// The value here is the ArrayBuffer type
value: buffer,
success (res) {
console.log('writeBLECharacteristicValue success', res.errMsg)
}
})