-
-
Notifications
You must be signed in to change notification settings - Fork 648
/
Copy pathLoRandom.ino
66 lines (59 loc) · 1.79 KB
/
LoRandom.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/********************************************************************
LoRandomSeed
Example demonstrating how to generate random numbers using LoRa.
created 7 Sep 2020
by Kongduino
adapted by Andres Sabas
***********************************************************************/
#include <SPI.h>
#include <LoRa.h>
void setup() {
Serial.begin(9600);
while(!Serial);
Serial.print(F("\n\n\n[SX1276] Initializing ... "));
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.print("Setting up LoRa ");
LoRa.setTxPower(20, PA_OUTPUT_PA_BOOST_PIN);
LoRa.setPreambleLength(8);
LoRa.beginRandom();
Serial.println("End of setup\n\n");
}
void loop() {
byte randomBytes[256];
// We'll build a stock of random bytes for use in code
int randomIndex = 0;
unsigned int i;
for (i = 0; i < 256; i++) {
int x = LoRa.random();
randomBytes[i] = x;
}
randomIndex = 0;
hexDump(randomBytes, 256);
delay(2000);
}
void hexDump(unsigned char *buf, unsigned int len) {
String s = "|", t = "| |";
Serial.println(F(" |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f |"));
Serial.println(F(" +------------------------------------------------+ +----------------+"));
for ( unsigned int i = 0; i < len; i += 16) {
for (int j = 0; j < 16; j++) {
if (i + j >= len) {
s = s + " "; t = t + " ";
} else {
char c = buf[i + j];
if (c < 16) s = s + "0";
s = s + String(c, HEX) + " ";
if (c < 32 || c > 127) t = t + ".";
else t = t + (String(c));
}
}
int index = i / 16;
Serial.print(index, HEX); Serial.write('.');
Serial.println(s + t + "|");
s = "|"; t = "| |";
}
Serial.println(F(" +------------------------------------------------+ +----------------+"));
}