Skip to content

Commit fd94031

Browse files
committed
Add initial sender and receiver examples
1 parent 038378c commit fd94031

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <SPI.h>
2+
#include <LoRa.h>
3+
4+
void setup() {
5+
Serial.begin(9600);
6+
while (!Serial);
7+
8+
Serial.println("LoRa Receiver");
9+
10+
if (!LoRa.begin(915E6)) {
11+
Serial.println("Starting LoRa failed!");
12+
while (1);
13+
}
14+
}
15+
16+
void loop() {
17+
// try to parse packet
18+
int packetSize = LoRa.parsePacket();
19+
if (packetSize) {
20+
// received a packet
21+
Serial.print("Received packet '");
22+
23+
// read packet
24+
while (LoRa.available()) {
25+
Serial.print((char)LoRa.read());
26+
}
27+
28+
// print RSSI of packet
29+
Serial.print("' with RSSI ");
30+
Serial.println(LoRa.packetRSSI());
31+
}
32+
}

examples/LoRaSender/LoRaSender.ino

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <SPI.h>
2+
#include <LoRa.h>
3+
4+
int counter = 0;
5+
6+
void setup() {
7+
Serial.begin(9600);
8+
while (!Serial);
9+
10+
Serial.println("LoRa Sender");
11+
12+
if (!LoRa.begin(915E6)) {
13+
Serial.println("Starting LoRa failed!");
14+
while (1);
15+
}
16+
}
17+
18+
void loop() {
19+
Serial.print("Sending packet: ");
20+
Serial.println(counter);
21+
22+
// send packet
23+
LoRa.beginPacket();
24+
LoRa.print("hello ");
25+
LoRa.print(counter);
26+
LoRa.endPacket();
27+
28+
counter++;
29+
30+
delay(5000);
31+
}

0 commit comments

Comments
 (0)