Closed danielkucera closed 4 years ago
I was under the impression that NimBLE automatically stops advertising as soon as it is connected to a host. Is this assumption incorrect?
@bergzand , no, it does not stop. You can try connecting with Gadgetbridge and scan afterwards with https://play.google.com/store/apps/details?id=uk.co.alt236.btlescan and the same after applying my patch
Without the patch, if I connect the pinetime with my laptop, it does not show up in Gadgetbridge or in nRF connect app. As soon as I disconnect it pops up almost immediately.
I'll try to find confirmation of this in the NimBLE source code.
With the following patch applied:
diff --git a/modules/bleman/bleman.c b/modules/bleman/bleman.c
index 3ff7318..39ec2f9 100644
--- a/modules/bleman/bleman.c
+++ b/modules/bleman/bleman.c
@@ -123,6 +123,10 @@ static int _gap_event_cb(struct ble_gap_event *event, void *arg)
return 0;
}
else {
+ int res = ble_gap_adv_stop();
+ if (res != 0) {
+ LOG_WARNING("[bleman]: unable to stop advertisements: %d\n", res);
+ }
bleman->conn_handle = event->connect.conn_handle;
bleman->state = BLEMAN_BLE_STATE_CONNECTED;
When connecting it logs that it is unable to stop advertisements with result code 2 (BLE_HS_EALREADY
) meaning that advertisements are already disabled.
You are right. I don't know how I was testing this.
to save power.