Skip to content

Commit

Permalink
Fix: Beelan DevNonce issue #179
Browse files Browse the repository at this point in the history
  • Loading branch information
REGIOIGER committed Feb 14, 2024
1 parent a5fc055 commit 9d91e93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/arduino-rfm/LoRaMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,15 @@ void LORA_Receive_Data(sBuffer *Data_Rx, sLoRa_Session *Session_Data, sLoRa_OTAA
*/
static void Generate_DevNonce(unsigned char *DevNonce)
{
#ifdef ESP32
// Use the built-in random number generator of ESP32 to obtain a random value
esp_fill_random(DevNonce, 2); // Fill the first 2 bytes of DevNonce with random values
#else
unsigned int RandNumber;

RandNumber = random(0xFFFF);

DevNonce[0] = RandNumber & 0x00FF;
DevNonce[1] = (RandNumber >> 8) & 0x00FF;
#endif
}
/*
*****************************************************************************************
Expand Down
6 changes: 5 additions & 1 deletion src/arduino-rfm/lorawan-arduino-rfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ bool LoRaWANClass::init(void)
// Lora Setting Class
dev_class = CLASS_A;
// Random seed
randomSeed(analogRead(0));
#ifdef ESP32
randomSeed(esp_random());
#else
randomSeed(analogRead(0));
#endif

// Status
RFM_Command_Status = NO_RFM_COMMAND;
Expand Down

0 comments on commit 9d91e93

Please sign in to comment.