Central Devices
To use LinkIt 7697 as a Bluetooth central device, use the LBLECentral class.
The LBLE library allows you to create a central device that scans for nearby BLE devices. To do so, initialize LBLE and use the LBLECentral object, for example:
After calling scan()
, the Bluetooth subsystem will continuously scan for nearby Bluetooth devices. The scanned results are updated internally in the LBLECentral object. Call getPeripheralCount()
to retrieve the number of peripheral advertisements scanned.
Keep in mind that the content of peripheral advertisements is all optional. For example, an iBeacon device only advertises a connectivity flag and a manufacturer data, while a heart rate monitor may advertise its service UUID and a device name.
One common scenario is to scan for nearby iBeacon devices. Two helper methods isIBeacon
and getIBeaconInfo
can be used to easily parse nearby iBeacon advertisements.
An example that scans for nearby peripheral devices can be found in the IDE menu File > Examples > LBLE > ScanPeripherals
. An example output with 2 BLE device found looks like the following:
Connecting to BLE Peripherals
After scanning nearby devices with LBLECentral, you can then call getAddress() and use LBLEClient object to connect to a peripheral device, if it is connectable without security requirements.
The connect API can take a while because it also enumerates services and characteristics availalbe on the peripheral device. After establishing the connection, you can use the LBLEClient object to check available services, and read/write to characteristics.
Refer to the example LBLE > ConnectPeripheral to learn how to read and write characteristics.
Last updated