Mysterious HTTP_UPDATE_FAILED Error (-106) attempting ESP32 OTA

User avatar
PeterPan
Posts: 3
Joined: Sun Aug 21, 2022 3:06 pm

Mysterious HTTP_UPDATE_FAILED Error (-106) attempting ESP32 OTA

Postby PeterPan » Mon Oct 23, 2023 4:42 pm

Platform ESP23 Rover module

I'm trying to get HTTP OTA updates to work in a sketch. As I have a web hosting account (URL in example below), I've placed my version (TXT) file and my firmware (BIN) file in a directory there. For simplicity, the code below only includes my OTA update code. By the output messages, you can see that the code does indeed find the version.txt file, and and determines the new firmware is available ( so you can safely assume it is being called when I'm online or I wouldn't get that far.) The problem is with the binary file header, as you can see from this output...
WiFi Connected - HTTP Response code: 200
Current FW version: 24
Server FW version: 25
New firmware version available...
Updating to http://elfintechnologies.com/ota/pumpMo ... ware25.bin
CALLBACK: HTTP update process started
HTTP_UPDATE_FAILED Error (-106): Verify Bin Header Failed
So, I don't think there is a problem with the server because the code can obviously find and read the version.txt file. I'm also plugged the complete URL to the binary into a browser (which you can see in the output above) to verify I can download it. I've also looked at the downloaded binary file in a hex editor because I'd read that my problem indicates an improper header file, and to look for 0xE9 in the first byte. Indeed the first 4 bytes after down load are "e9 05 02 2f". So at this point I'm not sure what else to do or what to try. The URLs are shown in the output and the code shows how the URL string is built, but I don't have any tools to see what the header for the HTTP download look like. Can anyone help me? Thanks if you can.
  1. /***************************************** */
  2.  
  3.  
  4. // additions for OTA update, 10/2023
  5. // NOTE both <HTTPClient.h> and  <HTTPUpdate.h> are included
  6.  
  7. String version_url  = "http://elfintechnologies.com/ota/pumpMonitor/current_version.txt";
  8. String firmware_url = "http://elfintechnologies.com/ota/pumpMonitor/firmware";
  9. String newbin_url   = "";
  10. unsigned long software_version = VERSION; // 24
  11. unsigned long update_version = 0;
  12. String http_string = "";  // Holding variable.
  13.  
  14.  
  15. /* *** BEGIN These are used by the updater below *** */
  16. void update_started() {
  17.   Serial.println("CALLBACK:  HTTP update process started");
  18. }
  19.  
  20. void update_finished() {
  21.   Serial.println("CALLBACK:  HTTP update process finished");
  22. }
  23.  
  24. void update_progress(int cur, int total) {
  25.   Serial.printf("CALLBACK:  HTTP update process at %d of %d bytes...\n", cur, total);
  26. }
  27.  
  28. void update_error(int err) {
  29.   Serial.printf("CALLBACK:  HTTP update fatal error code %d\n", err);
  30. }
  31.  
  32.  
  33. /* **************updater code ********************** */
  34.  
  35. // Assume this is called when connected to wifi
  36. // connectToWifi() is not shown, but returns TRUE if connected
  37.  
  38. void doVersionUpdate() {
  39.   if (connectToWifi() ) {
  40.     HTTPClient http;
  41.  
  42.     http.begin(version_url.c_str());
  43.  
  44.     int httpResponseCode = http.GET();
  45.  
  46.     if (httpResponseCode>0) {
  47.       Serial.print(" - HTTP Response code: ");
  48.       Serial.println(httpResponseCode);
  49.       http_string = http.getString();
  50.       update_version = http_string.toInt();
  51.       Serial.print("Current FW version: "); Serial.println(software_version);
  52.       Serial.print("Server  FW version: "); Serial.println(update_version);
  53.       // ***** BEGIN UPDATER CODE *****
  54.       if (software_version == update_version){
  55.         Serial.print("No new firmware available\n");
  56.         } else {
  57.         newbin_url = firmware_url + update_version + ".bin";
  58.         Serial.print("New firmware version available...\n Updating to ");
  59.         Serial.print(newbin_url); Serial.print("\n");
  60.  
  61.         httpUpdate.onStart(update_started);
  62.         httpUpdate.onEnd(update_finished);
  63.         httpUpdate.onProgress(update_progress);
  64.         httpUpdate.onError(update_error);
  65.  
  66.         //t_httpUpdate_return ret = httpUpdate.update(client, "newbin_url");
  67.         t_httpUpdate_return ret = httpUpdate.update(http, newbin_url);
  68.         // Or:
  69.         //t_httpUpdate_return ret = httpUpdate.update(client, "server", 80, "/file.bin");
  70.  
  71.         switch (ret) {
  72.           case HTTP_UPDATE_FAILED:
  73.             Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
  74.             break;
  75.  
  76.           case HTTP_UPDATE_NO_UPDATES:
  77.             Serial.println("HTTP_UPDATE_NO_UPDATES");
  78.             break;
  79.  
  80.           case HTTP_UPDATE_OK:
  81.             Serial.println("HTTP_UPDATE_OK");
  82.             break;
  83.  
  84.         }
  85.       }
  86.       // ***** END UPDATER CODE *****
  87.     }else{
  88.       Serial.print("Error code: ");
  89.       Serial.println(httpResponseCode);
  90.     }
  91.     // Free resources
  92.   http.end();
  93.  
  94.   } else {
  95.    Serial.print("\nCan't connect for Version update");
  96.   }
  97.  
  98.  WiFi.disconnect();
  99. }
  100.  

Who is online

Users browsing this forum: Eshwar487 and 123 guests