HomeDocs
Skip to main content

dlt.writeBLECharacteristicValue

Introduction

Write data to a characteristic.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
serviceUUIDstringYesThe UUID of the device's service.
characteristicUUIDstringYesThe UUID of the service's characteristic.
valueArrayBufferYesThe binary value to write to the Bluetooth device's characteristic.
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
serviceUUIDstringThe UUID of the device's service.
characteristicUUIDstringThe UUID of the service's characteristic.
valuestringThe characteristic value.
statusstringStatus

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

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.

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