BLE_Advert_Settings

Description

The data type used to set advertising behavior.

Syntax

    BLE_Advert_Settings advertSettings =
    {
      advertMode,
      timeout,
      interval,
      connectedBehavior
    };

Parameters

advertMode: Sets the advertisement mode.

  • BLE_ADV_MODE_NONCONN: Nonconnectable undirected advertisements.

  • BLE_ADV_MODE_CONN: Connectable undirected advertisements.

  • BLE_ADV_MODE_SCANNABLE: This mode compensates for the small size of advertisement packets. A BLE central device can respond with a scan request packet to advertisements from a peripheral in this mode. The peripheral must listen for these scan request packets, which uses more power than the other two modes. Upon receiving a scan request, the peripheral sends extra data to the central device. This essentially doubles the amount of data that can be advertised at the expense of higher power consumption.

timeout: How long to advertise for in milliseconds. 0 for indefinitely.

interval: Advertising Interval (interval * 0.625 ms). 0 for 100ms default

connectedBehavior: The advertising behavior during and after connections.

  • BLE_ADV_STOP_ON_CONN: Advertising is disabled during connection and will not start after.

  • BLE_ADV_RESTART_ON_CONN_EST: Advertising will continue with non-connectable advertising when connection is established. There are separate GAP parameters for setting the connected advertising interval.

  • BLE_ADV_RESTART_ON_CONN_TERM: Advertising will restart with connectable advertising when a connection is terminated.

Example

Indefinite nonconnectable (e.g. for a simple beacon) advertisement every 900ms. Note that the last member, the connected behavior, of advertSettings has no effect because this is nonconnectable advertising.

    #include <BLE.h>

    BLE_Advert_Settings advertSettings =
    {
      BLE_ADV_MODE_NONCONN,
      0,
      1440, // 1440*0.625ms = 900ms
      BLE_ADV_RESTART_ON_CONN_EST
    }

    void setup() {
      ble.begin();
      ble.startAdvert(&advertSettings);
    }

    void loop() {
      ble.handleEvents();
    }
Guide Home