This project contains two type of beacons: Eddystone and iBeacon.
Dependencies: microbit-iBeacon
Fork of BTW_ComboBeacon_Solution by
beacon_src.txt
- Committer:
- krenbluetoothsig
- Date:
- 2018-08-02
- Revision:
- 21:8d35c362b325
- Parent:
- 20:223f589c3fe9
File content as of revision 21:8d35c362b325:
//DIRECTORY: ./main.cpp //**@code **********************// // TODO: add ADV on and off flag #define ADV_ON 1 #define ADV_OFF 0 //**@endcode *******************// //**@code **********************// // TODO: constants, used for iBeacon UUID(MSB first), Major, Minor and txpower setting const uint8_t iBeaconProximityUUIDraw[] = { 0x01, 0xD9, 0xC8, 0x00, 0x45, 0xF3, 0x40, 0x24, 0x93, 0xB0, 0xB0, 0xCD, 0x4A, 0x50, 0x2A, 0xF7 }; // 01D9C800-45F3-4024-93B0-B0CD4A502AF7 use this UUID including dashes in mobile application const UUID iBeaconProximityUUID(iBeaconProximityUUIDraw); const int16_t iBeaconMajor = 1234; const int16_t iBeaconMinor = 5678; // lvl : Pwr@ 1m : Pwr@ 0m // 0 : -90 : -49 // 1 : -78 : -37 // 2 : -74 : -33 // 3 : -69 : -28 // 4 : -66 : -25 // 5 : -61 : -20 // 6 : -56 : -15 // 7 : -51 : -10 const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; //**@endcode *******************// //**@code **********************// // TODO: global data and functions char eddystoneURL[] = "https://www.bluetooth.com"; uint8_t advertising = 0; uint8_t tx_power_level = 6; BLE_BEACON_TYPE beacon_type = BEACON_TYPE_EDDYSTONE; // BEACON_TYPE_EDDYSTONE, BEACON_TYPE_IBEACON, BEACON_TYPE_NONE //**@endcode *******************// //**@code **********************// // TODO: functions, startAdvertising and stopAdvertising void startAdvertising() { switch(beacon_type) { case BEACON_TYPE_EDDYSTONE: uBit.bleManager.advertiseEddystoneUrl(eddystoneURL, CALIBRATED_POWERS[tx_power_level - 1], false); uBit.display.print("E"); pcCom.printf("eddystone\r\n"); break; // case BEACON_TYPE_IBEACON: uBit.bleManager.advertiseIBeacon(iBeaconProximityUUID, iBeaconMajor, iBeaconMinor, CALIBRATED_POWERS[0]); uBit.display.print("i"); pcCom.printf("iBeacon\r\n"); break; // case BEACON_TYPE_NONE: default: pcCom.printf("unknow\r\n"); break; } uBit.bleManager.setTransmitPower(tx_power_level); advertising = 1; } void stopAdvertising() { pcCom.printf("ADV OFF\r\n"); uBit.bleManager.stopAdvertising(); advertising = 0; } //**@endcode *******************// //**@code **********************// // TODO: functions, used for ButtonA and ButtonB interrupt callbacks void onButtonA(MicroBitEvent) { // toggle advertising switch(advertising) { case 0: pcCom.printf("ADV ON "); uBit.display.scroll("ON"); startAdvertising(); break; case 1: pcCom.printf("ADV OFF"); stopAdvertising(); uBit.display.scroll("OFF"); break; default: break; } } void onButtonB(MicroBitEvent) { // ButtonB is used to toggle beacon types, switch beacons types // between iBeacon and Eddystone. stopAdvertising(); switch(beacon_type) { case BEACON_TYPE_EDDYSTONE: beacon_type = BEACON_TYPE_IBEACON; break; case BEACON_TYPE_IBEACON: beacon_type = BEACON_TYPE_EDDYSTONE; break; case BEACON_TYPE_NONE: default: beacon_type = BEACON_TYPE_EDDYSTONE; break; } startAdvertising(); } //**@endcode *******************// //**@code **********************// // TODO: Register the interrupt and callback for ButtonA and ButtonB uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA); uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB); //**@endcode *******************// //**@code **********************// // TODO: First Advertisment, adv name only uBit.bleManager.advertise(); //**@endcode *******************//