LBLEPeripheral

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

stop advertisement and clears advertisement data.

Syntax

Parameters

none

Returns

none

Last updated