|
|
@ -17,6 +17,8 @@ String XD0OTA::getMAC() { |
|
|
|
|
|
|
|
void XD0OTA::update(void) { |
|
|
|
|
|
|
|
setClock(); |
|
|
|
|
|
|
|
int newVersion = checkForUpdates(); |
|
|
|
|
|
|
|
if (newVersion < 1) { |
|
|
@ -33,10 +35,18 @@ void XD0OTA::update(void) { |
|
|
|
String fwImageURL = fwURL; |
|
|
|
fwImageURL.concat( ".bin" ); |
|
|
|
|
|
|
|
DEBUG_MSG( "Firmware image URL: " ); |
|
|
|
DEBUG_MSG( "%s\n", fwImageURL.c_str() ); |
|
|
|
DEBUG_MSG( "Firmware image URL: " ); |
|
|
|
DEBUG_MSG( "%s\n", fwImageURL.c_str() ); |
|
|
|
|
|
|
|
BearSSL::WiFiClientSecure client; |
|
|
|
bool mfln = client.probeMaxFragmentLength("fwupdate.xd0.de", 444, 1024); |
|
|
|
Serial.printf("MFLN supported: %s\n", mfln ? "yes" : "no"); |
|
|
|
if (mfln) { |
|
|
|
client.setBufferSizes(1024, 1024); |
|
|
|
} |
|
|
|
client.setFingerprint(httpsFingerprint); |
|
|
|
|
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL, String(FW_VERSION), httpsFingerprint ); |
|
|
|
t_httpUpdate_return ret = ESPhttpUpdate.update( client, fwImageURL, String(FW_VERSION) ); |
|
|
|
|
|
|
|
switch(ret) { |
|
|
|
case HTTP_UPDATE_FAILED: |
|
|
@ -69,9 +79,12 @@ int XD0OTA::checkForUpdates() { |
|
|
|
DEBUG_MSG( "Firmware version URL: " ); |
|
|
|
DEBUG_MSG( "%s\n", fwVersionURL.c_str() ); |
|
|
|
|
|
|
|
BearSSL::WiFiClientSecure client; |
|
|
|
client.setFingerprint(httpsFingerprint); |
|
|
|
|
|
|
|
HTTPClient httpClient; |
|
|
|
httpClient.setTimeout(5000); |
|
|
|
httpClient.begin( fwVersionURL, httpsFingerprint ); |
|
|
|
httpClient.begin( client, fwVersionURL ); |
|
|
|
int httpCode = httpClient.GET(); |
|
|
|
if( httpCode == 200 ) { |
|
|
|
String newFWVersion = httpClient.getString(); |
|
|
@ -90,3 +103,21 @@ int XD0OTA::checkForUpdates() { |
|
|
|
httpClient.end(); |
|
|
|
return newVersion; |
|
|
|
} |
|
|
|
|
|
|
|
void XD0OTA::setClock() { |
|
|
|
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC
|
|
|
|
DEBUG_MSG(F("Waiting for NTP time sync: ")); |
|
|
|
time_t now = time(nullptr); |
|
|
|
while (now < 8 * 3600 * 2) { |
|
|
|
yield(); |
|
|
|
delay(500); |
|
|
|
DEBUG_MSG(F(".")); |
|
|
|
now = time(nullptr); |
|
|
|
} |
|
|
|
|
|
|
|
DEBUG_MSG(F("")); |
|
|
|
struct tm timeinfo; |
|
|
|
gmtime_r(&now, &timeinfo); |
|
|
|
DEBUG_MSG(F("Current time: ")); |
|
|
|
Serial.print(asctime(&timeinfo)); |
|
|
|
} |
|
|
|