Skip to content

API: set advertising param functions return success #133

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

Conversation

polldo
Copy link
Contributor

@polldo polldo commented Nov 2, 2020

API functions to set the parameters of advertising data return a bool value:

  • 'true' -> advertising parameter is correctly set
  • 'false' -> advertising parameter is not set, there is not enough space in the packet to advertise it

Example sketch:

Using standard advertising method

#include <ArduinoBLE.h>

// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop'
const uint8_t manufactData[4] = {0};
const uint8_t manufactDataLong[30] = {0};

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

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

  bool success = BLE.setLocalName("Test advertising return type");
  if (!success) { Serial.println("Failed to set parameter, not enough space available"); }

  // Try to set a too long manufacturer data
  success = BLE.setManufacturerData(0x004C, manufactDataLong, sizeof(manufactDataLong));
  if (!success) { Serial.println("Failed to set parameter, not enough space available"); }
  // Set a shorter manufacturer data
  success = BLE.setManufacturerData(0x004C, manufactData, sizeof(manufactData));
  if (!success) { Serial.println("Failed to set parameter, not enough space available"); }

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

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

Using enhanced advertising method

#include <ArduinoBLE.h>

// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop'
const uint8_t manufactData[4] = {0};
const uint8_t manufactDataLong[30] = {0};

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

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

  // Build scan response data packet
  BLEAdvertisingData scanData;
  bool success = scanData.setLocalName("Test advertising return type");
  if (!success) { Serial.println("Failed to set parameter, not enough space available"); }
  BLE.setScanResponseData(scanData);

  // Build advertising data packet
  BLEAdvertisingData advData;
  // Try to set a too long manufacturer data
  success = advData.setManufacturerData(0x004C, manufactDataLong, sizeof(manufactDataLong));
  if (!success) { Serial.println("Failed to set parameter, not enough space available"); }
  // Set a shorter manufacturer data
  success = advData.setManufacturerData(0x004C, manufactData, sizeof(manufactData));
  if (!success) { Serial.println("Failed to set parameter, not enough space available"); }
  BLE.setAdvertisingData(advData);

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

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

The functions to set the parameters of the advertising data return a bool value.
return 'true' -> advertising parameter is correctly set
return 'false' -> advertising parameter is not set, there is no enough space in the packet to advertise it
@polldo polldo requested review from facchinm and giulcioffi November 2, 2020 14:06
@facchinm facchinm merged commit 51595db into arduino-libraries:master Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants