-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPS.ino
71 lines (62 loc) · 1.76 KB
/
GPS.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
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
static const int RXPin = 4, TXPin = 5; // connect tx to d2
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
WidgetMap myMap(V4); // Pin V4 for map
SoftwareSerial ss(RXPin, TXPin);
BlynkTimer timer;
float spd;
String bearing;
char auth[] = "cc465ead5603481fa1ce9bb89503f0c5";
char ssid[] = "MSK";
char pass[] = "12345678";
unsigned int move_index = 1; // fixed location for now
void setup()
{
Serial.begin(115200);
Serial.println();
ss.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS);
}
void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V4, "GPS ERROR");
}
}
void loop()
{
while (ss.available() > 0)
{
if (gps.encode(ss.read()))
displayInfo();
}
Blynk.run();
timer.run();
}
void displayInfo()
{
if (gps.location.isValid() )
{
float latitude = (gps.location.lat());
float longitude = (gps.location.lng());
Serial.print("LAT: ");
Serial.println(latitude, 6);
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
spd = gps.speed.kmph(); //get speed
Blynk.virtualWrite(V3, spd);
bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction
Blynk.virtualWrite(V5, bearing);
}
Serial.println();
}