Fix Companion pairing PIN display and truthful identity startup

This commit is contained in:
mikecarper committed 2026-10-02 12:42:26 -07:00
1 parent a2854f8f43
commit 202930de8f
31 files changed
+1915 -148

No files matched your search

+25 -2
View File
@@ -1,4 +1,5 @@
#include <helpers/ui/DisplayPowerSettings.h>
#include <helpers/ui/StartupScreen.h>
#include "NotificationSettingsFile.h"
#include "MyMesh.h"
#include <helpers/CompanionTxRoutingCLI.h>
@@ -2339,7 +2340,8 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
if (_ui != nullptr) _ui->setShutdownGuard(this);
}
void MyMesh::begin(bool has_display, bool radio_available) {
void MyMesh::begin(bool has_display, bool radio_available,
mesh::ui::StartupScreen* startup_screen) {
_radio_available = radio_available;
setRadioAvailable(radio_available);
initializeContactStorage();
@@ -2354,6 +2356,9 @@ void MyMesh::begin(bool has_display, bool radio_available) {
mesh::ota::ota_set_context_config_loader(mesh::ota::loadCompanionOtaConfig);
#endif
#ifdef DISPLAY_CLASS
if (startup_screen != nullptr) startup_screen->loadingIdentity();
#endif
const bool identity_loaded = _store->loadMainIdentity(self_id);
const bool is_new_install = !identity_loaded
|| mesh::hasReservedIdentityPrefix(self_id);
@@ -2366,9 +2371,27 @@ void MyMesh::begin(bool has_display, bool radio_available) {
bool identity_ready = true;
if (is_new_install) {
identity_ready = mesh::generateUsableLocalIdentity(self_id, radio_new_identity);
{
#ifdef DISPLAY_CLASS
if (startup_screen != nullptr) startup_screen->generatingKey();
mesh::ScopedIdentityGenerationProgress progress(
mesh::ui::StartupScreen::progress, startup_screen);
#endif
identity_ready = mesh::generateUsableLocalIdentity(self_id, radio_new_identity);
}
#ifdef DISPLAY_CLASS
// Generation has finished. Flash persistence must never retain its label
// or cooperative animation callback.
if (startup_screen != nullptr) {
if (identity_ready) startup_screen->savingIdentity();
else startup_screen->starting();
}
#endif
if (identity_ready) identity_ready = _store->saveMainIdentity(self_id);
}
#ifdef DISPLAY_CLASS
if (startup_screen != nullptr) startup_screen->starting();
#endif
#if defined(ESP32_PLATFORM)
mesh::discardESP32TrueRandom();
+4 -1
View File
@@ -161,6 +161,8 @@ struct DiscoveredNode {
};
#endif
namespace mesh { namespace ui { class StartupScreen; } }
class MyMesh : public BaseChatMesh, public DataStoreHost, public UIShutdownGuard
#if COMPANION_FEATURE_NOTIFICATIONS
, public mesh::notify::Sink, public mesh::notify::Store
@@ -179,7 +181,8 @@ public:
return handleCommand(command, 0, reply);
}
void begin(bool has_display, bool radio_available = true);
void begin(bool has_display, bool radio_available = true,
mesh::ui::StartupScreen* startup_screen = nullptr);
void activateRadio();
bool isRadioReady() const { return _radio_available; }
void startInterface(BaseSerialInterface &serial);
+78 -35
View File
@@ -1,10 +1,15 @@
#include <Arduino.h> // needed for PlatformIO
#include <helpers/ui/StartupScreen.h>
#include <helpers/ui/DisplayPowerSettings.h>
#include <Mesh.h>
#include <helpers/BluetoothMac.h>
#include "MyMesh.h"
#include "CompanionBluetooth.h"
#include "CompanionWireless.h"
#include "CompanionWiFi.h"
#if defined(COMPANION_PAIRING_UI_HIL)
void companionPairingUiHilProbe();
#endif
#if MESH_PACKET_LOGGING
#include <helpers/SerialPacketLog.h>
#endif
@@ -2788,6 +2793,65 @@ void setup() {
external_watchdog.begin();
#endif
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
#if defined(NRF52_PLATFORM)
// InternalFileSystem::begin() auto-formats the entire primary store after a
// mount failure. The base mount plus a full raw scan distinguishes a virgin
// erased device from nonblank/corrupt identity storage. Only proven-erased
// media may be initialized automatically. A nonblank failure gets three
// additional mounts three seconds apart before the unusable store is erased
// so the node can still recover without physical access.
const mesh::storage::InternalSecondaryFsBootResult primary_fs_boot =
mesh::storage::beginInternalPrimaryFilesystemSafely(
InternalFS,
#if defined(EXTRAFS) && !defined(QSPIFLASH)
ResilientInternalExtraFS::primaryConfig()
#else
nullptr
#endif
);
if (!mesh::storage::internalPrimaryFilesystemReady(primary_fs_boot)) {
mesh::storage::RamFallbackFileSystem* ram_primary_fs =
mesh::storage::createRamFallbackFileSystem();
if (ram_primary_fs != nullptr) {
MESH_DEBUG_PRINTLN(
"InternalFS: physical storage unusable; running from volatile RAM filesystem");
store.useVolatilePrimaryFS(ram_primary_fs->filesystem());
} else {
MESH_DEBUG_PRINTLN(
"InternalFS: physical storage and RAM fallback initialization failed");
store.markPrimaryFSUnavailable();
}
}
#else
InternalFS.begin();
#endif
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
#elif defined(ESP32)
SPIFFS.begin(true);
#else
#error "need to define filesystem"
#endif
#ifdef DISPLAY_CLASS
// Load only the display policy before radio and secondary-storage startup.
FILESYSTEM* display_prefs_fs = store.getPrimaryFS();
#if defined(NRF52_PLATFORM)
// Never open files on a primary store whose mount and RAM fallback failed.
if (!mesh::storage::internalPrimaryFilesystemReady(primary_fs_boot)
&& !store.isVolatilePrimaryFS()) display_prefs_fs = nullptr;
#endif
mesh::ui::loadDisplayPowerSettings(display_prefs_fs,
#ifdef BLE_PIN_CODE
true,
#else
false,
#endif
true);
mesh::ui::StartupScreen startup_screen;
#endif
#ifdef DISPLAY_CLASS
DisplayDriver* disp = NULL;
if (display.begin()) {
@@ -2796,7 +2860,8 @@ void setup() {
&& UI_WIFI_SETUP_HOME_PAGE != 1
companion_setup_display = disp;
#endif
disp->turnOff(); // No boot content before the saved policy is loaded.
startup_screen.begin(disp,
board.isExternalPowered() || board.isUsbHostConnected());
}
#if defined(ESP32) && defined(WIFI_SSID)
companion_display_available = disp != NULL;
@@ -2846,38 +2911,6 @@ void setup() {
#endif
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
#if defined(NRF52_PLATFORM)
// InternalFileSystem::begin() auto-formats the entire primary store after a
// mount failure. The base mount plus a full raw scan distinguishes a virgin
// erased device from nonblank/corrupt identity storage. Only proven-erased
// media may be initialized automatically. A nonblank failure gets three
// additional mounts three seconds apart before the unusable store is erased
// so the node can still recover without physical access.
const mesh::storage::InternalSecondaryFsBootResult primary_fs_boot =
mesh::storage::beginInternalPrimaryFilesystemSafely(
InternalFS,
#if defined(EXTRAFS) && !defined(QSPIFLASH)
ResilientInternalExtraFS::primaryConfig()
#else
nullptr
#endif
);
if (!mesh::storage::internalPrimaryFilesystemReady(primary_fs_boot)) {
mesh::storage::RamFallbackFileSystem* ram_primary_fs =
mesh::storage::createRamFallbackFileSystem();
if (ram_primary_fs != nullptr) {
MESH_DEBUG_PRINTLN(
"InternalFS: physical storage unusable; running from volatile RAM filesystem");
store.useVolatilePrimaryFS(ram_primary_fs->filesystem());
} else {
MESH_DEBUG_PRINTLN(
"InternalFS: physical storage and RAM fallback initialization failed");
store.markPrimaryFSUnavailable();
}
}
#else
InternalFS.begin();
#endif
#if defined(QSPIFLASH)
if (!QSPIFlash.begin()) {
// debug output might not be available at this point, might be too early. maybe should fall back to InternalFS here?
@@ -2934,6 +2967,9 @@ void setup() {
#endif
,
radio_available
#ifdef DISPLAY_CLASS
, &startup_screen
#endif
);
#if defined(NRF52_PLATFORM)
if (store.isVolatilePrimaryFS()) {
@@ -2945,7 +2981,6 @@ void setup() {
}
#endif
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
store.begin();
the_mesh.begin(
#ifdef DISPLAY_CLASS
@@ -2955,9 +2990,11 @@ void setup() {
#endif
,
radio_available
#ifdef DISPLAY_CLASS
, &startup_screen
#endif
);
#elif defined(ESP32)
SPIFFS.begin(true);
store.begin();
the_mesh.begin(
#ifdef DISPLAY_CLASS
@@ -2967,6 +3004,9 @@ void setup() {
#endif
,
radio_available
#ifdef DISPLAY_CLASS
, &startup_screen
#endif
);
#else
#error "need to define filesystem"
@@ -3310,6 +3350,9 @@ void loop() {
#else
ui_task.loop();
#endif
#endif
#if defined(COMPANION_PAIRING_UI_HIL)
companionPairingUiHilProbe();
#endif
rtc_clock.tick();
board.loop();
+25 -8
View File
@@ -840,11 +840,7 @@ public:
const char* pairing_value = nullptr;
int pairing_value_size = 2;
char pairing_pin[16];
if (client_label != nullptr && !_task->isPairingPromptActive()) {
pairing_label = expanded_home && strcmp(client_label, "BLUETOOTH") == 0 ? "BLE" : client_label;
pairing_value = expanded_home ? "LINKED" : "CONNECTED";
if (expanded_home) pairing_value_size = 3;
} else if (mesh::ui::shouldDisplayBluetoothPairingPin(
if (mesh::ui::shouldDisplayBluetoothPairingPin(
bluetooth_enabled, bluetooth_connected, bluetooth_pin)
&& (!_task->isPairingPromptActive()
|| display.height() > 64)) {
@@ -853,6 +849,10 @@ public:
(unsigned int)bluetooth_pin);
pairing_value = pairing_pin;
pairing_value_size = 3;
} else if (client_label != nullptr && !_task->isPairingPromptActive()) {
pairing_label = expanded_home && strcmp(client_label, "BLUETOOTH") == 0 ? "BLE" : client_label;
pairing_value = expanded_home ? "LINKED" : "CONNECTED";
if (expanded_home) pairing_value_size = 3;
}
if (pairing_value != nullptr) {
@@ -901,7 +901,8 @@ public:
const char* client_label = _task->connectedClientLabel();
if (client_label != nullptr || show_bluetooth_pin) {
char pairing_pin[16];
const bool show_client = client_label != nullptr && !_task->isPairingPromptActive();
const bool show_client = client_label != nullptr && !show_bluetooth_pin
&& !_task->isPairingPromptActive();
const char* pairing_label = show_client ? client_label : "BLUETOOTH PIN";
const char* pairing_value = "CONNECTED";
if (!show_client) {
@@ -2150,11 +2151,16 @@ void UITask::renderPairingBanner() {
_display->drawTextCentered(_display->width() / 2, 2, prompt);
}
void UITask::showPairingPin() {
void UITask::showPairingPin(bool from_button) {
if (!isBluetoothEnabled()) return;
const unsigned long now = millis();
_pairing_screen_until = now + BLE_PAIRING_DISPLAY_MILLIS;
_pairing_from_button = from_button;
const auto& prefs = mesh::ui::displayPowerPrefs();
const auto& profile = (_board->isExternalPowered() || _board->isUsbHostConnected())
? prefs.usb : prefs.battery;
_pairing_screen_until = now + (from_button
? uint32_t(profile.seconds) * 1000U : BLE_PAIRING_DISPLAY_MILLIS);
if (curr == msg_preview && _msgcount > 0) {
_deferred_msg_preview = true;
}
@@ -2168,6 +2174,7 @@ void UITask::showPairingPin() {
void UITask::finishPairingScreen(bool timed_out) {
_pairing_screen_until = 0;
_pairing_from_button = false;
if (_deferred_msg_preview && !hasConnection()
&& static_cast<MsgPreviewScreen*>(msg_preview)->hasMessages()) {
@@ -2424,6 +2431,12 @@ void UITask::loop() {
}
#endif
// A button-wake PIN is a preview, not a modal pairing request. The next
// navigation gesture must still work; real phone requests retain priority.
if (_pairing_from_button && c != 0) {
_pairing_screen_until = 0;
_pairing_from_button = false;
}
if (isPairingScreenActive()) {
// Pairing has visual priority over navigation and asynchronous screens.
static_cast<HomeScreen*>(home)->showFirstPage();
@@ -2553,6 +2566,10 @@ char UITask::checkDisplayOn(char c) {
const bool was_on = _display->isOn();
_display->wake(mesh::ui::DisplayWake::Button);
if (!was_on) {
if (_display->isOn() && mesh::ui::shouldDisplayBluetoothPairingPin(
isBluetoothEnabled(), hasBluetoothConnection(), the_mesh.getBLEPin())) {
showPairingPin(true);
}
c = 0;
}
_next_refresh = 0; // trigger refresh
+2 -1
View File
@@ -114,7 +114,8 @@ class UITask : public AbstractUITask {
void setCurrScreen(UIScreen* c);
bool isPairingScreenActive() const;
void renderPairingBanner();
void showPairingPin();
void showPairingPin(bool from_button = false);
bool _pairing_from_button = false;
void finishPairingScreen(bool timed_out);
public:
+62 -44
View File
@@ -1,6 +1,8 @@
#include <Arduino.h> // needed for PlatformIO
#include <Mesh.h>
#include <helpers/IdentityGeneration.h>
#include <helpers/ui/StartupScreen.h>
#include <helpers/ui/DisplayPowerSettings.h>
#if MESH_PACKET_LOGGING
#include <helpers/SerialPacketLog.h>
#endif
@@ -101,27 +103,66 @@ void setup() {
#if MESH_PACKET_LOGGING
mesh::serialLogBegin();
#endif
delay(1000);
board.begin();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
bool volatile_primary_fs = false;
mesh::storage::RamFallbackFileSystem* ram_primary_fs = nullptr;
const auto primary_fs_boot =
mesh::storage::beginInternalPrimaryFilesystemSafely(InternalFS);
if (mesh::storage::internalPrimaryFilesystemReady(primary_fs_boot)) {
fs = &InternalFS;
} else {
ram_primary_fs = mesh::storage::createRamFallbackFileSystem();
if (ram_primary_fs == nullptr) {
MESH_DEBUG_PRINTLN("InternalFS and RAM fallback initialization failed; rebooting");
board.reboot();
return;
}
fs = &ram_primary_fs->filesystem();
volatile_primary_fs = true;
}
IdentityStore store(*fs, "");
#elif defined(STM32_PLATFORM)
InternalFS.begin();
fs = &InternalFS;
IdentityStore store(InternalFS, "");
#elif defined(ESP32)
SPIFFS.begin(true);
fs = &SPIFFS;
IdentityStore store(SPIFFS, "/identity");
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
fs = &LittleFS;
IdentityStore store(LittleFS, "/identity");
store.begin();
#else
#error "need to define filesystem"
#endif
#ifdef DISPLAY_CLASS
mesh::ui::loadDisplayPowerSettings(fs, false);
mesh::ui::StartupScreen startup_screen;
display_ready = display.begin();
if (display_ready) {
startup_screen.begin(&display,
board.isExternalPowered() || board.isUsbHostConnected());
}
#endif
// Let serial settle after the display is already showing startup.
delay(1000);
#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
// give some extra time for serial to settle so
// boot debug messages can be seen on terminal
delay(5000);
#endif
#ifdef DISPLAY_CLASS
display_ready = display.begin();
if (display_ready) {
display.turnOff(); // Stay dark until the saved display policy is loaded.
}
#endif
int radioinit_attempts = 0;
while (!radio_init()) {
++radioinit_attempts;
@@ -158,41 +199,6 @@ void setup() {
fast_rng.begin(radio_driver.getRngSeed());
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
bool volatile_primary_fs = false;
mesh::storage::RamFallbackFileSystem* ram_primary_fs = nullptr;
const auto primary_fs_boot =
mesh::storage::beginInternalPrimaryFilesystemSafely(InternalFS);
if (mesh::storage::internalPrimaryFilesystemReady(primary_fs_boot)) {
fs = &InternalFS;
} else {
ram_primary_fs = mesh::storage::createRamFallbackFileSystem();
if (ram_primary_fs == nullptr) {
MESH_DEBUG_PRINTLN("InternalFS and RAM fallback initialization failed; rebooting");
board.reboot();
return;
}
fs = &ram_primary_fs->filesystem();
volatile_primary_fs = true;
}
IdentityStore store(*fs, "");
#elif defined(STM32_PLATFORM)
InternalFS.begin();
fs = &InternalFS;
IdentityStore store(InternalFS, "");
#elif defined(ESP32)
SPIFFS.begin(true);
fs = &SPIFFS;
IdentityStore store(SPIFFS, "/identity");
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
fs = &LittleFS;
IdentityStore store(LittleFS, "/identity");
store.begin();
#else
#error "need to define filesystem"
#endif
#if defined(NRF52_PLATFORM)
IdentityLoadResult identity_load = volatile_primary_fs
? store.loadResult("_main", the_mesh.self_id)
@@ -217,9 +223,21 @@ void setup() {
&& mesh::hasReservedIdentityPrefix(the_mesh.self_id));
bool identity_ready = identity_load != IdentityLoadResult::Unreadable;
if (needs_identity) {
#ifdef DISPLAY_CLASS
startup_screen.generatingKey();
mesh::ScopedIdentityGenerationProgress progress(
mesh::ui::StartupScreen::progress, &startup_screen);
#endif
MESH_DEBUG_PRINTLN("Generating new keypair");
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
#ifdef DISPLAY_CLASS
if (identity_ready) startup_screen.savingIdentity();
else startup_screen.starting();
#endif
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
#ifdef DISPLAY_CLASS
startup_screen.starting();
#endif
}
#if defined(ESP32_PLATFORM)
+40 -22
View File
@@ -1,6 +1,8 @@
#include <Arduino.h> // needed for PlatformIO
#include <Mesh.h>
#include <helpers/IdentityGeneration.h>
#include <helpers/ui/StartupScreen.h>
#include <helpers/ui/DisplayPowerSettings.h>
#if MESH_PACKET_LOGGING
#include <helpers/SerialPacketLog.h>
#endif
@@ -57,34 +59,12 @@ void setup() {
#if MESH_PACKET_LOGGING
mesh::serialLogBegin();
#endif
delay(1000);
board.begin();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif
#ifdef DISPLAY_CLASS
display_ready = display.begin();
if (display_ready) {
display.turnOff(); // Stay dark until the saved display policy is loaded.
}
#endif
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());
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
bool volatile_primary_fs = false;
@@ -116,6 +96,32 @@ void setup() {
#else
#error "need to define filesystem"
#endif
#ifdef DISPLAY_CLASS
mesh::ui::loadDisplayPowerSettings(fs, false);
mesh::ui::StartupScreen startup_screen;
display_ready = display.begin();
if (display_ready) {
startup_screen.begin(&display,
board.isExternalPowered() || board.isUsbHostConnected());
}
#endif
// Let serial settle after the display is already showing startup.
delay(1000);
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());
#if defined(NRF52_PLATFORM)
IdentityLoadResult identity_load = volatile_primary_fs
? store.loadResult("_main", the_mesh.self_id)
@@ -140,8 +146,20 @@ void setup() {
&& mesh::hasReservedIdentityPrefix(the_mesh.self_id));
bool identity_ready = identity_load != IdentityLoadResult::Unreadable;
if (needs_identity) {
#ifdef DISPLAY_CLASS
startup_screen.generatingKey();
mesh::ScopedIdentityGenerationProgress progress(
mesh::ui::StartupScreen::progress, &startup_screen);
#endif
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
#ifdef DISPLAY_CLASS
if (identity_ready) startup_screen.savingIdentity();
else startup_screen.starting();
#endif
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
#ifdef DISPLAY_CLASS
startup_screen.starting();
#endif
}
#if defined(ESP32_PLATFORM)
+50 -29
View File
@@ -1,5 +1,7 @@
#include "SensorMesh.h"
#include <helpers/IdentityGeneration.h>
#include <helpers/ui/StartupScreen.h>
#include <helpers/ui/DisplayPowerSettings.h>
#if defined(NRF52_PLATFORM)
#include <helpers/nrf52/InternalPrimaryFsBoot.h>
#include <helpers/nrf52/RamFallbackFileSystem.h>
@@ -13,6 +15,7 @@
#ifdef DISPLAY_CLASS
#include "UITask.h"
static UITask ui_task(display);
static bool display_ready = false;
#endif
class MyMesh : public SensorMesh {
@@ -73,39 +76,12 @@ void setup() {
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
mesh::beginUsbLoggingPort();
#endif
delay(1000);
board.begin();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif
#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
// Allow the USB console to settle before printing boot diagnostics.
delay(5000);
#endif
#ifdef DISPLAY_CLASS
if (display.begin()) {
display.turnOff();
// Saved display policy is applied by UITask::begin().
}
#endif
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());
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
bool volatile_primary_fs = false;
@@ -141,6 +117,37 @@ void setup() {
#else
#error "need to define filesystem"
#endif
#ifdef DISPLAY_CLASS
mesh::ui::loadDisplayPowerSettings(fs, false);
mesh::ui::StartupScreen startup_screen;
display_ready = display.begin();
if (display_ready) {
startup_screen.begin(&display,
board.isExternalPowered() || board.isUsbHostConnected());
}
#endif
// Let serial settle after the display is already showing startup.
delay(1000);
#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
// Allow the USB console to settle before printing boot diagnostics.
delay(5000);
#endif
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());
#if defined(NRF52_PLATFORM)
IdentityLoadResult identity_load = volatile_primary_fs
? store.loadResult("_main", the_mesh.self_id)
@@ -165,9 +172,21 @@ void setup() {
&& mesh::hasReservedIdentityPrefix(the_mesh.self_id));
bool identity_ready = identity_load != IdentityLoadResult::Unreadable;
if (needs_identity) {
#ifdef DISPLAY_CLASS
startup_screen.generatingKey();
mesh::ScopedIdentityGenerationProgress progress(
mesh::ui::StartupScreen::progress, &startup_screen);
#endif
MESH_DEBUG_PRINTLN("Generating new keypair");
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
#ifdef DISPLAY_CLASS
if (identity_ready) startup_screen.savingIdentity();
else startup_screen.starting();
#endif
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
#ifdef DISPLAY_CLASS
startup_screen.starting();
#endif
}
#if defined(ESP32_PLATFORM)
@@ -201,7 +220,9 @@ void setup() {
#endif
#ifdef DISPLAY_CLASS
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
if (display_ready) {
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
}
#endif
// send out initial zero hop Advertisement to the mesh
@@ -264,7 +285,7 @@ void loop() {
the_mesh.loop();
sensors.loop();
#ifdef DISPLAY_CLASS
ui_task.loop();
if (display_ready) ui_task.loop();
#endif
rtc_clock.tick();
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE