Implemented timezone API HTTP proxy
This commit is contained in:
parent
d9d9b45956
commit
bc90234f73
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
echo file_get_contents('https://maps.googleapis.com/maps/api/timezone/json?' . $_SERVER['QUERY_STRING']);
|
||||||
|
?>
|
|
@ -1,5 +1,7 @@
|
||||||
@Echo Off
|
@Echo Off
|
||||||
echo -DASYNC_TCP_SSL_ENABLED=1
|
|
||||||
|
REM Enable this line if you're not using MapsAPIViaProxyScript
|
||||||
|
REM echo -DASYNC_TCP_SSL_ENABLED=1
|
||||||
|
|
||||||
if exist src\secret.h (
|
if exist src\secret.h (
|
||||||
echo -DSecretsPresent=1
|
echo -DSecretsPresent=1
|
||||||
|
|
4576
src/assets/js.h
4576
src/assets/js.h
File diff suppressed because it is too large
Load Diff
|
@ -4,10 +4,10 @@
|
||||||
const uint8_t VersionMajor = 2;
|
const uint8_t VersionMajor = 2;
|
||||||
const uint8_t VersionMinor = 0;
|
const uint8_t VersionMinor = 0;
|
||||||
const uint8_t VersionPatch = 0;
|
const uint8_t VersionPatch = 0;
|
||||||
const uint8_t VersionMetadata = 23;
|
const uint8_t VersionMetadata = 25;
|
||||||
const char VersionBranch[] = "release/2.0";
|
const char VersionBranch[] = "release/2.0";
|
||||||
const char VersionSemVer[] = "2.0.0-beta.1";
|
const char VersionSemVer[] = "2.0.0-beta.1";
|
||||||
const char VersionFullSemVer[] = "2.0.0-beta.1+23";
|
const char VersionFullSemVer[] = "2.0.0-beta.1+25";
|
||||||
const char VersionCommitDate[] = "2018-01-18";
|
const char VersionCommitDate[] = "2018-01-19";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
23
src/config.h
23
src/config.h
|
@ -34,4 +34,27 @@ static const uint16_t APButtonHoldTime = 5000;
|
||||||
// the configurable NTP interval is used
|
// the configurable NTP interval is used
|
||||||
static const uint32_t TimezoneRetryInterval = 60000;
|
static const uint32_t TimezoneRetryInterval = 60000;
|
||||||
|
|
||||||
|
|
||||||
|
// SSL takes quite a bit of memory (and I haven't been optimizing much),
|
||||||
|
// which seems to cause memory-related exceptions when getting the timezone
|
||||||
|
// information from Google's HTTPS API. Google requires HTTPS. The workaround
|
||||||
|
// is hosting a small proxy script on HTTP, which is included in the "hosted" folder
|
||||||
|
// of this project. Note that this completely defeats any security, and may
|
||||||
|
// cause your Google API key and location data to leak. My advice is simply to not
|
||||||
|
// specify your location too precisely :-)
|
||||||
|
//
|
||||||
|
// If you want to host your own version of the script because you don't trust
|
||||||
|
// that mine will not log anything, or want to disable the proxy script
|
||||||
|
// completely, change these definitions below. Also update platformio-buildflags.bat
|
||||||
|
// to enable SSL support in ESPAsyncTCP.
|
||||||
|
//
|
||||||
|
// If you can fix my sloppy code and get a direct SSL connection working,
|
||||||
|
// I'd be interested in the changes as well!
|
||||||
|
#define MapsAPIViaProxyScript
|
||||||
|
|
||||||
|
#ifdef MapsAPIViaProxyScript
|
||||||
|
static const char* TimezoneProxyScriptHost = "api.x2software.net";
|
||||||
|
static const char* TimezoneProxyScriptPath = "/timezone.php";
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -125,17 +125,21 @@ void updateTimezone()
|
||||||
|
|
||||||
|
|
||||||
uint32_t timestamp = ntpClient->getEpochTime();
|
uint32_t timestamp = ntpClient->getEpochTime();
|
||||||
|
#ifdef MapsAPIViaProxyScript
|
||||||
|
String request = String("GET ") + TimezoneProxyScriptPath + "?location=" +
|
||||||
|
#else
|
||||||
String request = "GET /maps/api/timezone/json?location=" +
|
String request = "GET /maps/api/timezone/json?location=" +
|
||||||
|
#endif
|
||||||
String(systemSettings->latitude(), 7) + "," + String(systemSettings->longitude(), 7) +
|
String(systemSettings->latitude(), 7) + "," + String(systemSettings->longitude(), 7) +
|
||||||
"8×tamp=" +
|
"8×tamp=" +
|
||||||
String(timestamp);
|
String(timestamp);
|
||||||
|
|
||||||
_d("Timezone :: request: ");
|
|
||||||
_dln(request);
|
|
||||||
|
|
||||||
if (systemSettings->mapsAPIKey() != nullptr)
|
if (systemSettings->mapsAPIKey() != nullptr)
|
||||||
request = request + "&key=" + systemSettings->mapsAPIKey();
|
request = request + "&key=" + systemSettings->mapsAPIKey();
|
||||||
|
|
||||||
|
_d("Timezone :: request: ");
|
||||||
|
_dln(request);
|
||||||
|
|
||||||
request = request + " HTTP/1.0\r\nHost: maps.googleapis.com\r\n\r\n";
|
request = request + " HTTP/1.0\r\nHost: maps.googleapis.com\r\n\r\n";
|
||||||
client->write(request.c_str());
|
client->write(request.c_str());
|
||||||
}, nullptr);
|
}, nullptr);
|
||||||
|
@ -143,7 +147,11 @@ void updateTimezone()
|
||||||
_d("Timezone :: available heap: ");
|
_d("Timezone :: available heap: ");
|
||||||
_dln(ESP.getFreeHeap());
|
_dln(ESP.getFreeHeap());
|
||||||
|
|
||||||
|
#ifdef MapsAPIViaProxyScript
|
||||||
|
if(!timezoneClient->connect(TimezoneProxyScriptHost, 80))
|
||||||
|
#else
|
||||||
if(!timezoneClient->connect("maps.googleapis.com", 443, true))
|
if(!timezoneClient->connect("maps.googleapis.com", 443, true))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
_dln("Timezone :: failed to connect to host");
|
_dln("Timezone :: failed to connect to host");
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue