This plugin is still in development and is not live on NPM yet!
A Capacitor plugin that communicates with bluetooth low energy laird devices. Supports older devices with the BluetoothAdapter and newer devices uses the BluetoothLeScanner.
npm install laird-capacitor-plugin
npx cap sync// Import Laird and Device.
import { Laird, Device } from 'laird-capacitor-plugin';
// Initialize the listener first.
Laird.addListener("deviceFoundEvent", (device) => {
console.log(device);
});
// Start discovering.
Laird.startDiscovering({ periodically: true });startDiscovering(...)cancelDiscovering()connectToDevice(...)disconnectFromDevice()sendDataToDevice(...)addListener(...)addListener(...)addListener(...)addListener(...)- Interfaces
startDiscovering(options?: { periodically: boolean; } | undefined) => anyStart the discovering process for finding bluetooth devices.
| Param | Type |
|---|---|
options |
{ periodically: boolean; } |
Returns: any
cancelDiscovering() => anyCancels the discovering process for finding bluetooth devices.
Returns: any
connectToDevice(options: { address: string; }) => anyConnects to the specified device with the address.
| Param | Type |
|---|---|
options |
{ address: string; } |
Returns: any
disconnectFromDevice() => anyDisconnects the current connected device.
Returns: any
sendDataToDevice(options: { data: string; }) => anySends data to the connected device.
| Param | Type |
|---|---|
options |
{ data: string; } |
Returns: any
addListener(eventName: 'discoveryStartEvent', callback: () => void) => Promise<PluginListenerHandle> & PluginListenerHandleDiscoveryStartEvent
| Param | Type |
|---|---|
eventName |
"discoveryStartEvent" |
callback |
() => void |
Returns: any
addListener(eventName: 'discoveryStopEvent', callback: () => void) => Promise<PluginListenerHandle> & PluginListenerHandleDiscoveryStopEvent
| Param | Type |
|---|---|
eventName |
"discoveryStopEvent" |
callback |
() => void |
Returns: any
addListener(eventName: 'deviceFoundEvent', callback: (device: Device) => void) => Promise<PluginListenerHandle> & PluginListenerHandleDeviceFoundListener
| Param | Type | Description |
|---|---|---|
eventName |
"deviceFoundEvent" |
DeviceFoundEvent |
callback |
(device: Device) => void |
Callback |
Returns: any
addListener(eventName: 'deviceRecvDataEvent', callback: (data: DeviceData) => void) => Promise<PluginListenerHandle> & PluginListenerHandleDeviceRecvDataListener
| Param | Type | Description |
|---|---|---|
eventName |
"deviceRecvDataEvent" |
DeviceRecvDataEvent |
callback |
(data: DeviceData) => void |
Callback |
Returns: any
| Prop | Type |
|---|---|
remove |
() => any |
| Prop | Type |
|---|---|
name |
string |
type |
number |
address |
string |
rssi |
number |
| Prop | Type |
|---|---|
data |
string |