This is an extremely simple consumer of the BLEDevice API. The aim is to demonstrate the smallest program that is sensibly detected on a device. Be careful with the name! iOS caches device names, and so you can't necessarily guarantee how long you'll be stuck with the first one you choose first time iOS sees your board.

Dependencies:   BLE_API mbed nRF51822

main.cpp

Committer:
JonnyA
Date:
2015-01-28
Revision:
1:db5fcf988f53
Parent:
0:e2b2b6bdb2dc

File content as of revision 1:db5fcf988f53:

/* mbed Microcontroller Library
 * Copyright (c) 2006-2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

BLEDevice  ble;

const static char     DEVICE_NAME[]        = "ChangeMyName";

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

    /* Setup the data to go into the advertising packets. */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
    
    /* The default advertising period is a little low - increase it */
    ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
    
    ble.startAdvertising();

    while (true) {
        ble.waitForEvent();
    }
}