|
| 1 | +/********************************************************************* |
| 2 | + This is an example for our nRF52 based Bluefruit LE modules |
| 3 | +
|
| 4 | + Pick one up today in the adafruit shop! |
| 5 | +
|
| 6 | + Adafruit invests time and resources providing this open source code, |
| 7 | + please support Adafruit and open-source hardware by purchasing |
| 8 | + products from Adafruit! |
| 9 | +
|
| 10 | + MIT license, check LICENSE for more information |
| 11 | + All text above, and the splash screen below must be included in |
| 12 | + any redistribution |
| 13 | +*********************************************************************/ |
| 14 | +#include <bluefruit.h> |
| 15 | + |
| 16 | +#define URL "https://www.adafruit.com" |
| 17 | + |
| 18 | +// Create an EddyStone URL with rssi at 0m = -40 and URL as defined above |
| 19 | +EddyStoneUrl eddyUrl(-40, URL); |
| 20 | + |
| 21 | +void setup() |
| 22 | +{ |
| 23 | + Serial.begin(115200); |
| 24 | + |
| 25 | + Serial.println("Bluefruit52 EddyStone URL Example"); |
| 26 | + Serial.println("---------------------------------\n"); |
| 27 | + |
| 28 | + Bluefruit.begin(); |
| 29 | + Bluefruit.setTxPower(4); // Maximum TX power = 4 dBm |
| 30 | + Bluefruit.setName("Bluefruit52"); |
| 31 | + |
| 32 | + // Setup the advertising packet |
| 33 | + startAdv(); |
| 34 | + |
| 35 | + Serial.println("Broadcasting EddyStone URL, open Google Physical Web app to test"); |
| 36 | +} |
| 37 | + |
| 38 | +void startAdv(void) |
| 39 | +{ |
| 40 | + // Advertising packet |
| 41 | + // Set the beacon payload using the BLEBeacon class populated |
| 42 | + // earlier in this example |
| 43 | + Bluefruit.Advertising.setBeacon(eddyUrl); |
| 44 | + |
| 45 | + // Secondary Scan Response packet (optional) |
| 46 | + // Since there is no room for 'Name' in Advertising packet |
| 47 | + Bluefruit.ScanResponse.addName(); |
| 48 | + |
| 49 | + /* Start Advertising |
| 50 | + * - Enable auto advertising if disconnected |
| 51 | + * - Timeout for fast mode is 30 seconds |
| 52 | + * - Start(timeout) with timeout = 0 will advertise forever (until connected) |
| 53 | + * |
| 54 | + * Apple Beacon specs |
| 55 | + * - Type: Non connectable, undirected |
| 56 | + * - Fixed interval: 100 ms -> fast = slow = 100 ms |
| 57 | + */ |
| 58 | + //Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_ADV_NONCONN_IND); |
| 59 | + Bluefruit.Advertising.restartOnDisconnect(true); |
| 60 | + Bluefruit.Advertising.setInterval(160, 160); // in unit of 0.625 ms |
| 61 | + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode |
| 62 | + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds |
| 63 | +} |
| 64 | + |
| 65 | +void loop() |
| 66 | +{ |
| 67 | + // Toggle both LEDs every second |
| 68 | + digitalToggle(LED_RED); |
| 69 | + delay(1000); |
| 70 | +} |
| 71 | + |
0 commit comments