Changed to work with St Board
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_URIBeacon by
main.cpp@9:e7f47bec97b8, 2014-12-04 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Dec 04 18:18:46 2014 +0000
- Revision:
- 9:e7f47bec97b8
- Parent:
- 8:b816829fb712
- Child:
- 11:c77cc2b74101
Initial Commit of the URI Beacon example. A simplified version of PhysicalWeb .
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:790a27ffc99b | 1 | /* mbed Microcontroller Library |
rgrover1 | 0:790a27ffc99b | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 0:790a27ffc99b | 3 | * |
rgrover1 | 0:790a27ffc99b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 0:790a27ffc99b | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 0:790a27ffc99b | 6 | * You may obtain a copy of the License at |
rgrover1 | 0:790a27ffc99b | 7 | * |
rgrover1 | 0:790a27ffc99b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 0:790a27ffc99b | 9 | * |
rgrover1 | 0:790a27ffc99b | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 0:790a27ffc99b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 0:790a27ffc99b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 0:790a27ffc99b | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 0:790a27ffc99b | 14 | * limitations under the License. |
rgrover1 | 0:790a27ffc99b | 15 | */ |
rgrover1 | 0:790a27ffc99b | 16 | |
rgrover1 | 0:790a27ffc99b | 17 | #include "mbed.h" |
rgrover1 | 0:790a27ffc99b | 18 | #include "BLEDevice.h" |
rgrover1 | 7:6faec5978fb4 | 19 | #include "URIBeaconConfigService.h" |
rgrover1 | 0:790a27ffc99b | 20 | |
rgrover1 | 0:790a27ffc99b | 21 | BLEDevice ble; |
rgrover1 | 8:b816829fb712 | 22 | URIBeaconConfigService *uriBeaconConfig; |
rgrover1 | 0:790a27ffc99b | 23 | |
mbedAustin | 9:e7f47bec97b8 | 24 | /*If beacon gets disconnected start advertising again */ |
rgrover1 | 6:31b65d4ea67d | 25 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
rgrover1 | 6:31b65d4ea67d | 26 | { |
rgrover1 | 6:31b65d4ea67d | 27 | ble.startAdvertising(); |
rgrover1 | 6:31b65d4ea67d | 28 | } |
rgrover1 | 0:790a27ffc99b | 29 | |
mbedAustin | 9:e7f47bec97b8 | 30 | /* |
mbedAustin | 9:e7f47bec97b8 | 31 | * The main loop. |
mbedAustin | 9:e7f47bec97b8 | 32 | * Here we will configure the URI Beacon and start advertising |
mbedAustin | 9:e7f47bec97b8 | 33 | */ |
rgrover1 | 0:790a27ffc99b | 34 | int main(void) |
rgrover1 | 0:790a27ffc99b | 35 | { |
mbedAustin | 9:e7f47bec97b8 | 36 | /* Initialize BLE base layer*/ |
rgrover1 | 0:790a27ffc99b | 37 | ble.init(); |
rgrover1 | 6:31b65d4ea67d | 38 | ble.onDisconnection(disconnectionCallback); |
rgrover1 | 0:790a27ffc99b | 39 | |
mbedAustin | 9:e7f47bec97b8 | 40 | /* Set the BLE device to be a URI Beacon, set advertising payload |
mbedAustin | 9:e7f47bec97b8 | 41 | the address after the preamble (www.) can be 17bytes at most.*/ |
mbedAustin | 9:e7f47bec97b8 | 42 | uriBeaconConfig = new URIBeaconConfigService(ble, "http://www.developer.mbed.org"); |
mbedAustin | 9:e7f47bec97b8 | 43 | |
mbedAustin | 9:e7f47bec97b8 | 44 | /*Check that the URI Beacon started successfully.*/ |
rgrover1 | 8:b816829fb712 | 45 | if (!uriBeaconConfig->configuredSuccessfully()) { |
rgrover1 | 6:31b65d4ea67d | 46 | error("failed to accommodate URI"); |
rgrover1 | 6:31b65d4ea67d | 47 | } |
mbedAustin | 9:e7f47bec97b8 | 48 | |
rgrover1 | 7:6faec5978fb4 | 49 | /* optional use of the API offered by URIBeaconConfigService */ |
rgrover1 | 7:6faec5978fb4 | 50 | const int8_t powerLevels[] = {-20, -4, 0, 10}; |
mbedAustin | 9:e7f47bec97b8 | 51 | uriBeaconConfig->setTxPowerLevels(powerLevels); // Set TX power levels, Lowest(-20), Low(-4), Medium(0), High(10) |
mbedAustin | 9:e7f47bec97b8 | 52 | uriBeaconConfig->setTxPowerMode(URIBeaconConfigService::TX_POWER_MODE_LOW); // Initialize tranmition in Low power mode |
rgrover1 | 0:790a27ffc99b | 53 | |
mbedAustin | 9:e7f47bec97b8 | 54 | /*Start advertising the URI Beacon*/ |
rgrover1 | 0:790a27ffc99b | 55 | ble.startAdvertising(); |
rgrover1 | 0:790a27ffc99b | 56 | |
rgrover1 | 0:790a27ffc99b | 57 | while (true) { |
rgrover1 | 0:790a27ffc99b | 58 | ble.waitForEvent(); |
rgrover1 | 0:790a27ffc99b | 59 | } |
rgrover1 | 0:790a27ffc99b | 60 | } |