Plugin EcosystemHardware & Sensors
Bluetooth Low Energy (BLE)
Connect and communicate with BLE peripherals and IoT devices.
BLE Plugin
The BLE plugin offers robust communication with Bluetooth Low Energy devices. Designed for IoT dashboards, medical devices, and industrial sensors.
Installation
npm install @easycord/plugin-bleAPI Reference
scanForDevices(options: ScanOptions)
Scans for nearby BLE devices matching the specified services.
Parameters
services(string[]): Array of GATT service UUIDs to filter by.duration(number): Scan duration in milliseconds.
Example Usage
import { useState } from 'react';
import { BLE, BleDevice } from '@easycord/plugin-ble';
export default function BleScanner() {
const [devices, setDevices] = useState<BleDevice[]>([]);
const startScan = async () => {
try {
const results = await BLE.scanForDevices({
services: ['180D'], // Heart Rate service example
duration: 5000
});
setDevices(results.devices);
} catch (err) {
console.error('BLE Scan Error:', err);
}
};
return (
<div className="p-4">
<button onClick={startScan} className="bg-purple-600 text-white px-4 py-2 rounded">
Scan for Devices
</button>
<ul className="mt-4 space-y-2">
{devices.map(dev => (
<li key={dev.id} className="border p-2 rounded">
{dev.name || 'Unknown Device'} ({dev.id})
</li>
))}
</ul>
</div>
);
}