-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoRaRS485.ino
67 lines (55 loc) · 1.43 KB
/
LoRaRS485.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
#include <SPI.h>
#include <LoRa.h>
//define the pins used by the transceiver module (ESP32)
#define ss 5
#define rst 15
#define dio0 4
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
Serial2.begin(19200);
while (!Serial)
;
Serial.println("LoRa Sender");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(915E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
while (LoRa.available()) {
String LoRaData = LoRa.readString();
Serial.print("LoRa: ");
Serial.println(LoRaData);
}
}
if (Serial2.available() > 0) {
Serial.print("RS485: ");
String bacaSerial2 = Serial2.readString();
Serial.println(bacaSerial2);
LoRa.beginPacket();
LoRa.print(bacaSerial2);
LoRa.endPacket();
}
if (Serial.available() > 0) {
String bacaSerial = Serial.readString();
LoRa.beginPacket();
Serial2.print(bacaSerial);
LoRa.print(bacaSerial);
Serial.println(bacaSerial);
LoRa.endPacket();
}
}