Laird Capacitor Plugin
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.
Install
npm install laird-capacitor-plugin
npx cap sync
Example
import { Laird, Device } from 'laird-capacitor-plugin';
Laird.addListener("deviceFoundEvent", (device) => {
console.log(device);
});
Laird.startDiscovering({ periodically: true });
API
startDiscovering(...)
startDiscovering(options?: { periodically: boolean; } | undefined) => any
Start the discovering process for finding bluetooth devices.
options | { periodically: boolean; } |
Returns: any
cancelDiscovering()
cancelDiscovering() => any
Cancels the discovering process for finding bluetooth devices.
Returns: any
connectToDevice(...)
connectToDevice(options: { address: string; }) => any
Connects to the specified device with the address.
options | { address: string; } |
Returns: any
disconnectFromDevice()
disconnectFromDevice() => any
Disconnects the current connected device.
Returns: any
sendDataToDevice(...)
sendDataToDevice(options: { data: string; }) => any
Sends data to the connected device.
Returns: any
addListener(...)
addListener(eventName: 'discoveryStartEvent', callback: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
DiscoveryStartEvent
eventName | "discoveryStartEvent" |
callback | () => void |
Returns: any
addListener(...)
addListener(eventName: 'discoveryStopEvent', callback: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
DiscoveryStopEvent
eventName | "discoveryStopEvent" |
callback | () => void |
Returns: any
addListener(...)
addListener(eventName: 'deviceFoundEvent', callback: (device: Device) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
DeviceFoundListener
eventName | "deviceFoundEvent" | DeviceFoundEvent |
callback | (device: Device) => void | Callback |
Returns: any
addListener(...)
addListener(eventName: 'deviceRecvDataEvent', callback: (data: DeviceData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
DeviceRecvDataListener
eventName | "deviceRecvDataEvent" | DeviceRecvDataEvent |
callback | (data: DeviceData) => void | Callback |
Returns: any
Interfaces
PluginListenerHandle
Device
name | string |
type | number |
address | string |
rssi | number |
DeviceData