When the timing for advertising to be active

Hiroaki_Maezawa
Thu, 02 Jun 2022 02:43:21 +0000
Mbed OS

I’m testing to use gap().stopAdvertising() function.

The advertising interval is set to 1000ms in the advertising parameter;

        ble::adv_interval_t(ble::millisecond_t(1000))

and start advertising;

         error = _ble.gap().startAdvertising(ble::LEGACY_ADVERTISING_HANDLE);

        if (error) {
            print_error(error, "_ble.gap().startAdvertising() failed");
            return;
        }
        adv_flag = true;

Then, in the _event_queue.call_every(), the interval for try to stop and restart advertising is set. Before stop and start advertising, gap().isAdvertisingActive() function check wheather is advertising active.

        _event_queue.call_every(
            100ms,
            [this]() {

                update_battery_level();

                if (_ble.gap().isAdvertisingActive(ble::LEGACY_ADVERTISING_HANDLE) && adv_flag) {

                    ble_error_t error = _ble.gap().stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE);
                    if (error) {
                        print_error(error, "_ble.gap().stopAdvertising() failed.");
                        return;
                    }
                    adv_flag = false;
                    printf("_ble.gap().stopAdvertising() successed.\n");
                }

                if ( !_ble.gap().isAdvertisingActive(ble::LEGACY_ADVERTISING_HANDLE) && !adv_flag) {

                    ble_error_t error = _ble.gap().startAdvertising(ble::LEGACY_ADVERTISING_HANDLE);
                    if (error) {
                        print_error(error, "_ble.gap().startAdvertising() failed.");
                        return;
                    }
                    adv_flag = true;
                    printf("_ble.gap().startAdvertising() successed.\n");
                }

            }
        );

Working with Mbed Studio, mbed os 6 and nRF52840 DK.
Source code refers to ARMmbed/mbed-os-example/BLE_Advertising.

I expected that the advertising is stop and restart in 100ms interval, but actualy the interval is 1000ms.
That is, it takes the same time interval as the advertising interval for the advertising to be active.

When does the advertising become active status, after the gap().start Advertising() is called?
Why does it depend on the advertising interval to be active status?

1 post - 1 participant