---
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 | - | `3.1.0` | Device ID |
| `timeoutMillis` | `number` | No | `15000` | `3.1.0` | Connection timeout Unit: milliseconds |
| `souceType` | `number` | No | `0` | `3.1.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. Succeeds if either the local or gateway path is available 1: App only: checks only whether the device is online locally and whether the local connection succeeds 2: Gateway only: checks only 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

#### Basic usage

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

const { connectBluetoothDevice } = device;

connectBluetoothDevice({
  devId: 'device_001',
  success: () => {
    console.log('connectBluetoothDevice success');
  },
  fail: (error) => {
    console.log('connectBluetoothDevice fail', error.errorMsg);
  },
});
```
