I am implementing OTA updates using Firebase cloud functions/cloud storage.
What I do is store a firmware.bin, generated by PlatformIO, in cloud storage. I then call a cloud function from my ESP32 that returns the signedUrl with rights to download the firmware.bin.
I receive the error “Magic header does not start with 0xE9”.
I have been copying the code from Arduino-esp32 to try and make this work.
WiFiClientSecure client;
client.setTimeout(12000 / 1000);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.print("Connected to ");
Serial.println(ssid);
if(client.connect(CLOUD_FUNCTION_BASE_URL, 443)) {
HTTPClient https;
Serial.print("[HTTPS] begin...\n");
if (https.begin(client, CLOUD_FUNCTION_URL)) {
Serial.print("[HTTPS] GET...\n");
//https.addHeader("Content-Type", "application/json");
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
SIGNED_URL = https.getString();
Serial.println(SIGNED_URL);
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
t_httpUpdate_return ret = httpUpdate.update(client, SIGNED_URL);
switch (ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("HTTP_UPDATE_OK");
break;
}