From 01eaf9ce80b9e660c2edb75cdfed8812a53f4047 Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Wed, 1 Jul 2026 07:01:39 +0000 Subject: [PATCH] Fix enable-after-Arduino-init: always try to enable Arduino framework inits BT controller but does NOT enable it. Previous patch skipped both init AND enable when init returned ESP_ERR_INVALID_STATE, leaving controller in init'd-but-not-enabled state. Now we always try to enable regardless of init outcome. --- pre_build.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pre_build.py b/pre_build.py index e87fadf..70783d7 100644 --- a/pre_build.py +++ b/pre_build.py @@ -185,13 +185,16 @@ def patch_nimble_device(): content = f.read() # v1.4.3 code has ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg)); + # Arduino framework inits controller but does NOT enable it. + # We must enable even if init returns INVALID_STATE (already init'd). old_block = ( 'ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));\n' ' ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n' ' ESP_ERROR_CHECK(esp_nimble_hci_init());' ) new_block = ( - 'if (esp_bt_controller_init(&bt_cfg) == ESP_OK) {\n' + 'esp_err_t __bt_err = esp_bt_controller_init(&bt_cfg);\n' + ' if (__bt_err == ESP_OK || __bt_err == ESP_ERR_INVALID_STATE) {\n' ' ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n' ' }\n' ' ESP_ERROR_CHECK(esp_nimble_hci_init());'