8 years, 4 months ago.

How can I update the Advertising Payload? ble.gap().updateAdvertisingPayload() not working

Hello everyone, I was trying to update the advertising payload in this way:

t

ble.gap().updateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t));

this, to update my trasmitted appData. The call reports BLE_ERROR_NONE so it seems to work but the advertising data remains the same as it was before the function update was called.

I also tried to stop, clear and setup again the advertising but the stop is not implemented in the BLE_API, even if it seems implemented in the X-NUCLEO IDB0XA1 library, so it returns error:

t

 ble.gap().stopAdvertising();
 ble.gap().clearAdvertisingPayload();

    /* Setup advertising payload */
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
    ApplicationData_t appData;
    setupApplicationData(appData);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t));

    /* Setup advertising parameters */
    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
    ble.gap().setAdvertisingInterval(500);

    ble.gap().startAdvertising();

How can I update the advertising payload? Thank you very much

Question relating to:

Hi Sara, thanks for your feedback! I just patched the X-NUCLEO-IDB0XA1 library. Now the ADV payload updates are correctly handled and transmitted. Please, check out the BLE_dummyBeacon code posted by Gabriele and try to run after updating the underlying libraries.

Let me know and regards.

posted by Andrea Palmieri 18 Mar 2016

Thank you very much! Now, I can correctly see the updated data.

Best regards

posted by Sara Carbonara 18 Mar 2016

2 Answers

8 years, 1 month ago.

Hi Andrea, I've tried to run the code posted by Gabriele, using the NUCLEO-F401RE platform, the BLE expansion board X-NUCLEO-IDB04A1 and the "BLE Scanner" app for iOS. I'm not able to see the updates of the dummy variable. How did you check the correctness of the code posted? Which was your environment?

Thank you for your help

Hi Sara, please check the comment I left above.

posted by Andrea Palmieri 18 Mar 2016
8 years, 4 months ago.

Dear Gabriele,

both the updateAdvertisingPayload() and the stopAdvertising() are fully supported. The second one is a virtual function implemented by the specific BLE wrapper, in this case the X_NUCLEO_IDB0XA1 lib by ST.

Just to be sure about the correct usage of the APIs, can you kindly provide the full main code you are using for your test?

Regards

Thank you for your answer.

Here, there is the code with which I try to update the adv payload

t

#include "mbed.h"
#include "toolchain.h"
#include "ble/BLE.h"
#include "hts221.h"

BLE ble;

static Ticker ticker;
static DigitalOut alivenessLED(LED1, 1);

struct ApplicationData_t {
    uint16_t                     applicationSpecificId; /* An ID used to identify temperature value in the manufacture specific AD data field */
    float                        tmpSensorValue;        /* User defined application data */
    float                        humiditySensorValue;   /* User defined application data */
} PACKED;

void setupApplicationData(ApplicationData_t &appData)
{
    static const uint16_t APP_SPECIFIC_ID_TEST = 0xFEFE;
    appData.applicationSpecificId = APP_SPECIFIC_ID_TEST;
    HTS221_ReadTempHumi(&appData.tmpSensorValue, &appData.humiditySensorValue);
    
}

void startAdvertisingTemperature(void)
{
    /* Setup advertising payload */
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
    ApplicationData_t appData;
    setupApplicationData(appData);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t));

    /* Setup advertising parameters */
    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
    ble.gap().setAdvertisingInterval(500);

    ble.gap().startAdvertising();
}

void periodicCallback(void)
{
    alivenessLED = !alivenessLED;  /* Do blinky on LED1 while we're waiting for BLE events. */

    ApplicationData_t appData;
    setupApplicationData(appData);
   
    ble_error_t ret;
    ret=ble.gap().updateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&appData, sizeof(ApplicationData_t));
    
    if (ret==BLE_ERROR_NONE)
        printf("NO ERROR update\n\r"); 
    else
        printf("ERROR UPDATE!!!\n\r");
  
}   


int main(void)
{
    ble.init();
    hts221_init();
    HTS221_Calib();
    startAdvertisingTemperature();
    
    ticker.attach(periodicCallback, 1); 

    while (true) {
        ble.waitForEvent();
    }
}


posted by gabriele calianno 14 Dec 2015

Hi Gabriele,

it is not safe to trigger a BLE stack call in interrupt context. Please, try to disjoin the ticker events and the ADV payload updates.

posted by Andrea Palmieri 14 Dec 2015

Dear Andrea, Thank you very much for your prompt reply. I followed your advice and I wrote this code: https://developer.mbed.org/teams/lasCuadra/code/BLE_dummyBeacon/

But I cannot update the adv payload, it is stuck at 0 from the beginning, it's very strange

Thank you for your help

posted by gabriele calianno 16 Dec 2015

Hi Gabriele,

I just run your code and the dummyValue is correctly incremented at 2 secs interval. What is your setup? I mean, which platform you are testing? How do you read the payload? You can enable the DEBUG macro (disabled by default) in debug.h Besides, the mbed lib needs to be updated in your project.

Let me know

posted by Andrea Palmieri 16 Dec 2015