Skip to content

Commit b228cba

Browse files
committed
espress/common-hal/_bleio: Adapter.c: handle BLE_HS_EBUSY on scan
1 parent 6bf9ec7 commit b228cba

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ports/espressif/common-hal/_bleio/Adapter.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,19 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t
290290
duration_ms = BLE_HS_FOREVER;
291291
}
292292

293-
CHECK_NIMBLE_ERROR(ble_gap_disc(own_addr_type, duration_ms, &disc_params,
294-
_scan_event, self->scan_results));
293+
int tries = 5;
294+
int status;
295+
// BLE_HS_EBUSY may occasionally occur, indicating something has not finished. Retry a few times if so.
296+
do {
297+
status = ble_gap_disc(own_addr_type, duration_ms, &disc_params,
298+
_scan_event, self->scan_results);
299+
if (status != BLE_HS_EBUSY) {
300+
break;
301+
}
302+
common_hal_time_delay_ms(50);
303+
RUN_BACKGROUND_TASKS;
304+
} while (tries-- > 0);
305+
CHECK_NIMBLE_ERROR(status);
295306

296307
return MP_OBJ_FROM_PTR(self->scan_results);
297308
}

0 commit comments

Comments
 (0)