Skip to main content
Use this API to remove a listener registered with my.onBLECharacteristicValueChange. If no callback is provided, all listeners are removed.

Parameters

PropertyTypeRequiredDescription
callbackFunctionNoThe specific callback to remove. If omitted, all listeners are removed.

Code Example

Remove All Listeners

my.offBLECharacteristicValueChange();

Remove Specific Listener

Page({
  onLoad() {
    my.onBLECharacteristicValueChange(this.handleValueChange);
  },

  handleValueChange(res) {
    console.log('Value changed:', res.value);
  },

  onUnload() {
    my.offBLECharacteristicValueChange(this.handleValueChange);
  }
});

Complete BLE Cleanup

function cleanupBLE() {
  my.offBLECharacteristicValueChange();
  my.offBluetoothDeviceFound();
  my.offBluetoothAdapterStateChange();
  my.disconnectBLEDevice({ deviceId: currentDeviceId });
  my.closeBluetoothAdapter();
}

my.onBLECharacteristicValueChange

Listen for value changes

my.readBLECharacteristicValue

Trigger a read on a characteristic