Skip to content

Commit 50bccee

Browse files
committed
Fix connection timeout and packetbuffer error
1 parent 4c85b5f commit 50bccee

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ mp_obj_t common_hal_bleio_adapter_connect(bleio_adapter_obj_t *self, bleio_addre
408408
_connect_event, self));
409409

410410
int error_code;
411-
CHECK_NOTIFY(xTaskNotifyWait(0, 0, (uint32_t *)&error_code, 200));
411+
// Wait an extra 50 ms to give the connect method the opportunity to time out.
412+
CHECK_NOTIFY(xTaskNotifyWait(0, 0, (uint32_t *)&error_code, pdMS_TO_TICKS(timeout * 1000 + 50)));
412413
// Negative values are error codes, connection handle otherwise.
413414
if (error_code < 0) {
414415
CHECK_BLE_ERROR(-error_code);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static int queue_next_write(bleio_packet_buffer_obj_t *self) {
9292
// Allocate an mbuf because the functions below consume it.
9393
struct os_mbuf *om = ble_hs_mbuf_from_flat(self->outgoing[self->pending_index], self->pending_size);
9494
if (om == NULL) {
95+
// We may not have any more mbufs if BLE busy. It isn't a problem (yet) so we'll
96+
// just skip queueing for now.
9597
return BLE_HS_ENOMEM;
9698
}
9799
size_t pending_size = self->pending_size;
@@ -331,7 +333,8 @@ mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, c
331333

332334
// If no writes are queued then sneak in this data.
333335
if (!self->packet_queued) {
334-
CHECK_NIMBLE_ERROR(queue_next_write(self));
336+
// This will queue up the packet even if it can't send immediately.
337+
queue_next_write(self);
335338
}
336339
return num_bytes_written;
337340
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void check_nimble_error(int rc, const char *file, size_t line) {
9999
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
100100
return;
101101
default:
102-
#if CIRCUITPY_VERBOSE_BLE
102+
#if CIRCUITPY_VERBOSE_BLE || CIRCUITPY_DEBUG
103103
if (file) {
104104
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Unknown system firmware error at %s:%d: %d"), file, line, rc);
105105
}
@@ -126,7 +126,7 @@ void check_ble_error(int error_code, const char *file, size_t line) {
126126
mp_raise_bleio_SecurityError(MP_ERROR_TEXT("Insufficient encryption"));
127127
return;
128128
default:
129-
#if CIRCUITPY_VERBOSE_BLE
129+
#if CIRCUITPY_VERBOSE_BLE || CIRCUITPY_DEBUG
130130
if (file) {
131131
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Unknown BLE error at %s:%d: %d"), file, line, error_code);
132132
}

0 commit comments

Comments
 (0)