Skip to content
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

v1.4.2: Allow dynamically change advertising data #743

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions src/NimBLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,33 @@ int NimBLEAdvertising::handleGapEvent(struct ble_gap_event *event, void *arg) {
return 0;
}

/**
* @brief Refresh advertsing data dynamically without stop/start cycle
* For instance allows refreshing manufacturer data dynamically
*
* @return int - error code from the operation
*/
int NimBLEAdvertising::refreshAdvertisingData() {
int rc = ble_gap_adv_set_fields(&m_advData);
switch(rc) {
case 0:
break;

case BLE_HS_EBUSY:
NIMBLE_LOGE(LOG_TAG, "Already advertising");
break;

case BLE_HS_EMSGSIZE:
NIMBLE_LOGE(LOG_TAG, "Advertisement data too long");
break;

default:
NIMBLE_LOGE(LOG_TAG, "Error setting advertisement data; rc=%d, %s",
rc, NimBLEUtils::returnCodeToString(rc));
break;
}
return rc;
}

/**
* @brief Add data to the payload to be advertised.
Expand Down
1 change: 1 addition & 0 deletions src/NimBLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class NimBLEAdvertising {
void reset();
void advCompleteCB();
bool isAdvertising();
int refreshAdvertisingData();

private:
friend class NimBLEDevice;
Expand Down