Mulai Menggunakan
Copy prompt pengaturan dengan langkah instalasi 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.
Instalasi
Bab berjudul “Instalasi”Kamu bisa menggunakan Pengaturan AI yang Dibantu untuk menginstal plugin. Tambahkan Capgo kemampuan ke alat AI kamu menggunakan perintah berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsKemudian 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 kamu lebih suka Pengaturan Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:
bun add @capgo/capacitor-bluetooth-low-energynpx cap syncImport
Section titled “Import”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';Mulai cepat
Section titled “Quick start”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });Contoh: shimWebBluetooth
Section titled “Example: shimWebBluetooth”import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();Contoh: isAvailable
Judul Bagian: Contoh: isAvailableimport { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();Kesulitan Umum
Judul Bagian: Kesulitan Umum- Izin: panggil
checkPermissions()lalurequestPermissions()ketika dibutuhkan. - Pengaturan: hapuskan pengaturan ketika layar tidak aktif.
- Inisialisasi sekali: jalankan setup selama aplikasi berjalan.
API Pengenalan
Judul Bagian “API Pengenalan”initialize
Judul Bagian “inisialisasi”Inisialisasi plugin BLE. Harus dipanggil sebelum metode lainnya.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });shimWebBluetooth
Judul Bagian “shimWebBluetooth”Pasang shim Web Bluetooth Capacitor pada navigator.bluetooth.
Panggil secara manual sebelum menggunakan Web Bluetooth API dari aplikasi native Capacitor.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();isAvailable
Judul Bagian “tersedia”Periksa jika Bluetooth tersedia pada perangkat.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();isEnabled
Judul Bagian “isEnabled”Periksa apakah Bluetooth diaktifkan di perangkat.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isEnabled();isLocationEnabled
Bagian berjudul “isLocationEnabled”Periksa apakah layanan lokasi telah diaktifkan (hanya untuk Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isLocationEnabled();openAppSettings
Periksa apakah layanan lokasi diaktifkan (hanya Android).Judul Bagian “openAppSettings”
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openAppSettings();openBluetoothSettings
Buka halaman pengaturan aplikasi.Buka halaman pengaturan Bluetooth (hanya untuk Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openBluetoothSettings();openLocationSettings
Judul Bagian ‘bukaPengaturanLokasi’Buka halaman pengaturan lokasi (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openLocationSettings();checkPermissions
Judul Bagian ‘periksaIzin’Periksa status izin saat ini.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.checkPermissions();requestPermissions
Section titled “requestPermissions”Minta izin Bluetooth.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.requestPermissions();startScan
Judul Bagian ‘mulaiSkanning’Mulai mencari perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startScan({ services: ['180D'], // Heart Rate Service timeout: 10000});stopScan
Judul Bagian “stopScan”Hentikan pencarian perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopScan();connect
Section titled “connect”Hubungkan ke Perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.connect({ deviceId: 'AA:BB:CC:DD:EE:FF' });disconnect
Judul Bagian “connect”Hubungkan ke perangkat BLE.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.disconnect({ deviceId: 'AA:BB:CC:DD:EE:FF' });createBond
Judul Bagian “disconnect”Buat koneksi dengan perangkat BLE (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.createBond({ deviceId: 'AA:BB:CC:DD:EE:FF' });isBonded
Judul Bagian ‘isBonded’Periksa apakah perangkat terikat (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bonded } = await BluetoothLowEnergy.isBonded({ deviceId: 'AA:BB:CC:DD:EE:FF' });discoverServices
Judul Bagian ‘discoverServices’Temukan layanan pada perangkat terhubung.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.discoverServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getServices
Judul Bagian ‘getServices’Temukan layanan yang telah ditemukan untuk perangkat.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { services } = await BluetoothLowEnergy.getServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getConnectedDevices
Judul Bagian ‘getConnectedDevices’Dapatkan daftar perangkat yang terhubung.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { devices } = await BluetoothLowEnergy.getConnectedDevices();readCharacteristic
Judul Bagian ‘baca Karakteristik’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
Judul Bagian ‘tulis Karakteristik’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
Judul Bagian ‘Mulai Notifikasi Karakteristik’Mulai 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
Judul Bagian ‘Hentikan Notifikasi Karakteristik’Hentikan notifikasi untuk karakteristik.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});readDescriptor
Judul Bagian “readDescriptor”Baca nilai deskriptor.
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'});Judul Bagian “writeDescriptor”
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
Tulis nilai ke deskriptor.Baca kekuatan sinyal RSSI dari perangkat yang terhubung.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { rssi } = await BluetoothLowEnergy.readRssi({ deviceId: 'AA:BB:CC:DD:EE:FF' });Ubah ukuran MTU (hanya untuk Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { mtu } = await BluetoothLowEnergy.requestMtu({ deviceId: 'AA:BB:CC:DD:EE:FF', mtu: 512});requestConnectionPriority
Judul Bagian: “requestConnectionPriority”Minta prioritas koneksi (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.requestConnectionPriority({ deviceId: 'AA:BB:CC:DD:EE:FF', priority: 'high'});startAdvertising
Judul Bagian: “startAdvertising”Mulai iklan sebagai perangkat perifer (server BLE).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startAdvertising({ name: 'MyDevice', services: ['180D']});stopAdvertising
Judul Bagian: “stopAdvertising”Berhenti iklan.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopAdvertising();startForegroundService
Judul Bagian: “startForegroundService”Mulai layanan latar depan untuk menjaga koneksi BLE di latar belakang (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startForegroundService({ title: 'BLE Connection', body: 'Maintaining connection...'});stopForegroundService
Judul Bagian “stopForegroundService”Hentikan layanan latar depan (hanya Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopForegroundService();Referensi Tipe
Section titled “Type Reference”InitializeOptions
Judul Bagian “Type Reference”Judul Bagian “InitializeOptions”
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
Opsi inisialisasi plugin.Judul Bagian “IsAvailableResult”
export interface IsAvailableResult { /** * Whether Bluetooth is available on the device. * * @since 1.0.0 */ available: boolean;}IsEnabledResult
Hasil metode isAvailable .Hasil metode isEnabled.
export interface IsEnabledResult { /** * Whether Bluetooth is enabled on the device. * * @since 1.0.0 */ enabled: boolean;}IsLocationEnabledResult
Bagian berjudul “IsLocationEnabledResult”Hasil metode 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”Pilihan untuk memulai skanning.
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 menghubungkan 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
Opsi Menghubungkan KembaliPilihan untuk melepaskan koneksi dari perangkat.
export interface DisconnectOptions { /** * The device ID to disconnect from. * * @since 1.0.0 */ deviceId: string;}CreateBondOptions
Bagian berjudul “Pengaturan Koneksi”Opsi untuk melepas koneksi dari perangkat.
export interface CreateBondOptions { /** * The device ID to bond with. * * @since 1.0.0 */ deviceId: string;}IsBondedOptions
Bagian berjudul “Pengaturan Ikatan”Opsi untuk membuat ikatan.
export interface IsBondedOptions { /** * The device ID to check. * * @since 1.0.0 */ deviceId: string;}IsBondedResult
Bagian berjudul “Pengaturan Status Ikatan”Hasil dari metode isBonded.
export interface IsBondedResult { /** * Whether the device is bonded. * * @since 1.0.0 */ bonded: boolean;}DiscoverServicesOptions
Bagian berjudul “Tentang Melayani Opsi”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 dihasilkan dari plugin’s src/definitions.ts. Jalankan ulang sinkronisasi ketika API publik berubah di atas.
Teruskan dari Mulai Berjalan
Bagian berjudul “Teruskan dari Mulai Berjalan”Jika Anda menggunakan Mulai Berjalan untuk merencanakan dashboard dan API operasi, hubungkannya dengan Menggunakan @capgo/capacitor-bluetooth-low-energy untuk kemampuan asli dalam Menggunakan @capgo/capacitor-bluetooth-low-energy, Ringkasan API untuk detail implementasi dalam Ringkasan API, Pendahuluan untuk detail implementasi dalam Pendahuluan, Kunci API untuk detail implementasi dalam Kunci API, dan Perangkat Untuk detail implementasi di Perangkat.