From db7e72b43de57cdf789471717f69092bf5a4d376 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 31 Jan 2022 15:45:43 -0800 Subject: [PATCH] Fix BLE scanning forever on ESP32-S3 --- ports/espressif/common-hal/_bleio/Adapter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/espressif/common-hal/_bleio/Adapter.c b/ports/espressif/common-hal/_bleio/Adapter.c index 1927d6da62..288a908546 100644 --- a/ports/espressif/common-hal/_bleio/Adapter.c +++ b/ports/espressif/common-hal/_bleio/Adapter.c @@ -229,7 +229,12 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t disc_params.filter_policy = 0; disc_params.limited = 0; - CHECK_NIMBLE_ERROR(ble_gap_disc(own_addr_type, timeout * 1000, &disc_params, + size_t duration_ms = timeout * 1000; + if (duration_ms == 0) { + duration_ms = BLE_HS_FOREVER; + } + + CHECK_NIMBLE_ERROR(ble_gap_disc(own_addr_type, duration_ms, &disc_params, _scan_event, self->scan_results)); return MP_OBJ_FROM_PTR(self->scan_results);