test
Dependencies: BLE_API mbed nRF51822
Fork of BLE_Beacon by
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "BLEDevice.h" 00019 00020 BLEDevice ble; 00021 00022 #define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console; 00023 * it will have an impact on code-size and power consumption. */ 00024 00025 #if NEED_CONSOLE_OUTPUT 00026 Serial pc(USBTX, USBRX); 00027 #define DEBUG(...) { pc.printf(__VA_ARGS__); } 00028 #else 00029 #define DEBUG(...) /* nothing */ 00030 #endif /* #if NEED_CONSOLE_OUTPUT */ 00031 00032 /* 00033 * For this demo application, populate the beacon advertisement payload 00034 * with 2 AD structures: FLAG and MSD (manufacturer specific data). 00035 * 00036 * Reference: 00037 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 00038 */ 00039 00040 /* 00041 * The Beacon payload (encapsulated within the MSD advertising data structure) 00042 * has the following composition: 00043 * 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00044 * Major/Minor = 0000 / 0000 00045 * Tx Power = C8 00046 */ 00047 const uint8_t beaconPayload[] = { 00048 0x4C, 0x00, // Company identifier code (0x004C == Apple) 00049 0x02, // ID 00050 0x15, // length of the remaining payload 00051 //0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // location UUID 00052 //0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61, 00053 //0x5A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // location UUID 00054 //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 00055 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 00056 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0, //Nordic UUID from examples 00057 0x00, 0x00, // the major value to differentiate a location 00058 0x00, 0x00, // the minor value to differentiate a location 00059 0xC8 // 2's complement of the Tx power (-56dB) 00060 }; 00061 00062 int main(void) 00063 { 00064 //DEBUG("Initialising BTLE transport\n\r"); 00065 ble.init(); 00066 00067 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); 00068 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, beaconPayload, sizeof(beaconPayload)); 00069 00070 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); 00071 ble.setAdvertisingInterval(1600); /* 1s; in multiples of 0.625ms. */ 00072 ble.startAdvertising(); 00073 00074 for (;;) { 00075 ble.waitForEvent(); 00076 } 00077 00078 // An alternative to the above: 00079 // 00080 // DigitalOut mainloopLED(LED1); 00081 // for (;;) { 00082 // mainloopLED = !mainloopLED; 00083 // ble.waitForEvent(); 00084 // } 00085 }
Generated on Wed Jul 13 2022 20:18:50 by 1.7.2