I am using the following:
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
In order to connect to a FOTA server that I have set up.
There I check for a ".bin" file that matches the ESP8266´s own MAC address converted to string. All is well there.
What I´m doing with http.GET() is first to retrieve "Last Modified" header, so I can compare to my current firmware´s saved date and time.
HTTPClient httpClient;
httpClient.setTimeout(2000);
httpClient.begin( cfgVersionURL );
httpClient.collectHeaders(headerKeys, headerKeysCount);
int httpCode = httpClient.GET();
if (httpCode == 200 && httpClient.hasHeader("date") && httpClient.hasHeader("last-modified")) {
String onlineCurrentDate = UTC2Date(httpClient.header("date"));
String onlineConfigDate = UTC2Date(httpClient.header("last-modified"));
String lastConfigUpdate = <value from SPIFF parameter>
if (onlineConfigDate > lastConfigUpdate) {
String newConfig = httpClient.getString();
"UTC2Date" simply converts a UTC Date format to YYYYMMDDhhmmss string for easier comparison.
Of course, +99 out of 100 requests do not result in firmware update.
The question is if GET() retrieves the whole file from the server, or the bulk of the file is not currently received until getString() is called.
The .bin files are currently around 400Kb and in some scenarios the ESP8266 will be running on battery, so every kbyte and second turned on counts.
I have read that http.HEAD() sent to the same URL retrieves only headers, which is all I need to compare dates, but I haven´t found a clear way to implement it in my sketch.
Any advice?