LBLEPeripheral is a singleton object representing the local BLE periphral device. Developers can use this object to create beacon devices or peripheral devices that stores characterstics.
There are several stages when using LBLEPeripheral:
Prepare characteristics and services: design what services and characteristics your device is going to have. Define these entities in the global scope:
// Define a simple GATT service with only 1 characteristic
LBLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214");
LBLECharacteristicInt switchCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", LBLE_READ | LBLE_WRITE);
Configuration: if you need to create a peripheral that can store characteristics, you need to create services. use addService() to add services into your peripheral.
// Add characteristics into ledService
ledService.addAttribute(switchCharacteristic);
// Add service to GATT server (peripheral)
LBLEPeripheral.addService(ledService);
// start the GATT server - it is now
// available to connect
LBLEPeripheral.begin();
Start the service framework by calling LBLEPeripheral.begin()
And finally broadcast your presense with LBLEPeripheral.advertise()
Methods
addService()
begin()
advertise()
advertiseAsBeacon()
stopAdvertise()
notifyAll()
configuring GATT Services. You must configure services before advertising the device. The services cannot change after being connected.
Syntax
Parameters
service: The service to be added into this peripheral. The service object is referenced instead of copied, so tt must be valid and alive all the time. It is recommended to define the service in global scope.
Returns
none
After setup services and characteristics you have to call begin() to enable the GATT server.
Syntax
Parameters
none
Returns
none
start advertisement as a connectable device
Syntax
Parameters
advertisementData is an instance of LBLEAdvertisementData. Call the methods of LBLEAdvertisementData to configure information in the advertisement.
Returns
none
start advertisement as an non-connectable device (such as an iBeacon)
Syntax
Parameters
advertisementData is an instance of LBLEAdvertisementData. Call the methods of LBLEAdvertisementData to configure information in the advertisement.
Returns
none
stop advertisement and clears advertisement data.
Syntax
Parameters
none
Returns
none
Send GATT notification of the given characteristic. The content of the notification is the handle and value of the characteristic.
Syntax
Parameters
characterstic: a LBLECharacteristic object that has previously been added to the LBLEPeripheral. Its value will be used as the content of the notification.