-
Notifications
You must be signed in to change notification settings - Fork 9
/
lora-tx.ino
94 lines (74 loc) · 2.34 KB
/
lora-tx.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
92
93
94
/*********
Modified from the examples of the Arduino LoRa library
More resources: https://randomnerdtutorials.com
*********/
#include <SPI.h>
#include <LoRa.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <stdlib.h>
//define the pins used by the transceiver module
#define ss 6
#define rst 5
#define dio0 2
SoftwareSerial gpsSerial(8,9);//rx,tx
TinyGPSPlus tinyGPS; // create gps object
#define gpsPort gpsSerial // Alternatively, use Serial1 on the Leonardo
#define SerialMonitor Serial
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
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!");
gpsPort.begin(9600); // connect gps sensor
Serial.println("GPS Initialized");
Serial.println("Waiting for GPS.. .");
LoRa.beginPacket();
LoRa.print("Waiting for GPS...");
LoRa.endPacket();
Serial.println("___________________________");
}
void loop() {
printGPSInfo();
smartDelay(10000);
}
void printGPSInfo() {
LoRa.beginPacket();
LoRa.print("lat: ");
LoRa.print(tinyGPS.location.lat(),6);
LoRa.print(",lng: ");
LoRa.println(tinyGPS.location.lng(),6);
LoRa.endPacket();
Serial.println(tinyGPS.location.lat(),6);
Serial.println(tinyGPS.location.lng(),6);
Serial.println(tinyGPS.altitude.meters());
Serial.println("___________________________");
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
// If data has come in from the GPS module
while (gpsPort.available())
tinyGPS.encode(gpsPort.read()); // Send it to the encode function
// tinyGPS.encode(char) continues to "load" the tinGPS object with new
// data coming in from the GPS module. As full NMEA strings begin to come in
// the tinyGPS library will be able to start parsing them for pertinent info
} while (millis() - start < ms);
}