-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timezone.cpp
140 lines (117 loc) · 2.55 KB
/
Timezone.cpp
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
#include "ESP8266WiFi.h"
#include <JsonStreamingParser.h>
#include "GoogleGeolocation.h"
#include "UserConfig.h"
//extern NTPClient NTP;
bool Timezone::acquire(double latitude, double longitude, String timestamp)
{
/**********************************************************
Step 2 - Timezone
Get Timezone from latitude and longitude
**********************************************************/
//Connect to the client and make the api call
if (httpsConnect(FPSTR(maps_Host), FPSTR(maps_fingerprint)))
{
// Concatenate url and key
String url = FPSTR(timeZone_url);
url += String(latitude, 6);
url += F(",") ;
url += String(longitude, 6) ;
url += F("×tamp=") ;
url += timestamp;
url += F("&key=") ;
url += FPSTR(googleApiKey);
if (httpsGet(FPSTR(maps_Host), url) && skipResponseHeaders())
{
JsonStreamingParser parser;
parser.setListener(this);
char c;
int size = 0;
while ((size = client.available()) > 0)
{
c = client.read();
parser.parse(c);
}
}
else
{
// Get failed
// Serial.println("get failed");
return false;
}
}
else
{
// Could not connect
// Serial.println("Could not connect");
return false;
}
disconnect();
valid = true;
return true;
}
bool Timezone::isValid()
{
return valid;
}
void Timezone::whitespace(char c) {
// Serial.println("whitespace");
}
void Timezone::startDocument() {
// Serial.println("start document");
}
void Timezone::key(String key) {
// Serial.println("key: " + key);
currentKey = String(key);
}
void Timezone::value(String value)
{
// Serial.println("value: " + value);
if (currentKey == F("dstOffset"))
{
dstOffset = value.toInt();
}
else if (currentKey == F("rawOffset"))
{
rawOffset = value.toInt();
}
else if (currentKey == F("timeZoneId"))
{
timeZoneId = value;
}
else if (currentKey == F("timeZoneName"))
{
timeZoneName = value;
}
}
void Timezone::endArray() {
// Serial.println("end array. ");
}
void Timezone::endObject() {
// Serial.println("end object. ");
}
void Timezone::endDocument() {
// Serial.println("end document. ");
}
void Timezone::startArray() {
// Serial.println("start array. ");
}
void Timezone::startObject() {
// Serial.println("start object. ");
}
String Timezone::getTimeZoneId()
{
return timeZoneId;
}
String Timezone::getTimeZoneName()
{
return timeZoneName;
}
int Timezone::getDstOffset()
{
return dstOffset;
}
int Timezone::getRawOffset()
{
return rawOffset;
}