Getting Started
Eine Setup-Anleitung mit den Installations-Schritten und der vollständigen Markdown-Guideline für diesen Plugin kopieren.
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.
Installieren
Abschnitt mit dem Titel „Installieren“Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie den Capgo-Fähigkeiten Ihrer AI-Werkzeug mit der folgenden Befehl hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsVerwenden Sie dann den folgenden Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-bluetooth-low-energy` plugin in my project.Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und folgen Sie den unten angegebenen Plattform-spezifischen Anweisungen:
bun add @capgo/capacitor-bluetooth-low-energybunx cap syncImportieren
Abschnitt mit dem Titel „Import“import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';API Übersicht
Abschnitt mit dem Titel „API Übersicht“initialize
Abschnitt mit dem Titel „initialize“Die BLE-Plugin initialisieren. Muss vor der Verwendung jeder anderen Methode aufgerufen werden.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });shimWebBluetooth
Abschnitt mit dem Titel „shimWebBluetooth“Installieren Sie das Capacitor Web Bluetooth Shim auf navigator.bluetooth.
Rufen Sie diese Funktion manuell auf, bevor Sie das Web Bluetooth API aus einer Capacitor nativen App verwenden.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();isAvailable
Abschnitt mit dem Titel „isAvailable“Überprüfen Sie, ob Bluetooth auf dem Gerät verfügbar ist.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();isEnabled
Abschnitt mit dem Titel “isEnabled”Überprüfen Sie, ob Bluetooth auf dem Gerät aktiviert ist.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isEnabled();isLocationEnabled
Abschnitt mit dem Titel “isLocationEnabled”Überprüfen Sie, ob die Standortdienste auf dem Gerät (nur Android) aktiviert sind.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isLocationEnabled();openAppSettings
Abschnitt mit dem Titel “openAppSettings”Öffnen Sie die App-Einstellungen.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openAppSettings();openBluetoothSettings
Abschnitt mit dem Titel “openBluetoothSettings”Öffnen Sie die Bluetooth-Einstellungen-Seite (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openBluetoothSettings();openLocationSettings
Abschnitt mit dem Titel “openLocationSettings”Öffnen Sie die Standorteinstellungen-Seite (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openLocationSettings();checkPermissions
Abschnitt mit dem Titel “checkPermissions”Überprüfen Sie den aktuellen Zustand der Berechtigungen.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.checkPermissions();requestPermissions
Abschnitt mit dem Titel “requestPermissions”Berechtigungen für Bluetooth anfordern.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bluetooth, location } = await BluetoothLowEnergy.requestPermissions();startScan
Abschnitt mit dem Titel “startScan”Starten Sie die Suche nach BLE-Geräten.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startScan({ services: ['180D'], // Heart Rate Service timeout: 10000});Beenden Sie die Suche nach BLE-Geräten.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopScan();Verbinden Sie sich mit einem BLE-Gerät.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.connect({ deviceId: 'AA:BB:CC:DD:EE:FF' });disconnect
Abschnitt mit dem Titel “disconnect”Trennen Sie sich von einem BLE-Gerät.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.disconnect({ deviceId: 'AA:BB:CC:DD:EE:FF' });createBond
Abschnitt mit dem Titel “createBond”Erstelle eine Verbindung mit einem BLE-Gerät (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.createBond({ deviceId: 'AA:BB:CC:DD:EE:FF' });Überprüfe, ob ein Gerät verbunden ist (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { bonded } = await BluetoothLowEnergy.isBonded({ deviceId: 'AA:BB:CC:DD:EE:FF' });discoverServices
Abschnitt mit dem Titel „discoverServices“Entdecke Dienste auf einem verbundenen Gerät.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.discoverServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getServices
Abschnitt mit dem Titel „getServices“Hol dir die entdeckten Dienste für ein Gerät.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { services } = await BluetoothLowEnergy.getServices({ deviceId: 'AA:BB:CC:DD:EE:FF' });getConnectedDevices
Abschnitt mit dem Titel „getConnectedDevices“Eine Liste der verbundenen Geräte erhalten.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { devices } = await BluetoothLowEnergy.getConnectedDevices();readCharacteristic
Abschnitt mit dem Titel “readCharacteristic”Ein Charakteristikwert lesen.
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
Abschnitt mit dem Titel “writeCharacteristic”Ein Wert auf eine Charakteristik schreiben.
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
Abschnitt mit dem Titel “startCharacteristicNotifications”Benachrichtigungen für eine Charakteristik starten.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});stopCharacteristicNotifications
Abschnitt mit dem Titel “stopCharacteristicNotifications”Benachrichtigungen für eine Eigenschaft stoppen.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopCharacteristicNotifications({ deviceId: 'AA:BB:CC:DD:EE:FF', service: '180D', characteristic: '2A37'});readDescriptor
Abschnitt mit dem Titel “readDescriptor”Ein Wert einer Beschreibung lesen.
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
Abschnitt mit dem Titel “writeDescriptor”Ein Wert in einer Beschreibung schreiben.
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]});Den RSSI-Wert (Signalstärke) eines verbundenen Geräts lesen.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { rssi } = await BluetoothLowEnergy.readRssi({ deviceId: 'AA:BB:CC:DD:EE:FF' });requestMtu
Abschnitt mit dem Titel “requestMtu”Anfrage MTU-Größe ändern (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { mtu } = await BluetoothLowEnergy.requestMtu({ deviceId: 'AA:BB:CC:DD:EE:FF', mtu: 512});requestConnectionPriority
Abschnitt mit dem Titel „requestConnectionPriority“Verbindungspriorität anfordern (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.requestConnectionPriority({ deviceId: 'AA:BB:CC:DD:EE:FF', priority: 'high'});startAdvertising
Abschnitt mit dem Titel „startAdvertising“Als BLE-Server als Peripherie starten.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startAdvertising({ name: 'MyDevice', services: ['180D']});stopAdvertising
Abschnitt mit dem Titel „stopAdvertising“Werbung beenden.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopAdvertising();startForegroundService
Abschnitt mit dem Titel „startForegroundService“Starten Sie einen Hintergrunddienst, um BLE-Verbindungen im Hintergrund aufrechtzuerhalten (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.startForegroundService({ title: 'BLE Connection', body: 'Maintaining connection...'});stopForegroundService
Abschnitt mit dem Titel “stopForegroundService”Stoppen Sie den Hintergrunddienst (nur Android).
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.stopForegroundService();Typenverweis
Abschnitt mit dem Titel “Type Reference”InitializeOptions
Abschnitt mit dem Titel “InitializeOptions”Initialisierungsoptionen für das 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
Abschnitt mit dem Titel “IsAvailableResult”Ergbnis der isAvailable-Methode.
export interface IsAvailableResult { /** * Whether Bluetooth is available on the device. * * @since 1.0.0 */ available: boolean;}IsEnabledResult
Abschnitt mit dem Titel „IsEnabledResult“Ergibt das Ergebnis der Methode isEnabled.
export interface IsEnabledResult { /** * Whether Bluetooth is enabled on the device. * * @since 1.0.0 */ enabled: boolean;}IsLocationEnabledResult
Abschnitt mit dem Titel „IsLocationEnabledResult“Ergibt das Ergebnis der Methode isLocationEnabled.
export interface IsLocationEnabledResult { /** * Whether location services are enabled on the device. * * @since 1.0.0 */ enabled: boolean;}PermissionStatus
Abschnitt mit dem Titel „PermissionStatus“Zustand der Genehmigung für Bluetooth und Standort.
export interface PermissionStatus { /** * Bluetooth permission status. * * @since 1.0.0 */ bluetooth: PermissionState;
/** * Location permission status (Android only). * * @since 1.0.0 */ location: PermissionState;}StartScanOptions
Abschnitt mit dem Titel „StartScanOptions“Optionen für den Start einer Scan-Suche.
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
Abschnitt mit dem Titel “ConnectOptions”Optionen für die Verbindung zu einem Gerät.
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
Abschnitt mit dem Titel “DisconnectOptions”Optionen für die Trennung von einem Gerät.
export interface DisconnectOptions { /** * The device ID to disconnect from. * * @since 1.0.0 */ deviceId: string;}CreateBondOptions
Abschnitt mit dem Titel “CreateBondOptions”Optionen für die Erstellung eines Bündels.
export interface CreateBondOptions { /** * The device ID to bond with. * * @since 1.0.0 */ deviceId: string;}IsBondedOptions
Abschnitt mit dem Titel “IsBondedOptions”Optionen für die Überprüfung des Bündelstatus.
export interface IsBondedOptions { /** * The device ID to check. * * @since 1.0.0 */ deviceId: string;}IsBondedResult
Abschnitt mit dem Titel „IsBondedResult“Ergebnis der Methode isBonded.
export interface IsBondedResult { /** * Whether the device is bonded. * * @since 1.0.0 */ bonded: boolean;}DiscoverServicesOptions
Abschnitt mit dem Titel „DiscoverServicesOptions“Optionen für die Entdeckung von Diensten.
export interface DiscoverServicesOptions { /** * The device ID to discover services on. * * @since 1.0.0 */ deviceId: string;}Quelle der Wahrheit
Abschnitt mit dem Titel „Source Of Truth“Diese Seite wird aus dem Plugin generiert. src/definitions.tsRe-run the sync wenn die öffentliche API sich im Hintergrund ändert.
Weiter von Getting Started
Abschnitt mit dem Titel „Weitermachen von Getting Started“Wenn Sie " Getting Started um das Dashboard und die API-Operationen zu planen, verbinden Sie es mit Verwenden Sie @capgo/capacitor-bluetooth-low-energy für die native Fähigkeit in Verwenden Sie @capgo/capacitor-bluetooth-low-energy API Übersicht für die Implementierungsdetails in API Übersicht Einführung für die Implementierungsdetails in Einführung API Schlüssel für die Implementierungsdetails in API Schlüssel Geräte für die Implementierungsdetails in Geräte.