-
Notifications
You must be signed in to change notification settings - Fork 1
/
UploadsOnArduino.ino
118 lines (95 loc) · 2.62 KB
/
UploadsOnArduino.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <LoRa.h>
// Choose two Arduino pins to use for software serial
int RXPin = 2;
int TXPin = 3;
int GPSBaud = 9600;
// Create a TinyGPS++ object
TinyGPSPlus gps;
// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);
#define ss 18
#define rst 14
#define dio0 26
void setup()
{
// Start the Arduino hardware serial port at 9600 baud
Serial.begin(9600);
while (!Serial); //wait until serial is connected
Serial.println("LoRa Sender");
// 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!");
// Start the software serial port at the GPS's default baud
gpsSerial.begin(GPSBaud);
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
// while (gpsSerial.available() > 0)
// if (gps.encode(gpsSerial.read()))
// displayInfo();
// If 5000 milliseconds pass and there are no characters coming in
// over the software serial port, show a "No GPS detected" error
// if (millis() > 5000 && gps.charsProcessed() < 10)
// {
// Serial.println("No GPS detected");
// while (true);
// }
String gpstime;
if (gps.location.isValid())
{
gpstime += "{Latitude: " + (gps.location.lat(), 6);
gpstime += ", Longitude: " + (gps.location.lng(), 6);
}
else
{
gpstime += "{Latitude: Not Available ";
gpstime += ", Longitude: Not Available ";
}
String zero = "0";
String hour, minute, second;
if (gps.time.hour() < 10) {
hour = zero + String(gps.time.hour());
}
else {
hour = String(gps.time.hour());
}
if (gps.time.minute() < 10) {
minute = zero + String(gps.time.minute());
}
else {
minute = String(gps.time.minute());
}
if (gps.time.second() < 10) {
second = zero + String(gps.time.second());
}
else {
second = String(gps.time.second());
}
String timeStr;
if (gps.date.isValid() && gps.time.isValid()) {
timeStr = String(gps.date.year()) + "-" + String(gps.date.month()) + "-" + String(gps.date.day()) + " " + hour + ":" + minute + ":" + second;
gpstime += ", Time: " + timeStr + "}";
}
else {
Serial.println("Not Available");
}
delay(1000);
//Serial.println(gpstime);
//Send LoRa packet to receiver
// Serial.println(gpstime);
LoRa.beginPacket();
LoRa.print(String(gpstime));
LoRa.endPacket();
Serial.println("hi");
delay(5000);
}
//void displayInfo() {
//
//}