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 00:50:59 2015 +0000
Revision:
0:e2b2b6bdb2dc
Child:
1:db5fcf988f53
Basic BLEDevice with a name; ; This adds a very simple BLE device that does nothing except have a name. Useful for your very first program if you want iOS to cache a particular name.

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 0:e2b2b6bdb2dc 28 /* Setup advertising. */
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 0:e2b2b6bdb2dc 31 ble.startAdvertising();
JonnyA 0:e2b2b6bdb2dc 32
JonnyA 0:e2b2b6bdb2dc 33 while (true) {
JonnyA 0:e2b2b6bdb2dc 34 ble.waitForEvent();
JonnyA 0:e2b2b6bdb2dc 35 }
JonnyA 0:e2b2b6bdb2dc 36 }