]> git.tnoah.ca Git - lora-radio.git/commitdiff
Use hardware RNG for CSMA r-value seed on ESP32
authorMark Qvist <mark@unsigned.io>
Sat, 30 Mar 2024 14:11:24 +0000 (15:11 +0100)
committerMark Qvist <mark@unsigned.io>
Sat, 30 Mar 2024 14:11:24 +0000 (15:11 +0100)
RNode_Firmware.ino

index 54ddb125e8c117daf2c3441062b3cd4abdb755af..7b460945e6ddc8bce9e0406f42f840a77b6f2d6d 100644 (file)
@@ -60,8 +60,17 @@ void setup() {
     }
   #endif
 
-  // Seed the PRNG
-  randomSeed(analogRead(0));
+  // Seed the PRNG for CSMA R-value selection
+  # if MCU_VARIANT == MCU_ESP32
+    // On ESP32, get the seed value from the
+    // hardware RNG
+    int seed_val = (int)esp_random();
+  #else
+    // Otherwise, get a pseudo-random seed
+    // value from an unconnected analog pin
+    int seed_val = analogRead(0);
+  #endif
+  randomSeed(seed_val);
 
   // Initialise serial communication
   memset(serialBuffer, 0, sizeof(serialBuffer));