forked from cubapp/LilyGO-TTGO-LoRa32-SenderReceiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoRa.ino
92 lines (79 loc) · 2.17 KB
/
LoRa.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
85
86
87
88
89
90
91
#include <SPI.h>
#include <LoRa.h>
#include "board_def.h"
OLED_CLASS_OBJ display(OLED_ADDRESS, OLED_SDA, OLED_SCL);
//display size for better string placement
int width;
int height;
void setup()
{
Serial.begin(115200);
while (!Serial);
if (OLED_RST > 0) {
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, HIGH);
delay(100);
digitalWrite(OLED_RST, LOW);
delay(100);
digitalWrite(OLED_RST, HIGH);
}
display.init();
width = display.getWidth() / 2;
height = display.getHeight() / 2;
display.flipScreenVertically();
display.clear();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(width - 50, height, LORA_SENDER ? "LoRa++ Sender" : "LoRa++ Receiver");
display.display();
delay(2000);
SPI.begin(CONFIG_CLK, CONFIG_MISO, CONFIG_MOSI, CONFIG_NSS);
LoRa.setPins(CONFIG_NSS, CONFIG_RST, CONFIG_DIO0);
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
if (!LORA_SENDER) {
display.clear();
display.drawString(width - 50, height, "LoraRecv++ Ready");
display.display();
}
}
int count = 0;
void loop()
{
#if LORA_SENDER
// LORA SENDER PART -
// sending random number and counter to the LoRa Receiver
int32_t rssi;
count++;
rssi = random(1, 100);
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(width - 50, height, String(count) + ". RandNum: " + String(rssi));
display.display();
LoRa.beginPacket();
LoRa.print(count);
LoRa.print(". Rnd= ");
LoRa.print(rssi);
LoRa.endPacket();
delay(500);
#else
// LORA RECEIVER PART -
// displaying random number and counter from the LoRa Sender
if (LoRa.parsePacket()) {
String recv = "";
while (LoRa.available()) {
recv += (char)LoRa.read();
}
count++;
display.clear();
display.drawString(width - 50, height, recv);
String info = "[" + String(count) + "]" + "RSSI " + String(LoRa.packetRssi());
String snr = "[" + String(count) + "]" + "SNR: " + String(LoRa.packetSnr());
display.drawString(width - 50, height - 16, info);
display.drawString(width - 50, height - 24, snr);
display.display();
}
#endif
}