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

Add API to set advertising scheme on disconnected #2837

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

XuGuohui
Copy link
Member

Problem

Currently when device acting as BLE peripheral is disconnected from peer device, it will re-start advertising automatically. In some use cases, user may wants to stop advertising on disconnected, unless otherwise user manually calls BLE.advertise() to start advertising.

Solution

Add wiring API to set advertising scheme for which after disconnected from peer deivce.

Example App

#include "application.h"

SYSTEM_MODE(MANUAL);

SerialLogHandler logHandler(LOG_LEVEL_ALL);

system_tick_t disconTime = 0;
bool restartAdv = false;

/* executes once at startup */
void setup() {
    // BLE.setAdvertisingScheme(BleAdvertisingScheme::RESTART_ADV_ON_DISCONNECTED);
    // BLE.setAdvertisingScheme(BleAdvertisingScheme::STOP_ADV_ON_DISCONNECTED);
    BLE.setAdvertisingScheme(BleAdvertisingScheme::STOP_ADV_ON_DISCONNECTED_ONCE);
    BLE.advertise();
    BLE.onDisconnected([&](const BlePeerDevice& peer) {
        disconTime = millis();
        restartAdv = true;
    });
}

/* executes continuously after setup() runs */
void loop() {
    if (restartAdv && (millis() - disconTime > 15000)) {
        restartAdv = false;
        if (!BLE.advertising()) {
            Log.info("Restarting advertising");
            BLE.advertise();
        }
    }
}

References

https://community.particle.io/t/ble-disconnect-works-but-then-reconnects/68469


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui added feature ble Bluetooth Low Energy labels Oct 16, 2024
@XuGuohui XuGuohui added this to the 6.2.1 milestone Oct 16, 2024
@XuGuohui
Copy link
Member Author

TODO: I'll add on-device tests after we approve the wiring API prototypes.

Copy link
Member

@avtolstoy avtolstoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuGuohui Can we add a test for this to ble central/peripheral suite?

wiring/inc/spark_wiring_ble.h Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ble Bluetooth Low Energy feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants