dlt.writeBLECharacteristicValue
Introduction
Write data to a characteristic.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
serviceUUID | string | Yes | The UUID of the device's service. | |
characteristicUUID | string | Yes | The UUID of the service's characteristic. | |
value | ArrayBuffer | Yes | The binary value to write to the Bluetooth device's characteristic. | |
success | function | No | The callback function for a successful API call. | |
fail | function | No | The callback function for a failed API call. | |
complete | function | No | The callback function that is called when the API call ends (whether it succeeds or fails). |
object.success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true - Success |
serviceUUID | string | The UUID of the device's service. |
characteristicUUID | string | The UUID of the service's characteristic. |
value | string | The characteristic value. |
status | string | Status |
object.fail Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | false - Failure |
errCode | string | Error code |
Explanation of Error Codes
Error Code | Description |
---|---|
-1 | Failed |
0 | Normal |
10000 | Bluetooth adapter uninitialized |
10001 | Bluetooth not available |
10002 | Device not found |
10003 | Connection failed |
10004 | Already connected |
10005 | Characteristic not found |
10006 | Descriptor not found |
10007 | Location access required |
10008 | System reports an exception |
10013 | Invalid data |
10014 | Permission not granted |
10015 | Adapter already initialized |
Sample Code
let buffer = new ArrayBuffer(1);
dlt.writeBLECharacteristicValue({
serviceUUID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
characteristicUUID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
value: buffer,
success: function (res) {
console.log(res);
},
complete: function (res) {
console.log(res);
},
fail: function (res) {
console.log(res);
},
});
In the sample code provided, dlt.writeBLECharacteristicValue
is used to write data to a Bluetooth device's characteristic. You need to provide the service UUID, characteristic UUID, and the binary value to write. When the operation is successful, the success callback function is called, and it logs the result to the console.