EddyStone Beacon demo for the BLE API using the nRF51822 native mode drivers
Dependencies: BLE_API mbed nRF51822
Fork of BLE_iBeacon by
main.cpp@73:4793c5b3a7be, 2015-09-28 (annotated)
- Committer:
- RezaCute
- Date:
- Mon Sep 28 03:40:33 2015 +0000
- Revision:
- 73:4793c5b3a7be
- Parent:
- 72:eb4de3de66b8
EddyStone
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RezaCute | 73:4793c5b3a7be | 1 | // mbed HRM1017 Eddystone |
RezaCute | 73:4793c5b3a7be | 2 | // Programed by Kazuyuki Eguchi |
ktownsend | 0:7613d21e5974 | 3 | |
ktownsend | 0:7613d21e5974 | 4 | #include "mbed.h" |
RezaCute | 73:4793c5b3a7be | 5 | #include "BLE.h" |
RezaCute | 73:4793c5b3a7be | 6 | |
RezaCute | 73:4793c5b3a7be | 7 | BLEDevice ble; |
RezaCute | 73:4793c5b3a7be | 8 | |
RezaCute | 73:4793c5b3a7be | 9 | static const uint16_t uuid16_list[] = {0xFEAA}; |
RezaCute | 73:4793c5b3a7be | 10 | |
RezaCute | 73:4793c5b3a7be | 11 | const static uint8_t beaconPayload_uid[] = { |
RezaCute | 73:4793c5b3a7be | 12 | 0xaa, |
RezaCute | 73:4793c5b3a7be | 13 | 0xfe, |
RezaCute | 73:4793c5b3a7be | 14 | |
RezaCute | 73:4793c5b3a7be | 15 | // UID |
RezaCute | 73:4793c5b3a7be | 16 | |
RezaCute | 73:4793c5b3a7be | 17 | 0x00, // Frame Type |
RezaCute | 73:4793c5b3a7be | 18 | 0x00, // Ranging Data |
RezaCute | 73:4793c5b3a7be | 19 | |
RezaCute | 73:4793c5b3a7be | 20 | 0x01, // NID[0] |
RezaCute | 73:4793c5b3a7be | 21 | 0x02, // NID[1] |
RezaCute | 73:4793c5b3a7be | 22 | 0x03, // NID[2] |
RezaCute | 73:4793c5b3a7be | 23 | 0x04, // NID[3] |
RezaCute | 73:4793c5b3a7be | 24 | 0x05, // NID[4] |
RezaCute | 73:4793c5b3a7be | 25 | 0x06, // NID[5] |
RezaCute | 73:4793c5b3a7be | 26 | 0x07, // NID[6] |
RezaCute | 73:4793c5b3a7be | 27 | 0x08, // NID[7] |
RezaCute | 73:4793c5b3a7be | 28 | 0x09, // NID[8] |
RezaCute | 73:4793c5b3a7be | 29 | 0x0A, // NID[9] |
RezaCute | 73:4793c5b3a7be | 30 | |
RezaCute | 73:4793c5b3a7be | 31 | 0x11, // BID[0] |
RezaCute | 73:4793c5b3a7be | 32 | 0x22, // BID[1] |
RezaCute | 73:4793c5b3a7be | 33 | 0x33, // BID[2] |
RezaCute | 73:4793c5b3a7be | 34 | 0x44, // BID[3] |
RezaCute | 73:4793c5b3a7be | 35 | 0x55, // BID[4] |
RezaCute | 73:4793c5b3a7be | 36 | 0x66, // BID[5] |
RezaCute | 73:4793c5b3a7be | 37 | 0x00, // RFU |
RezaCute | 73:4793c5b3a7be | 38 | 0x00 // RFU |
RezaCute | 73:4793c5b3a7be | 39 | }; |
RezaCute | 73:4793c5b3a7be | 40 | |
RezaCute | 73:4793c5b3a7be | 41 | const static uint8_t beaconPayload_url[] = { |
RezaCute | 73:4793c5b3a7be | 42 | 0xaa, |
RezaCute | 73:4793c5b3a7be | 43 | 0xfe, |
mbedAustin | 56:56bc0cab3916 | 44 | |
RezaCute | 73:4793c5b3a7be | 45 | // URL |
RezaCute | 73:4793c5b3a7be | 46 | |
RezaCute | 73:4793c5b3a7be | 47 | 0x10, // Frame Type |
RezaCute | 73:4793c5b3a7be | 48 | 0x00, // Ranging Data |
RezaCute | 73:4793c5b3a7be | 49 | 0x02, // URL Scheme (http:// = 0x02) |
RezaCute | 73:4793c5b3a7be | 50 | |
RezaCute | 73:4793c5b3a7be | 51 | 'c', |
RezaCute | 73:4793c5b3a7be | 52 | 'u', |
RezaCute | 73:4793c5b3a7be | 53 | 'b', |
RezaCute | 73:4793c5b3a7be | 54 | 'e', |
RezaCute | 73:4793c5b3a7be | 55 | 'a', |
RezaCute | 73:4793c5b3a7be | 56 | 'c', |
RezaCute | 73:4793c5b3a7be | 57 | 'o', |
RezaCute | 73:4793c5b3a7be | 58 | 'n', |
RezaCute | 73:4793c5b3a7be | 59 | '.', |
RezaCute | 73:4793c5b3a7be | 60 | 'c', |
RezaCute | 73:4793c5b3a7be | 61 | 'o', |
RezaCute | 73:4793c5b3a7be | 62 | 'm' |
RezaCute | 73:4793c5b3a7be | 63 | }; |
RezaCute | 73:4793c5b3a7be | 64 | |
RezaCute | 73:4793c5b3a7be | 65 | const static uint8_t beaconPayload_tlm[] = { |
RezaCute | 73:4793c5b3a7be | 66 | 0xaa, |
RezaCute | 73:4793c5b3a7be | 67 | 0xfe, |
RezaCute | 73:4793c5b3a7be | 68 | |
RezaCute | 73:4793c5b3a7be | 69 | // TLM |
RezaCute | 73:4793c5b3a7be | 70 | |
RezaCute | 73:4793c5b3a7be | 71 | 0x20, // Frame Type |
RezaCute | 73:4793c5b3a7be | 72 | 0x00, // Version |
RezaCute | 73:4793c5b3a7be | 73 | 0x01, // VBATT[0] |
RezaCute | 73:4793c5b3a7be | 74 | 0x00, // VBATT[1] |
RezaCute | 73:4793c5b3a7be | 75 | 0x02, // TEMP[0] |
RezaCute | 73:4793c5b3a7be | 76 | 0x00, // TEMP[1] |
RezaCute | 73:4793c5b3a7be | 77 | 0x03, // ADV[0] |
RezaCute | 73:4793c5b3a7be | 78 | 0x00, // ADV[1] |
RezaCute | 73:4793c5b3a7be | 79 | 0x00, // ADV[2] |
RezaCute | 73:4793c5b3a7be | 80 | 0x00, // ADV[3] |
RezaCute | 73:4793c5b3a7be | 81 | 0x04, // SEC_CNT[0] |
RezaCute | 73:4793c5b3a7be | 82 | 0x00, // SEC_CNT[1] |
RezaCute | 73:4793c5b3a7be | 83 | 0x00, // SEC_CNT[2] |
RezaCute | 73:4793c5b3a7be | 84 | 0x00 // SEC_CNT[3] |
RezaCute | 73:4793c5b3a7be | 85 | }; |
RezaCute | 73:4793c5b3a7be | 86 | |
mbedAustin | 50:7bc38f01d2d3 | 87 | |
ktownsend | 0:7613d21e5974 | 88 | int main(void) |
ktownsend | 0:7613d21e5974 | 89 | { |
Rohit Grover |
11:6774f4827024 | 90 | ble.init(); |
mbedAustin | 53:f9ec2c7a47f5 | 91 | |
RezaCute | 73:4793c5b3a7be | 92 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
RezaCute | 73:4793c5b3a7be | 93 | |
RezaCute | 73:4793c5b3a7be | 94 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); |
RezaCute | 73:4793c5b3a7be | 95 | |
RezaCute | 73:4793c5b3a7be | 96 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload_uid, sizeof(beaconPayload_uid)); |
RezaCute | 73:4793c5b3a7be | 97 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload_url, sizeof(beaconPayload_url)); |
RezaCute | 73:4793c5b3a7be | 98 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload_tlm, sizeof(beaconPayload_tlm)); |
mbedAustin | 53:f9ec2c7a47f5 | 99 | |
RezaCute | 73:4793c5b3a7be | 100 | ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); |
RezaCute | 73:4793c5b3a7be | 101 | |
RezaCute | 73:4793c5b3a7be | 102 | ble.setAdvertisingInterval(160); |
ktownsend | 0:7613d21e5974 | 103 | |
RezaCute | 73:4793c5b3a7be | 104 | ble.startAdvertising(); |
RezaCute | 73:4793c5b3a7be | 105 | |
RezaCute | 73:4793c5b3a7be | 106 | for (;;) { |
RezaCute | 73:4793c5b3a7be | 107 | ble.waitForEvent(); |
ktownsend | 0:7613d21e5974 | 108 | } |
RezaCute | 73:4793c5b3a7be | 109 | } |