my.writeBLECharacteristicValue
Use this API to write data to Bluetooth Low Energy (BLE) device characteristics.
Instructions:
- The device characteristics must support writing to use this API. See properties in my.getBLEDeviceCharacteristics for details.
- The written binary data needs Hex coding.
Note:
Currently simulation in IDE is not supported. Please debug in production environment.
Sample Code
copy
my.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: 'fffe',
success: (res) => {
console.log(res)
},
fail:(res) => {
},
complete: (res)=>{
}
});Parameters
| Property | Type | Required | Description |
| deviceId | String | Yes | The Bluetooth device ID. |
| serviceId | String | Yes | The UUID of the service corresponding to a Bluetooth characteristic. |
| characteristicId | String | Yes | The Bluetooth characteristic UUID. |
| value | Hex String | Yes | The value corresponding to the Bluetooth device characteristic, which is a hexadecimal string, limited to 20 bytes. |
| 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 used when the API call is completed. This function is always executed no matter the call succeeds or fails. |