Skip to content

Esp32 OTA crashing while updating(invalid chip ID) #3889

@yogeshwaran774

Description

@yogeshwaran774

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.3
IDE name: Arduino IDE
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

I am using AsyncTcp library for OTA in my ESP32. My device Esp32 act as client and file downloaded from the server, then Update.write(); called to do OTA operation. So i wrote a call back "onData()" such that whenever data comes i read in a string and check for "#$#$#$#$#$" which i added in the bin file to detect the body of the response. When special string comes i know bin file data starts and i started pushing data to the OTA memory. Up to some point OTA write operation was proper, after sometime server disconnects, there it goes to disconnect callback and call Update.end(true) after that ESP throws error as E (15066) boot_comm: image has invalid chip ID, expected at least 0, found 35478
E (15067) boot_comm: image has invalid chip revision, expected at least 1, found 17
and i have checked total amount of bytes received 824092 bytes, but my original file size was 825210 bytes

FLASK SERVER CODE(host : 0.0.0.0)
@app.route("/send_bin")
def Update():
print("sending bin file",file=sys.stderr)
filename = "test.ino.esp32.bin"
return send_file(filename, mimetype='application/octet-stream')

Sketch:

//Change the code below by your sketch
static AsyncClient * aClient = NULL;
bool uploading = false;
void  start_upload(uint8_t &d, size_t &len);
size_t total_length;
void setup() {
Serial.begin(115200);
  //Serial.println("new frimware");
  WiFi.setAutoConnect(true);
  WiFi.begin("your_ssid", "your_password");
  while (WiFi.status() != WL_CONNECTED);
  Serial.print("IP : "); Serial.println(WiFi.localIP());
  runAsyncClient();
}

void loop() {
}

void runAsyncClient() {
  if (aClient) //client already exists
    return;

  aClient = new AsyncClient();
  if (!aClient) //could not allocate client
    return;

  aClient->onError([](void * arg, AsyncClient * client, int error) {
    Serial.println("Connect Error");
    aClient = NULL;
    delete client;
  }, NULL);

  aClient->onConnect([](void * arg, AsyncClient * client) {
    Serial.println("Connected");
    aClient->onError(NULL, NULL);

    client->onDisconnect([](void * arg, AsyncClient * c) {
      Serial.println("Disconnected");
      Serial.println(total_length);
      if (Update.end(true)) { //true to set the size to the current progress
        Serial.printf("Update Success Rebooting...");
        esp_restart();
      }
      esp_restart();
      aClient = NULL;
      delete c;
    }, NULL);

    client->onData([](void * arg, AsyncClient * c, void * data, size_t len) {
      Serial.print("\r\nData: ");
      Serial.println(len);
      size_t captured;
      String conv_To_String;
      if (!uploading)
      {
        char* Rec_string = (char*)data;
        conv_To_String = (String)Rec_string;
        Serial.println(conv_To_String);
        captured = conv_To_String.indexOf("#$#$#$#$#$");  // added this string in BIN file such 
                                                                                           //while detecting body part of the 
                                                                                          //response will be easier.
        if (captured != -1)
        {
          Serial.println("Captured");
          //Serial.println(conv_To_String);
          String cap_data = conv_To_String.substring(captured + 10, len);
          Serial.println(cap_data);
          size_t len = cap_data.length();
          char to_array[len];
          cap_data.toCharArray(to_array, len);
          uint8_t *passing_data = (uint8_t*)data;
          for (size_t i = 0; i < len; i++)
          {
            Serial.write(to_array[i]);
            passing_data[i] = NULL;
          }
          memcpy(passing_data, to_array, len);
          uploading = true;
          len = len - 1;
          total_length = len;
          start_upload(*passing_data, len);
        }
      }
      else
      {
        //once bin file data starts coming in Ondata handle push to OTA memory
        uint8_t* d = (uint8_t*)data;
        total_length += len;
        //        for (size_t i = 0; i < len; i++)
        //                {
        //                  Serial.write(d[i]);
        //                }
        if (Update.write(d, len) != len) {
          Update.printError(Serial);
          return;
        }
      }

      //      for (size_t i = 0; i < len; i++)
      //        Serial.write(d[i]);
    }, NULL);

    //send the request
    client->write("GET /send_bin HTTP/1.0\r\nHost: \r\n\r\n");
  }, NULL);

  if (!aClient->connect("192.168.43.140", 5000)) {  // ip mentioned was computer wifi adapter ip
    Serial.println("Connect Fail");
    AsyncClient * client = aClient;
    aClient = NULL;
    delete client;
  }
}

void  start_upload(uint8_t &d, size_t &len)
{
  if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH)) { // Start with max available size
    Update.printError(Serial);
    return;
  }
  /* flashing firmware to ESP*/
  Serial.println("starts uploading");
  if (Update.write(&d, len) != len) {
    Update.printError(Serial);
    return;
  }
}

when i call Update.end(true); the following was the debug message

Debug Messages:

[D][Updater.cpp:136] begin(): OTA Partition: app1
E (9509) boot_comm: image has invalid chip ID, expected at least 0, found 65535
E (9516) boot_comm: image has invalid chip revision, expected at least 1, found 255

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions