Skip to main content
Use this API to disconnect from a connected Bluetooth Low Energy (BLE) device.

Parameters

PropertyTypeRequiredDescription
deviceIdStringYesDevice identifier
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Code Example

Basic Usage

my.disconnectBLEDevice({
  deviceId: 'XX:XX:XX:XX:XX:XX',
  success() {
    console.log('Disconnected from device');
  }
});

Disconnect with UI Update

Page({
  data: {
    connectedDevice: null
  },

  disconnect() {
    const { connectedDevice } = this.data;
    if (!connectedDevice) return;

    my.disconnectBLEDevice({
      deviceId: connectedDevice.deviceId,
      success: () => {
        this.setData({ connectedDevice: null });
        my.showToast({ content: 'Disconnected' });
      },
      fail: (err) => {
        my.showToast({ content: 'Failed to disconnect', type: 'fail' });
      }
    });
  }
});

Cleanup on Page Exit

Page({
  data: {
    deviceId: null
  },

  onUnload() {
    if (this.data.deviceId) {
      my.disconnectBLEDevice({
        deviceId: this.data.deviceId
      });
    }
    my.closeBluetoothAdapter();
  }
});
Always disconnect from BLE devices when leaving a page to free up the connection slot for other apps.

my.connectBLEDevice

Connect to device

my.getConnectedBluetoothDevices

Get connected devices