-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorkingLoraCodeWithGPS.ino
191 lines (161 loc) · 4.39 KB
/
WorkingLoraCodeWithGPS.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
/*
This sample sketch demonstrates the normal use of a TinyGPSPlus (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 32, TXPin = 33;
static const uint32_t GPSBaud = 9600;
// The TinyGPSPlus object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
#include "heltec.h"
#define BAND 915E6
int counter = 0;
int startTime = millis();
String gpstime;
String hour, minute, second;
String timeStr;
String zero = "0";
void setup()
{
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.LoRa Disable*/, false /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
Serial.begin(115200); //for gps
while(!Serial);
ss.begin(GPSBaud);
while(!ss);
Serial.println(F("DeviceExample.ino"));
Serial.println(F("A simple demonstration of TinyGPSPlus with an attached GPS module"));
Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
// if(millis()-startTime>1000){
// startTime = millis();
// sendLora();
// }
if (millis()>15000 && gps.charsProcessed()<10){
Serial.println("No GPS Detected");
while(true);
}
if (gps.location.isValid())
{
gpstime += String(gps.location.lat(), 6);
gpstime += "," + String(gps.location.lng(), 6);
}
else
{
gpstime += "N/A";
gpstime += ",N/A";
}
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());
}
if (gps.date.isValid() && gps.time.isValid()) {
timeStr = String(gps.date.year()) + "-" + String(gps.date.month()) + "-" + String(gps.date.day()) + " " + hour + ":" + minute + ":" + second;
gpstime += "," + timeStr + ",";
}
else {
Serial.println("NA");
}
if(Serial.available()){
LoRa.beginPacket();
LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
LoRa.print(gpstime + Serial.readStringUntil('\n') + ",1,0");
Serial.print(gpstime);
LoRa.endPacket();
}
//boat 2 = odd seconds
// if(gps.time.second()%2 == 1){
// if(Serial.available()){
// LoRa.beginPacket();
// LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
// LoRa.print(gpstime + Serial.readStringUntil('\n') + ",2");
// Serial.print(gpstime);
// LoRa.endPacket();
// }
// }
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void sendLora(){
// Serial.print();
// Serial.println("-------------------------------------------");
// LoRa.beginPacket();
// LoRa.setTxPower(14,RF_PACONFIG_PASELECT_PABOOST);
// LoRa.print();
// LoRa.endPacket();
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(String(gps.location.lat(), 6));
Serial.print(F(","));
Serial.print(String(gps.location.lng(), 6));
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}