> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebellapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# my.onBluetoothDeviceFound

> Listen for newly discovered Bluetooth devices.

Use this API to listen for newly discovered Bluetooth devices during discovery. The callback triggers when new devices are found.

## Parameters

| Property | Type     | Required | Description                     |
| -------- | -------- | -------- | ------------------------------- |
| success  | Function | No       | Callback when devices are found |
| fail     | Function | No       | Callback on failure             |

## Success Callback Parameters

| Property | Type  | Description                          |
| -------- | ----- | ------------------------------------ |
| devices  | Array | List of all newly discovered devices |

## Device Object Properties

| Property     | Type       | Description                                                     |
| ------------ | ---------- | --------------------------------------------------------------- |
| deviceId     | String     | Device ID                                                       |
| name         | String     | Name of the Bluetooth device (some devices may not have a name) |
| deviceName   | String     | Name of the Bluetooth device                                    |
| localName    | String     | Name of the local device                                        |
| RSSI         | Number     | Received Signal Strength Indicator                              |
| advertisData | Hex String | Advertisement data of the device                                |

## Code Example

### Basic Usage

```javascript theme={null}
my.onBluetoothDeviceFound({
  success: (res) => {
    res.devices.forEach(device => {
      console.log('Found:', device.name, device.deviceId);
    });
  }
});
```

### Build Device List

```javascript theme={null}
Page({
  data: {
    devices: []
  },

  onLoad() {
    my.openBluetoothAdapter({
      success: () => {
        this.setupDeviceListener();
        this.startScan();
      }
    });
  },

  setupDeviceListener() {
    my.onBluetoothDeviceFound({
      success: (res) => {
        const { devices } = this.data;

        res.devices.forEach(newDevice => {
          const exists = devices.find(d => d.deviceId === newDevice.deviceId);
          if (!exists && newDevice.name) {
            devices.push(newDevice);
          }
        });

        this.setData({ devices });
      }
    });
  },

  startScan() {
    my.startBluetoothDevicesDiscovery();
  },

  onUnload() {
    my.offBluetoothDeviceFound();
    my.closeBluetoothAdapter();
  }
});
```

### Find Specific Device

```javascript theme={null}
Page({
  findDevice(targetName) {
    my.onBluetoothDeviceFound({
      success: (res) => {
        const target = res.devices.find(d => d.name === targetName);

        if (target) {
          my.stopBluetoothDevicesDiscovery();
          my.offBluetoothDeviceFound();
          this.connectToDevice(target);
        }
      }
    });

    my.startBluetoothDevicesDiscovery();
  },

  connectToDevice(device) {
    console.log('Connecting to:', device.name);
  }
});
```

<Tip>
  Remember to call `my.offBluetoothDeviceFound` when done to stop receiving device updates.
</Tip>

## Related APIs

<CardGroup cols={2}>
  <Card title="my.offBluetoothDeviceFound" icon="xmark" href="/jsapi/device/bluetooth/my.offBluetoothDeviceFound">
    Stop listening
  </Card>

  <Card title="my.startBluetoothDevicesDiscovery" icon="magnifying-glass" href="/jsapi/device/bluetooth/my.startBluetoothDevicesDiscovery">
    Start discovery
  </Card>
</CardGroup>
