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:

LBLE.begin();
while(!LBLE.ready())
{
  delay(10);
}
Serial.println("BLE ready");

// start scanning nearby advertisements
LBLECentral.scan();

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.

for(int i = 0; i < scanner.getPeripheralCount(); ++i)
{
    Serial.println(LBLECentral.getName(i));
}

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:

..........Total 2 devices found:
idx	address			flag	RSSI
0	C6:32:4D:E8:51:75(RAN)	1A	-80	OMATE X by Unknown, service: (no service info)
1	C0:20:63:BA:FF:8A(RAN)	6	-99	BT_HEADSET_DEMO_LE by Unknown, service: (no service info)
------scan stopped-------

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.

serverAddress = LBLECentral.getBLEAddress(idx);
LBLEClient client;
client.connect(serverAddress);

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.

    // read the device manufacturer
    // first we check if "Device Information"(0x180A) service is available:
    if(client.hasService(0x180A))
    {
      const String name = client.readCharacteristicString(LBLEUuid(0x2A29));
      if(name.length() > 0)
      {
        Serial.print("manufacturer=");
        Serial.println(name);
      }
    }

Refer to the example LBLE > ConnectPeripheral to learn how to read and write characteristics.

Last updated