diff --git a/src/XD0OTA.cpp b/src/XD0OTA.cpp index fd6fcb5..c105696 100644 --- a/src/XD0OTA.cpp +++ b/src/XD0OTA.cpp @@ -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)); +} diff --git a/src/XD0OTA.h b/src/XD0OTA.h index e1a77a6..97a4cdd 100644 --- a/src/XD0OTA.h +++ b/src/XD0OTA.h @@ -6,6 +6,8 @@ #include #include +#include + //const int FW_VERSION = 13; // see main.h class XD0OTA { @@ -13,9 +15,10 @@ class XD0OTA { XD0OTA(); void update(void); int checkForUpdates(); + void setClock(); private: const char* fwUrlBase = "https://fwupdate.xd0.de:444/fota/"; - const char* httpsFingerprint = "37 42 61 B9 E6 EE 22 36 D1 59 67 7D 55 53 6E A4 C7 AA 60 26"; + const uint8_t httpsFingerprint[20] = {0x37, 0x42, 0x61, 0xB9, 0xE6, 0xEE, 0x22, 0x36, 0xD1, 0x59, 0x67, 0x7D, 0x55, 0x53, 0x6E, 0xA4, 0xC7, 0xAA, 0x60, 0x26}; String getMAC(); };