Skip to content

Add enhanced advertising examples #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <ArduinoBLE.h>

BLEService myService("fff0");
BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast);

// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop'
const uint8_t manufactData[4] = {0x01, 0x02, 0x03, 0x04};
const uint8_t serviceData[3] = {0x00, 0x01, 0x02};

void setup() {
Serial.begin(9600);
while (!Serial);

if (!BLE.begin()) {
Serial.println("failed to initialize BLE!");
while (1);
}

myService.addCharacteristic(myCharacteristic);
BLE.addService(myService);

// Build scan response data packet
BLEAdvertisingData scanData;
// Set parameters for scan response packet
scanData.setLocalName("Test enhanced advertising");
// Copy set parameters in the actual scan response packet
BLE.setScanResponseData(scanData);

// Build advertising data packet
BLEAdvertisingData advData;
// Set parameters for advertising packet
advData.setManufacturerData(0x004C, manufactData, sizeof(manufactData));
advData.setAdvertisedService(myService);
advData.setAdvertisedServiceData(0xfff0, serviceData, sizeof(serviceData));
// Copy set parameters in the actual advertising packet
BLE.setAdvertisingData(advData);

BLE.advertise();
Serial.println("advertising ...");
}

void loop() {
BLE.poll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <ArduinoBLE.h>

BLEService myService("fff0");
BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast);

// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop'
const uint8_t completeRawAdvertisingData[] = {0x02,0x01,0x06,0x09,0xff,0x01,0x01,0x00,0x01,0x02,0x03,0x04,0x05};

void setup() {
Serial.begin(9600);
while (!Serial);

if (!BLE.begin()) {
Serial.println("failed to initialize BLE!");
while (1);
}

myService.addCharacteristic(myCharacteristic);
BLE.addService(myService);

// Build advertising data packet
BLEAdvertisingData advData;
// If a packet has a raw data parameter, then all the other parameters of the packet will be ignored
advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData));
// Copy set parameters in the actual advertising packet
BLE.setAdvertisingData(advData);

// Build scan response data packet
BLEAdvertisingData scanData;
scanData.setLocalName("Test advertising raw data");
// Copy set parameters in the actual scan response packet
BLE.setScanResponseData(scanData);

BLE.advertise();

Serial.println("advertising ...");
}

void loop() {
BLE.poll();
}