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

Committer:
JonnyA
Date:
Wed Jan 28 01:01:47 2015 +0000
Revision:
1:db5fcf988f53
Parent:
0:e2b2b6bdb2dc
The default advertising period seems too slow for the name to show up fast.; ; As that's the sole point of this example, let's decrease the interval

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonnyA 0:e2b2b6bdb2dc 1 /* mbed Microcontroller Library
JonnyA 0:e2b2b6bdb2dc 2 * Copyright (c) 2006-2015 ARM Limited
JonnyA 0:e2b2b6bdb2dc 3 *
JonnyA 0:e2b2b6bdb2dc 4 * Licensed under the Apache License, Version 2.0 (the "License");
JonnyA 0:e2b2b6bdb2dc 5 * you may not use this file except in compliance with the License.
JonnyA 0:e2b2b6bdb2dc 6 * You may obtain a copy of the License at
JonnyA 0:e2b2b6bdb2dc 7 *
JonnyA 0:e2b2b6bdb2dc 8 * http://www.apache.org/licenses/LICENSE-2.0
JonnyA 0:e2b2b6bdb2dc 9 *
JonnyA 0:e2b2b6bdb2dc 10 * Unless required by applicable law or agreed to in writing, software
JonnyA 0:e2b2b6bdb2dc 11 * distributed under the License is distributed on an "AS IS" BASIS,
JonnyA 0:e2b2b6bdb2dc 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JonnyA 0:e2b2b6bdb2dc 13 * See the License for the specific language governing permissions and
JonnyA 0:e2b2b6bdb2dc 14 * limitations under the License.
JonnyA 0:e2b2b6bdb2dc 15 */
JonnyA 0:e2b2b6bdb2dc 16
JonnyA 0:e2b2b6bdb2dc 17 #include "mbed.h"
JonnyA 0:e2b2b6bdb2dc 18 #include "BLEDevice.h"
JonnyA 0:e2b2b6bdb2dc 19
JonnyA 0:e2b2b6bdb2dc 20 BLEDevice ble;
JonnyA 0:e2b2b6bdb2dc 21
JonnyA 0:e2b2b6bdb2dc 22 const static char DEVICE_NAME[] = "ChangeMyName";
JonnyA 0:e2b2b6bdb2dc 23
JonnyA 0:e2b2b6bdb2dc 24 int main(void)
JonnyA 0:e2b2b6bdb2dc 25 {
JonnyA 0:e2b2b6bdb2dc 26 ble.init();
JonnyA 0:e2b2b6bdb2dc 27
JonnyA 1:db5fcf988f53 28 /* Setup the data to go into the advertising packets. */
JonnyA 0:e2b2b6bdb2dc 29 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
JonnyA 0:e2b2b6bdb2dc 30 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
JonnyA 1:db5fcf988f53 31
JonnyA 1:db5fcf988f53 32 /* The default advertising period is a little low - increase it */
JonnyA 1:db5fcf988f53 33 ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
JonnyA 1:db5fcf988f53 34
JonnyA 0:e2b2b6bdb2dc 35 ble.startAdvertising();
JonnyA 0:e2b2b6bdb2dc 36
JonnyA 0:e2b2b6bdb2dc 37 while (true) {
JonnyA 0:e2b2b6bdb2dc 38 ble.waitForEvent();
JonnyA 0:e2b2b6bdb2dc 39 }
JonnyA 0:e2b2b6bdb2dc 40 }