From 29e62b9ce23a5c1de3d88d73e2c2730409f9c761 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Tue, 4 Feb 2025 01:35:04 +1100 Subject: [PATCH] * IdentityStore::save() was failing on RAK. * Repeater: CLI 'erase' command added. --- examples/companion_radio/main.cpp | 4 ++++ examples/simple_repeater/main.cpp | 12 +++++++++++- examples/simple_room_server/main.cpp | 2 +- examples/simple_secure_chat/main.cpp | 4 ++++ src/helpers/IdentityStore.cpp | 4 +++- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index b66190aa..1ebec27e 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -388,7 +388,11 @@ public: BaseChatMesh::begin(); + #if defined(NRF52_PLATFORM) + IdentityStore store(fs, ""); + #else IdentityStore store(fs, "/identity"); + #endif if (!store.load("_main", self_id)) { self_id = mesh::LocalIdentity(&trng); // create new random identity store.save("_main", self_id); diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 73d63a4e..af86837f 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -498,6 +498,15 @@ public: } else { sprintf(reply, "unknown config: %s", config); } + } else if (sender_timestamp == 0 && strcmp(command, "erase") == 0) { + #if defined(NRF52_PLATFORM) + bool s = InternalFS.format(); + #elif defined(ESP32) + bool s = SPIFFS.format(); + #else + #error "need to implement file system erase" + #endif + sprintf(reply, "File system erase: %s", s ? "OK" : "Err"); } else if (memcmp(command, "ver", 3) == 0) { strcpy(reply, FIRMWARE_VER_TEXT); } else { @@ -576,7 +585,7 @@ void setup() { #if defined(NRF52_PLATFORM) InternalFS.begin(); fs = &InternalFS; - IdentityStore store(InternalFS, "/identity"); + IdentityStore store(InternalFS, ""); #elif defined(ESP32) SPIFFS.begin(true); fs = &SPIFFS; @@ -585,6 +594,7 @@ void setup() { #error "need to define filesystem" #endif if (!store.load("_main", the_mesh.self_id)) { + MESH_DEBUG_PRINTLN("Generating new keypair"); RadioNoiseListener rng(radio); the_mesh.self_id = mesh::LocalIdentity(&rng); // create new random identity store.save("_main", the_mesh.self_id); diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 38dfbc36..b9880892 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -727,7 +727,7 @@ void setup() { #if defined(NRF52_PLATFORM) InternalFS.begin(); fs = &InternalFS; - IdentityStore store(InternalFS, "/identity"); + IdentityStore store(InternalFS, ""); #elif defined(ESP32) SPIFFS.begin(true); fs = &SPIFFS; diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index c9737a01..108db592 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -301,7 +301,11 @@ public: BaseChatMesh::begin(); + #if defined(NRF52_PLATFORM) + IdentityStore store(fs, ""); + #else IdentityStore store(fs, "/identity"); + #endif if (!store.load("_main", self_id, _prefs.node_name, sizeof(_prefs.node_name))) { // legacy: node_name was from identity file self_id = mesh::LocalIdentity(getRNG()); // create new random identity store.save("_main", self_id); diff --git a/src/helpers/IdentityStore.cpp b/src/helpers/IdentityStore.cpp index 84cf6ace..3b44eb4a 100644 --- a/src/helpers/IdentityStore.cpp +++ b/src/helpers/IdentityStore.cpp @@ -45,10 +45,12 @@ bool IdentityStore::save(const char *name, const mesh::LocalIdentity& id) { File file = _fs->open(filename, "w", true); #endif if (file) { - id.writeTo(file); + bool success = id.writeTo(file); file.close(); + MESH_DEBUG_PRINTLN("IdentityStore::save() write - %s", success ? "OK" : "Err"); return true; } + MESH_DEBUG_PRINTLN("IdentityStore::save() failed"); return false; }