# 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 <a href="#lbleperipheral-methods" id="lbleperipheral-methods"></a>

&#x20;addService()

&#x20;begin()

&#x20;advertise()

&#x20;advertiseAsBeacon()

&#x20;stopAdvertise()

&#x20;notifyAll()



{% tabs %}
{% tab title="addService()" %}
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
{% endtab %}

{% tab title="begin()" %}
After setup services and characteristics you have to call begin() to enable the GATT server.

**Syntax**

**Parameters**

none

**Returns**

none
{% endtab %}

{% tab title="advertise()" %}
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
{% endtab %}

{% tab title="advertiseAsBeacon()" %}
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
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="stopAdvertise()" %}
stop advertisement and clears advertisement data.

**Syntax**

**Parameters**

none

**Returns**

none
{% endtab %}

{% tab title="notifyAll()" %}
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.

**Returns**

none
{% endtab %}
{% endtabs %}
