Singleton objects that represents a BLE central device.
This class allows LinkIt 7697 to act as a BLE central device. It can scan nearby BLE peripherals, checking if they are beacons or devices that provides GATT services.
This class does not provide functions to connect to remote peripheral devices. Use LBLEClient class instead to connect to a remote device and read/write its characteristics.
To use this object, call scan() first and check if there's any peripherals nearby with getPeripheralCount, and then use APIs such as getName and getAddress:
// start scanning
LBLECentral.scan();
// wait for 5 seconds to scan
for(int i = 0; i < 5; ++i)
{
delay(1000);
Serial.print(".");
}
// list name of the peripherals found.
const int found = LBLECentral.getPeripheralCount();
for (int i = 0; i < found; ++i) {
Serial.println(LBLECentral.getName(i));
}
Scan Methods
scan()
stopScan()
getPeripheralCount ()
Start scanning nearby BLE peripherals. This puts the system into a scanning state. The system keeps updating the peripheral list in the background.
The result of getPeripheralCount()will be updated once a new peripheral is found.
Note that it may took sometime for peripherals to get scanned.
To get the scanned peripheral, call getPeripheralCount() and use methods such as getPeripheralNameor isBeacon with index as input.
Syntax
Parameters
n/a
Returns
n/a
Stop scanning nearby BLE peripherals.
Stops the system from scanning nearby peripherals. The list of discovered peripherals are still kept but will no longer be updated.
Syntax
Parameters
n/a
Returns
n/a
Retrive the number of peripherals currently discovered.
Syntax
Parameters
n/a
Returns
Number of peripherals found.
Methods for Scanned Device Information
After a peripheral is found, you can use the index to query information on the scanned device. Note that due to the design of BLE advertisement packets, not all devices broadcast the same information, so the query result can be empty.
getAddress()
getBLEAddress()
getManufacturer()
getName()
getRSSI()
getTxPower()
getServiceUuid()
getIBeaconInfo()
Get scanned peripheral information by index.
Get address of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
Device address (in string format) of the scanned peripheral.
Get address of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
Device address of the scanned peripheral.
Get manufacturer info in the advertisement packet of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
manufacturer id, if any, in the advertisement packet.
Get device name of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
device name
Get scanned RSSI of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
RSSI value in dbm.
Get txPower value in the advertisement packet of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
TX power field, if any, in the advertisement packet.
Get service UUID in the advertisement packet of the peripheral in the list of scanned devices.
Syntax
Parameters
indexranges from 0 to (getRemotePeripheralCount() - 1). The same index represents the same device.
Returns
service UUID, if any, in the advertisement packet.
Get iBeacon infomrmation from the advertisement data of an iBeacon device.