Minimal usage example of BLE API

Dependencies:   BLE_API mbed nRF51822

Just a very simple and minimal BluetoothLE API 'Hello World' example.

main.cpp

Committer:
waynek
Date:
2015-01-28
Revision:
1:b84d6e0b404e
Parent:
0:a89b73f690c1
Child:
2:4f0d8bf09690

File content as of revision 1:b84d6e0b404e:

#include "mbed.h"
#include "BLEDevice.h"

// DFUService is already included & automatically advertised by the mbed lib dependancies (currently)

const static char     DEVICE_NAME[]        = "HelloBlue";

BLEDevice ble;

void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
    ble.startAdvertising(); // restart advertising
}

int main(void)
{
    ble.init();
    ble.onDisconnection(disconnectionCallback);

    /* Setup advertising. */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
    ble.startAdvertising();
    
   while (true) {
        ble.waitForEvent();
    }
}