Panduan Memulai
Salin prompt setup yang berisi langkah install dan panduan markdown lengkap untuk plugin ini.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-bluetooth-low-energy`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/bluetooth-low-energy/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Anda bisa menggunakan AI-Assisted Setup kami untuk menginstal plugin ini. Tambahkan skill Capgo ke tool AI Anda dengan command berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsLalu gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-bluetooth-low-energy` plugin in my project.Jika Anda lebih memilih Manual Setup, instal plugin dengan menjalankan perintah berikut dan ikuti petunjuk khusus platform di bawah ini:
bun add @capgo/capacitor-bluetooth-low-energynpx cap syncimport { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';Mulai cepat
Bagian berjudul “Mulai cepat”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });Contoh: shimWebBluetooth
Bagian berjudul “Contoh: shimWebBluetooth”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();Contoh: isAvailable
Bagian berjudul “Contoh: isAvailable”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();Kesalahan umum
Bagian berjudul “Kesalahan umum”- Izin: panggil
checkPermissions()kemudianrequestPermissions()saat dibutuhkan. - Listener: hapus handle saat screen unmount.
- Inisialisasi sekali saja: jalankan setup saat app bootstrap.
Ringkasan API
Bagian berjudul “Ikhtisar API”initialize
Bagian berjudul “initialize”Inisialisasi plugin BLE. Harus dipanggil sebelum method lainnya.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });shimWebBluetooth
Bagian berjudul “shimWebBluetooth”Instal Capacitor Web Bluetooth shim pada navigator.bluetooth.
Panggil ini secara manual sebelum menggunakan Web Bluetooth API dari native app Capacitor.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();isAvailable
Bagian berjudul “isAvailable”Cek apakah Bluetooth tersedia di perangkat.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();isEnabled
Bagian berjudul “isEnabled”Cek apakah Bluetooth aktif di perangkat.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isEnabled();isLocationEnabled
Bagian berjudul “isLocationEnabled”Cek apakah layanan lokasi aktif (khusus Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isLocationEnabled();openAppSettings
Bagian berjudul “openAppSettings”Buka halaman pengaturan aplikasi.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openAppSettings();openBluetoothSettings
Bagian berjudul “openBluetoothSettings”Buka halaman pengaturan Bluetooth (khusus Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openBluetoothSettings();openLocationSettings
Bagian berjudul “openLocationSettings”Buka halaman pengaturan lokasi (khusus Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openLocationSettings();checkPermissions
Bagian berjudul “checkPermissions”Periksa status izin saat ini.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.checkPermissions();requestPermissions
Bagian berjudul “requestPermissions”Minta izin Bluetooth.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.requestPermissions();startScan
Bagian berjudul “startScan”Mulai scan perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startScan({ services: ['180D'], // Heart Rate Service timeout: 10000});stopScan
Bagian berjudul “stopScan”Hentikan scan perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopScan();connect
Bagian berjudul “connect”Hubungkan ke perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.connect({ deviceId: 'AA:BB:CC:DD:EE:FF' });disconnect
Bagian berjudul “disconnect”Putuskan koneksi dari perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.disconnect({ deviceId: 'AA:BB:CC:DD:EE:FF' });createBond
Bagian berjudul “createBond”Buat bonding dengan perangkat BLE (khusus Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.createBond({ deviceId: 'AA:BB:CC:DD:EE:FF' });isBonded
Bagian berjudul “isBonded”Cek apakah perangkat sudah bonded (khusus Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bonded } = await BluetoothLowEnergy.isBonded({ deviceId: 'AA:BB:CC:DD:EE:FF' });discoverServices
Bagian berjudul “discoverServices”Temukan service pada perangkat yang terhubung.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.discoverServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getServices
Bagian berjudul “getServices”Ambil daftar service yang ditemukan untuk perangkat.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { services } = await BluetoothLowEnergy.getServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getConnectedDevices
Bagian berjudul “getConnectedDevices”Dapatkan daftar perangkat yang terhubung.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { devices } = await BluetoothLowEnergy.getConnectedDevices();readCharacteristic
Bagian berjudul “readCharacteristic”Baca nilai karakteristik.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { value } = await BluetoothLowEnergy.readCharacteristic({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});writeCharacteristic
Bagian berjudul “writeCharacteristic”Tulis nilai ke karakteristik.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.writeCharacteristic({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A39', value: [0x01]});startCharacteristicNotifications
Bagian berjudul “startCharacteristicNotifications”Aktifkan notifikasi untuk karakteristik.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});stopCharacteristicNotifications
Bagian berjudul “stopCharacteristicNotifications”Hentikan notifikasi untuk sebuah characteristic.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});readDescriptor
Bagian berjudul “readDescriptor”Baca nilai descriptor.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { value } = await BluetoothLowEnergy.readDescriptor({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37', descriptor: '2902'});writeDescriptor
Bagian berjudul “writeDescriptor”Tulis nilai ke sebuah descriptor.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.writeDescriptor({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37', descriptor: '2902', value: [0x01, 0x00]});readRssi
Bagian berjudul “readRssi”Baca RSSI (kekuatan sinyal) dari perangkat yang terhubung.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { rssi } = await BluetoothLowEnergy.readRssi({ deviceId: 'AA:BB:CC:DD:EE:FF' });requestMtu
Bagian berjudul “requestMtu”Minta perubahan ukuran MTU (Android saja).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { mtu } = await BluetoothLowEnergy.requestMtu({ deviceId: 'AA:BB:CC:DD:EE:FF', mtu: 512});requestConnectionPriority
Bagian berjudul “requestConnectionPriority”Minta prioritas koneksi (Android saja).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.requestConnectionPriority({ deviceId: 'AA:BB:CC:DD:EE:FF', priority: 'high'});startAdvertising
Bagian berjudul “startAdvertising”Mulai advertising sebagai peripheral (BLE server).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startAdvertising({ name: 'MyDevice', services: ['180D']});stopAdvertising
Bagian berjudul “stopAdvertising”Hentikan advertising.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopAdvertising();startForegroundService
Bagian berjudul “startForegroundService”Jalankan foreground service untuk menjaga koneksi BLE tetap aktif di background (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startForegroundService({ title: 'BLE Connection', body: 'Maintaining connection...'});stopForegroundService
Bagian berjudul “stopForegroundService”Hentikan foreground service (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopForegroundService();Referensi Tipe
Bagian berjudul “Referensi Tipe”InitializeOptions
Bagian berjudul “InitializeOptions”Opsi inisialisasi untuk plugin.
export interface InitializeOptions { /** * The mode to initialize the plugin in. * - 'central': Act as a BLE central (client) * - 'peripheral': Act as a BLE peripheral (server) * * @default 'central' * @since 1.0.0 */ mode?: 'central' | 'peripheral';}IsAvailableResult
Bagian berjudul “IsAvailableResult”Hasil dari method isAvailable.
export interface IsAvailableResult { /** * Whether Bluetooth is available on the device. * * @since 1.0.0 */ available: boolean;}IsEnabledResult
Bagian berjudul “IsEnabledResult”Hasil dari method isEnabled.
export interface IsEnabledResult { /** * Whether Bluetooth is enabled on the device. * * @since 1.0.0 */ enabled: boolean;}IsLocationEnabledResult
Bagian berjudul “IsLocationEnabledResult”Hasil dari method isLocationEnabled.
export interface IsLocationEnabledResult { /** * Whether location services are enabled on the device. * * @since 1.0.0 */ enabled: boolean;}PermissionStatus
Bagian berjudul “PermissionStatus”Status izin untuk Bluetooth dan lokasi.
export interface PermissionStatus { /** * Bluetooth permission status. * * @since 1.0.0 */ bluetooth: PermissionState;
/** * Location permission status (Android only). * * @since 1.0.0 */ location: PermissionState;}StartScanOptions
Bagian berjudul “StartScanOptions”Opsi untuk memulai scan.
export interface StartScanOptions { /** * List of service UUIDs to filter by. * Only devices advertising these services will be returned. * * @since 1.0.0 */ services?: string[];
/** * Scan timeout in milliseconds. * Set to 0 for no timeout. * * @default 0 * @since 1.0.0 */ timeout?: number;
/** * Whether to allow duplicate scan results. * * @default false * @since 1.0.0 */ allowDuplicates?: boolean;}ConnectOptions
Bagian berjudul “ConnectOptions”Opsi untuk terhubung ke perangkat.
export interface ConnectOptions { /** * The device ID (MAC address on Android, UUID on iOS). * * @since 1.0.0 */ deviceId: string;
/** * Whether to automatically connect when the device becomes available. * * @default false * @since 1.0.0 */ autoConnect?: boolean;}DisconnectOptions
Bagian berjudul “DisconnectOptions”Opsi untuk memutus koneksi dari perangkat.
export interface DisconnectOptions { /** * The device ID to disconnect from. * * @since 1.0.0 */ deviceId: string;}CreateBondOptions
Bagian berjudul “CreateBondOptions”Opsi untuk membuat bond.
export interface CreateBondOptions { /** * The device ID to bond with. * * @since 1.0.0 */ deviceId: string;}IsBondedOptions
Bagian berjudul “IsBondedOptions”Opsi untuk memeriksa status bond.
export interface IsBondedOptions { /** * The device ID to check. * * @since 1.0.0 */ deviceId: string;}IsBondedResult
Bagian berjudul “IsBondedResult”Hasil dari metode isBonded.
export interface IsBondedResult { /** * Whether the device is bonded. * * @since 1.0.0 */ bonded: boolean;}DiscoverServicesOptions
Bagian berjudul “DiscoverServicesOptions”Opsi untuk menemukan layanan.
export interface DiscoverServicesOptions { /** * The device ID to discover services on. * * @since 1.0.0 */ deviceId: string;}Sumber Kebenaran
Bagian berjudul “Sumber Kebenaran”Halaman ini dibuat dari plugin src/definitions.ts. Jalankan ulang sync saat API publik berubah di upstream.
Lanjutkan dari Getting Started
Bagian berjudul “Lanjutkan dari Getting Started”Jika Anda menggunakan Panduan Memulai untuk merencanakan operasi dashboard dan API, hubungkan dengan Menggunakan @capgo/capacitor-bluetooth-low-energy untuk kemampuan native di Menggunakan @capgo/capacitor-bluetooth-low-energy, Ringkasan API untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Introduction, Kunci API untuk detail implementasi di API Keys, dan Perangkat untuk detail implementasi di Devices.