Bluetooth API FAQ
Q: Does calling my.writeBLECharacteristicValue return a null object?
A: No. This API call returns the value that was successfully written.
Q: Why does my listener not work when I call my.onBLECharacteristicValueChange? Do I have to write a value first before I can listen for changes?
A: Yes, you do. You must write a value before you can listen for changes with this API. To prevent multiple callbacks for a single event, call the off method to disable previous event listeners before you call the on method to register a new one.
Q: Why do I get a 10014 error when I call my.writeBLECharacteristicValue?
A: The 10014 error occurs because the data you sent is empty or in an incorrect format. Check the data that you are writing and check for errors in the hexadecimal conversion.
Q: When I write a characteristic value by calling my.writeBLECharacteristicValue, can I use a hexadecimal array?
A: No, you cannot. You must use a hexadecimal string to write the characteristic value. The string must be 20 bytes or less.
Q: What is the format of the deviceId returned by Android and iOS?
A:
Android returns the Bluetooth MAC address. For example:
11:22:33:44:55:66.iOS returns the Bluetooth UUID. For example:
00000000-0000-0000-0000-00000000****.
Q: Why can't I find any devices when I call the my.startBluetoothDevicesDiscovery API?
A: Make sure the device is broadcasting. If you pass services to the API, make sure the device's broadcast data includes the service UUID.
Q: How do I fix a failed device connection?
A: Make sure that the deviceId you pass is correct and that the device signal is strong enough. A weak signal can cause connection failures.
Q: How do I fix failed data read or write operations?
A:
Make sure that the
deviceId,serviceId, andcharacteristicIdare in the correct format.Make sure the device is connected. You can call
my.onBLEConnectionStateChangedto listen for connection state changes or callmy.getConnectedBluetoothDevicesto retrieve a list of connected devices.You can call the write method while the connection is active.
Check that the
characteristicIdbelongs to the specifiedservice.This feature value is read-write.
Q: How do I receive data notifications?
A:
Make sure you have called the
my.notifyBLECharacteristicValueChangemethod with the correct parameters.Make sure the characteristic for the specified
characteristicIdsupports thenotifyorindicateoperation.Make sure the hardware has sent a notification.
Make sure to call the
my.notifyBLECharacteristicValueChangemethod after the connection is established.
Q: Why is my event callback invoked multiple times?
A: This happens because you have registered a listener for the same event multiple times. To fix this, call the off method to disable the previous event listener before you call the on method to register a new one.