---
name: "connectBluetoothDevice"
mode: "kit"
versionRequirements:
  - { name: "DeviceKit", version: "3.1.0" }
  - { name: "@ray-js/ray", version: "0.8.0" }
platform:
  - "iOS"
  - "Android"
async: true
---

## connectBluetoothDevice

> [VERSION] DeviceKit >= 3.1.0 | @ray-js/ray >= 0.8.0

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Aggregated Bluetooth connection API; supports ble, ble in dual-mode, beacon, mesh, and mesh single-live-wire connections.

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `devId` | `string` | Yes | - | - | Device ID |
| `timeoutMillis` | `number` | No | `15000` | - | Connection timeout Unit: milliseconds |
| `souceType` | `number` | No | `0` | - | Source type If it's an automatic connection from a panel, pass 1; otherwise the default is 0 for a manual connection |
| `connectType` | `number` | No | `0` | `3.1.2` | Bluetooth connection mode (default: 0) 0: Gateway and app. Default mode; effective if either the local or gateway path is available. 1: App only. Only checks whether the device is locally online and whether the local connection succeeds. 2: Gateway only. Only checks whether the gateway is online and whether the gateway connection succeeds. |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `() => void` | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Examples

```tsx
import { device } from '@ray-js/ray'

device.connectBluetoothDevice({
  devId: "xx",
  timeoutMillis: 15000,
  souceType: 0,
  connectType: 0,
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
