Advertisement
Guest User

Beacon

a guest
Mar 31st, 2020
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <bluefruit.h>
  2.  
  3. // https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
  4. // 0x004C is Apple (for example)
  5. #define MANUFACTURER_ID 0x004c
  6.  
  7. // AirLocate UUID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
  8. uint8_t beaconUuid[16] =
  9. {
  10. 0xE2, 0xC5, 0x6D, 0xB5, 0xDF, 0xFB, 0x48, 0xD2,
  11. 0xB0, 0x60, 0xD0, 0xF5, 0xA7, 0x10, 0x96, 0xE0,
  12. };
  13.  
  14. int txpowers[14] = {-40, -20, -16, -12, -8, -4, 0, 2, 3, 4, 5, 6, 7, 8};
  15.  
  16. void setup()
  17. {
  18. Serial.begin(115200);
  19. while ( !Serial ) delay(10); // for nrf52840 with native usb
  20.  
  21. Serial.println("Bluefruit52 Beacon Example");
  22. Serial.println("--------------------------\n");
  23.  
  24. Bluefruit.begin();
  25.  
  26. Bluefruit.autoConnLed(false);
  27. Bluefruit.setName("Bluefruit_tristan");
  28.  
  29. size_t txlen = sizeof(txpowers)/sizeof(txpowers[0]);
  30. for(int i = 0; i < (int) txlen; i++){
  31. BLEBeacon beacon(beaconUuid, 0x0000, 0x0000, txpowers[i]); // UUID, Major, Minor, RSSI @ 1M
  32. beacon.setManufacturer(MANUFACTURER_ID); // Manufacturer ID is required for Manufacturer Specific Data
  33. Bluefruit.setTxPower(txpowers[i]); // Check bluefruit.h for supported values
  34. startAdv(beacon);
  35. }
  36.  
  37. Serial.println("Broadcasting beacon, open your beacon app to test");
  38.  
  39. // Suspend Loop() to save power, since we didn't have any code there
  40. // suspendLoop();
  41. }
  42.  
  43. void startAdv(BLEBeacon beacon)
  44. {
  45. Bluefruit.Advertising.setBeacon(beacon);
  46.  
  47. // Attempt to put sequence number in manufacturing data
  48. //Bluefruit.Advertising.addData(0x88, "Hi", 0x02);
  49. //Bluefruit.Advertising.addManufacturerData(data, 4);
  50.  
  51. // Secondary Scan Response packet (optional)
  52. // Since there is no room for 'Name' in Advertising packet
  53. Bluefruit.ScanResponse.addName();
  54.  
  55.  
  56. // Consider making beacon non-scannable to reduce overhead
  57. Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED);
  58. Bluefruit.Advertising.restartOnDisconnect(true);
  59. Bluefruit.Advertising.setInterval(35, 35); // in unit of 0.625 ms
  60. Bluefruit.Advertising.setFastTimeout(1); // number of seconds in fast mode
  61. Bluefruit.Advertising.start(1); // 0 = Don't stop advertising after n seconds
  62. delay(1000);
  63. Bluefruit.Advertising.stop();
  64. }
  65.  
  66. void loop()
  67. {
  68. // loop is already suspended, CPU will not run loop() at all
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement