-
Notifications
You must be signed in to change notification settings - Fork 0
/
Baggage_Tracking.ino
122 lines (89 loc) · 3.25 KB
/
Baggage_Tracking.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
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
const char* server = "garbage-monitoring-syste-f1f56.appspot.com";
static const int RXPin = 5, TXPin = 4; // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS)
static const uint32_t GPSBaud = 9600; //if Baud rate 9600 didn't work in your case then use 4800
TinyGPSPlus gps; // The TinyGPS++ object
WiFiClient client;
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
float spd; //Variable to store the speed
float sats; //Variable to store no. of satellites response
String bearing; //Variable to store orientation or direction of GPS
char auth[] = "G-QNFYPNepq8AcNDfUf6QtgUCstqSm3"; //Your Project authentication key
char ssid[] = "IOT_J"; // Name of your network (HotSpot or Router name)
char pass[] = "10101010"; // Corresponding Password
const char *ssid1 = "Param";
const char *pass1 = "87654321";
//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now
void setup()
{
Serial.begin(9600);
Serial.println();
ss.begin(GPSBaud);
Serial.println("Connecting to ");
Serial.println(ssid1);
WiFi.begin(ssid1, pass1);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(("No GPS detected: check wiring."));
}
}
void loop()
{
delay(5000);
checkGPS();
while (ss.available() > 0)
{
//sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(ss.read()))
displayInfo();
}
}
void displayInfo()
{
if (gps.location.isValid() )
{
float latitude = (gps.location.lat()); //Storing the Lat. and Lon.
float longitude = (gps.location.lng());
Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
if(WiFi.status()==WL_CONNECTED){
if (client.connect(server,80))
{
String postStr = "";
postStr +="lat=";
postStr += String(latitude);
postStr +="&long=";
postStr += String(longitude);
postStr += "\r\n\r\n";
client.print("POST /location HTTP/1.1\n");
client.print("Host: garbage-monitoring-syste-f1f56.appspot.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
else{
Serial.println("Connection Failed");
}
client.stop();
}
delay(20000);
}
Serial.println();
}