Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bluefruit.h>
- // https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
- // 0x004C is Apple (for example)
- #define MANUFACTURER_ID 0x004c
- // AirLocate UUID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
- uint8_t beaconUuid[16] =
- {
- 0xE2, 0xC5, 0x6D, 0xB5, 0xDF, 0xFB, 0x48, 0xD2,
- 0xB0, 0x60, 0xD0, 0xF5, 0xA7, 0x10, 0x96, 0xE0,
- };
- int txpowers[14] = {-40, -20, -16, -12, -8, -4, 0, 2, 3, 4, 5, 6, 7, 8};
- void setup()
- {
- Serial.begin(115200);
- while ( !Serial ) delay(10); // for nrf52840 with native usb
- Serial.println("Bluefruit52 Beacon Example");
- Serial.println("--------------------------\n");
- Bluefruit.begin();
- Bluefruit.autoConnLed(false);
- Bluefruit.setName("Bluefruit_tristan");
- size_t txlen = sizeof(txpowers)/sizeof(txpowers[0]);
- for(int i = 0; i < (int) txlen; i++){
- BLEBeacon beacon(beaconUuid, 0x0000, 0x0000, txpowers[i]); // UUID, Major, Minor, RSSI @ 1M
- beacon.setManufacturer(MANUFACTURER_ID); // Manufacturer ID is required for Manufacturer Specific Data
- Bluefruit.setTxPower(txpowers[i]); // Check bluefruit.h for supported values
- startAdv(beacon);
- }
- Serial.println("Broadcasting beacon, open your beacon app to test");
- // Suspend Loop() to save power, since we didn't have any code there
- // suspendLoop();
- }
- void startAdv(BLEBeacon beacon)
- {
- Bluefruit.Advertising.setBeacon(beacon);
- // Attempt to put sequence number in manufacturing data
- //Bluefruit.Advertising.addData(0x88, "Hi", 0x02);
- //Bluefruit.Advertising.addManufacturerData(data, 4);
- // Secondary Scan Response packet (optional)
- // Since there is no room for 'Name' in Advertising packet
- Bluefruit.ScanResponse.addName();
- // Consider making beacon non-scannable to reduce overhead
- Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED);
- Bluefruit.Advertising.restartOnDisconnect(true);
- Bluefruit.Advertising.setInterval(35, 35); // in unit of 0.625 ms
- Bluefruit.Advertising.setFastTimeout(1); // number of seconds in fast mode
- Bluefruit.Advertising.start(1); // 0 = Don't stop advertising after n seconds
- delay(1000);
- Bluefruit.Advertising.stop();
- }
- void loop()
- {
- // loop is already suspended, CPU will not run loop() at all
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement