* fix for double radio.begin(). RNG seed from pressing ENTER

This commit is contained in:
Scott Powell
2025-03-25 17:40:36 +11:00
parent 1220c69aa9
commit d32e641225
2 changed files with 11 additions and 7 deletions

View File

@@ -267,9 +267,9 @@ protected:
public: public:
#ifdef WRAPPER_CLASS #ifdef WRAPPER_CLASS
MyMesh(RadioLibWrapper& radio, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables) MyMesh(RadioLibWrapper& radio, StdRNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
#else #else
MyMesh(mesh::Radio& radio, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables) MyMesh(mesh::Radio& radio, StdRNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
#endif #endif
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables) : BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables)
{ {
@@ -298,6 +298,14 @@ public:
IdentityStore store(fs, "/identity"); IdentityStore store(fs, "/identity");
#endif #endif
if (!store.load("_main", self_id, _prefs.node_name, sizeof(_prefs.node_name))) { // legacy: node_name was from identity file if (!store.load("_main", self_id, _prefs.node_name, sizeof(_prefs.node_name))) { // legacy: node_name was from identity file
// Need way to get some entropy to seed RNG
Serial.println("Press ENTER to generate key:");
char c = 0;
while (c != '\n') { // wait for ENTER to be pressed
if (Serial.available()) c = Serial.read();
}
((StdRNG *)getRNG())->begin(millis());
self_id = mesh::LocalIdentity(getRNG()); // create new random identity self_id = mesh::LocalIdentity(getRNG()); // create new random identity
store.save("_main", self_id); store.save("_main", self_id);
} }
@@ -543,10 +551,6 @@ void setup() {
#ifdef WRAPPER_CLASS #ifdef WRAPPER_CLASS
fast_rng.begin(radio.random(0x7FFFFFFF)); fast_rng.begin(radio.random(0x7FFFFFFF));
#else #else
char c = 0;
// while (c != '\n') { // wait for ENTER to be pressed
// if (Serial.available()) c = Serial.read();
// }
fast_rng.begin(millis()); fast_rng.begin(millis());
#endif #endif

View File

@@ -6,6 +6,6 @@ ESP32Board board;
ESPNOWRadio radio; ESPNOWRadio radio;
bool radio_init() { bool radio_init() {
radio.begin(); // NOTE: radio.begin() is called by Dispatcher::begin(), so not needed here
return true; // success return true; // success
} }