diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/eddystone_url/eddystone_url.ino b/libraries/Bluefruit52Lib/examples/Peripheral/eddystone_url/eddystone_url.ino new file mode 100644 index 00000000..7249dc45 --- /dev/null +++ b/libraries/Bluefruit52Lib/examples/Peripheral/eddystone_url/eddystone_url.ino @@ -0,0 +1,71 @@ +/********************************************************************* + This is an example for our nRF52 based Bluefruit LE modules + + Pick one up today in the adafruit shop! + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + MIT license, check LICENSE for more information + All text above, and the splash screen below must be included in + any redistribution +*********************************************************************/ +#include + +#define URL "https://www.adafruit.com" + +// Create an EddyStone URL with rssi at 0m = -40 and URL as defined above +EddyStoneUrl eddyUrl(-40, URL); + +void setup() +{ + Serial.begin(115200); + + Serial.println("Bluefruit52 EddyStone URL Example"); + Serial.println("---------------------------------\n"); + + Bluefruit.begin(); + Bluefruit.setTxPower(4); // Maximum TX power = 4 dBm + Bluefruit.setName("Bluefruit52"); + + // Setup the advertising packet + startAdv(); + + Serial.println("Broadcasting EddyStone URL, open Google Physical Web app to test"); +} + +void startAdv(void) +{ + // Advertising packet + // Set the beacon payload using the BLEBeacon class populated + // earlier in this example + Bluefruit.Advertising.setBeacon(eddyUrl); + + // Secondary Scan Response packet (optional) + // Since there is no room for 'Name' in Advertising packet + Bluefruit.ScanResponse.addName(); + + /* Start Advertising + * - Enable auto advertising if disconnected + * - Timeout for fast mode is 30 seconds + * - Start(timeout) with timeout = 0 will advertise forever (until connected) + * + * Apple Beacon specs + * - Type: Non connectable, undirected + * - Fixed interval: 100 ms -> fast = slow = 100 ms + */ + //Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_ADV_NONCONN_IND); + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(160, 160); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds +} + +void loop() +{ + // Toggle both LEDs every second + digitalToggle(LED_RED); + delay(1000); +} +