-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoRaDumper.ino
84 lines (68 loc) · 1.59 KB
/
LoRaDumper.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <SPI.h>
#include <LoRa.h>
#define PIN_LED 13
#define LED_MILLIS 500
#define PIN_LORA_CS 8
#define PIN_LORA_RST 4
#define PIN_LORA_IRQ 7
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver v3");
pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_LED, HIGH);
LoRa.setPins(PIN_LORA_CS, PIN_LORA_RST, PIN_LORA_IRQ);
if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1) {
digitalWrite(PIN_LED, HIGH);
delay(100);
digitalWrite(PIN_LED, LOW);
delay(100);
}
}
Serial.println("LORA register dump:");
LoRa.dumpRegisters(Serial);
Serial.println("Setup done");
}
int nextblink = 0;
bool blinkstate = true;
void blink() {
if (blinkstate) {
digitalWrite(PIN_LED, HIGH);
blinkstate = false;
} else {
digitalWrite(PIN_LED, LOW);
blinkstate = true;
}
}
void loop() {
int now = millis();
if (now > nextblink) {
blink();
nextblink = now + LED_MILLIS;
}
int packetSize = LoRa.parsePacket();
if (packetSize) {
Serial.print("RCV");
Serial.print(" millis:");
Serial.print(millis());
Serial.print(" rssi:");
Serial.print(LoRa.packetRssi());
Serial.print(" snr:");
Serial.print(LoRa.packetSnr());
Serial.print(" fe:");
Serial.print(LoRa.packetFrequencyError());
Serial.print(" size:");
Serial.print(packetSize);
Serial.print(" data:");
while (LoRa.available()) {
byte val = LoRa.read();
Serial.print(" ");
if (val < 16) { Serial.print("0"); }
Serial.print(String(val,HEX));
blink();
}
Serial.println("");
}
}