From 9395d547353ef6b780eeb7e78b43c3803711e7ee Mon Sep 17 00:00:00 2001 From: entr0p1 <1475255+entr0p1@users.noreply.github.com> Date: Thu, 30 Jul 2026 13:18:19 +1000 Subject: [PATCH] If radio_init() fails on the first attempt, currently the board will halt immediately with no feedback. This commit changes the behaviour to make 3 attempts to call the init. After 3 failures, the board will reboot. --- examples/companion_radio/main.cpp | 11 ++++++++++- examples/kiss_modem/main.cpp | 11 +++++++++-- examples/simple_repeater/main.cpp | 12 +++++++++--- examples/simple_room_server/main.cpp | 11 ++++++++++- examples/simple_secure_chat/main.cpp | 11 ++++++++++- examples/simple_sensor/main.cpp | 11 ++++++++++- 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index d39aeef95..f784ccaa4 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -135,7 +135,16 @@ void setup() { } #endif - if (!radio_init()) { halt(); } + int radioinit_attempts = 0; + while (!radio_init()) { + ++radioinit_attempts; + MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts); + if (radioinit_attempts >= 3) { + MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting"); + board.reboot(); + } + delay(500); + } fast_rng.begin(radio_driver.getRngSeed()); diff --git a/examples/kiss_modem/main.cpp b/examples/kiss_modem/main.cpp index 5836a6941..8d254cefc 100644 --- a/examples/kiss_modem/main.cpp +++ b/examples/kiss_modem/main.cpp @@ -78,8 +78,15 @@ void onGetStats(uint32_t* rx, uint32_t* tx, uint32_t* errors) { void setup() { board.begin(); - if (!radio_init()) { - halt(); + int radioinit_attempts = 0; + while (!radio_init()) { + ++radioinit_attempts; + MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts); + if (radioinit_attempts >= 3) { + MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting"); + board.reboot(); + } + delay(500); } radio_driver.begin(); diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index a714db68e..e5b57a068 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -60,9 +60,15 @@ void setup() { } #endif - if (!radio_init()) { - MESH_DEBUG_PRINTLN("Radio init failed!"); - halt(); + int radioinit_attempts = 0; + while (!radio_init()) { + ++radioinit_attempts; + MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts); + if (radioinit_attempts >= 3) { + MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting"); + board.reboot(); + } + delay(500); } fast_rng.begin(radio_driver.getRngSeed()); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index d833fff39..db314b33a 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -45,7 +45,16 @@ void setup() { } #endif - if (!radio_init()) { halt(); } + int radioinit_attempts = 0; + while (!radio_init()) { + ++radioinit_attempts; + MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts); + if (radioinit_attempts >= 3) { + MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting"); + board.reboot(); + } + delay(500); + } fast_rng.begin(radio_driver.getRngSeed()); diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index da42ddcbb..c4929c053 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -564,7 +564,16 @@ void setup() { external_watchdog.begin(); #endif - if (!radio_init()) { halt(); } + int radioinit_attempts = 0; + while (!radio_init()) { + ++radioinit_attempts; + MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts); + if (radioinit_attempts >= 3) { + MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting"); + board.reboot(); + } + delay(500); + } fast_rng.begin(radio_driver.getRngSeed()); diff --git a/examples/simple_sensor/main.cpp b/examples/simple_sensor/main.cpp index 69182f3a7..3b98d34cc 100644 --- a/examples/simple_sensor/main.cpp +++ b/examples/simple_sensor/main.cpp @@ -70,7 +70,16 @@ void setup() { } #endif - if (!radio_init()) { halt(); } + int radioinit_attempts = 0; + while (!radio_init()) { + ++radioinit_attempts; + MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts); + if (radioinit_attempts >= 3) { + MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting"); + board.reboot(); + } + delay(500); + } fast_rng.begin(radio_driver.getRngSeed());