Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Diff: main.cpp
- Revision:
- 25:7cf2a38ea175
- Parent:
- 24:12eb3f19e9a4
--- a/main.cpp Wed Jan 08 11:13:14 2014 +0000
+++ b/main.cpp Wed Jan 08 18:49:39 2014 +0000
@@ -2,61 +2,53 @@
#include "uuid.h"
#include "hw/nrf51822.h"
-DigitalOut myled ( LED1 );
-
/* Radio HW */
nRF51822 radio;
void startBeacon(void)
{
- ble_error_t error;
GapAdvertisingParams advParams ( GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED );
GapAdvertisingData advData;
GapAdvertisingData scanResponse;
+ /* Define an iBeacon payload
+ --------------------------------------------------------------
+ 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
+ Major/Minor = 0000 / 0000
+ Tx Power = C8
+ */
uint8_t iBeaconPayload[25] = { 0x4C, 0x00, 0x02, 0x15, 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61, 0x00, 0x00, 0x00, 0x00, 0xC8 };
/* iBeacon includes the FLAG and MSD fields */
- error = advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
- error = advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, 25);
+ advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+ advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, sizeof(iBeaconPayload));
- error = radio.reset();
- error = radio.setAdvertising(advParams, advData, scanResponse);
- error = radio.start();
-
- /* Hang around here for a while */
- while(1)
- {
- }
+ radio.reset();
+ radio.setAdvertising(advParams, advData, scanResponse);
+ radio.start();
}
void startBatteryService(void)
{
- ble_error_t error;
GattService battService ( 0x180F );
GattCharacteristic battLevel ( 0x2A19, 1, 1, BLE_GATT_CHAR_PROPERTIES_NOTIFY | BLE_GATT_CHAR_PROPERTIES_READ);
/* Make sure we get a clean start */
- error = radio.reset();
+ radio.reset();
/* Add the characteristic to our service */
- error = battService.addCharacteristic(battLevel);
+ battService.addCharacteristic(battLevel);
/* Pass the service into the radio */
- error = radio.addService(battService);
+ radio.addService(battService);
/* Configure the radio and start advertising with default values */
/* Make sure you've added all of your services before calling this function! */
- error = radio.start();
+ radio.start();
/* Now that we're live, update the battery level characteristic */
uint8_t batt = 72;
- error = radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
-
- /* Hang around here for a while */
- while(1)
- {
- }
+ radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
}
int main()
@@ -64,6 +56,7 @@
/* Give the radio some time to boot up and settle */
wait(2);
+ /* Select one of the options below depending on the demo you want to see */
// startBeacon();
startBatteryService();
