0

I was trying to understand if it is possible(if yes how) to continue the OTA process after downloading the bin file hosted in a remote IP (within the network) ? The code is to be running on ESP32. (Edit) i am trying to introduce a method of self OTA update..which can also be triggered by hitting an end point of the esp webserver (either through mqtt, http etc etc)

I am referring to How to enable the server to automatically download files using arduino for ESP32 WebServer without using SPIFFS and instead using SDcard file but it focusses on downloading from sd card but not network.

Currently, I am following the code mentioned in https://randomnerdtutorials.com/esp32-over-the-air-ota-programming/ which currently deals in uploading the bin file through browser, which I am trying to automate. If somehow I can trigger this part of the code with the data programmatically then I think my question will still be solved.

server.on("/update", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
    ESP.restart();
  }, []() {
    HTTPUpload& upload = server.upload();
    if (upload.status == UPLOAD_FILE_START) {
      Serial.printf("Update: %s\n", upload.filename.c_str());
      if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_WRITE) {
      /* flashing firmware to ESP*/
      if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_END) {
      if (Update.end(true)) { //true to set the size to the current progress
        Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
      } else {
        Update.printError(Serial);
      }
    }
  });

Regards, Shariq

Shariq Azim
  • 136
  • 16
  • servers don't download. clients download. btw: I don't see why the bin should be first saved to SPIFFS or SD card. It can be written to Update directly. – Juraj Apr 12 '21 at 17:32
  • Yes i mean the webserver gives an option hitting which should indicate that it can connect to the remote ota server as client..how can can we write the file to update as you are saying? – Shariq Azim Apr 12 '21 at 18:05
  • It's very hard to understand what you're doing or what exactly your problem is. – Tarmo Apr 12 '21 at 20:24
  • Ok ill explain..i am looking for a method through which i am expecting the program to fetch the ota bin file directly from the remote ip automatically and self OTA update.this can be done in a frequent manner (say every few mins)... But that process can also be triggered externally where i can start the OTA process manually too..so its both self(auto) +manual option...hope it explains. – Shariq Azim Apr 13 '21 at 02:30
  • and with which part do you have a problem? – Juraj Apr 13 '21 at 05:11
  • Ah, you want to trigger OTA; both manually (a user clicking a button) and non-interactively (e.g. when a device detects new firmware). This is a system design choice which depends on many things known only to you. For example, you can build OTA server in the cloud (AWS IoT or GCP IoT) to which the device connects and maintains an MQTT link through which you can send commands to it, including the command to trigger OTA. In the cloud you can implement logic to trigger the OTA automatically, a UI to launch it manually, store the firmware images, manage security, etc - it's yours to build. – Tarmo Apr 13 '21 at 07:24
  • Yes you are correct..both way ota..i am confused how to put that into code..or how to trigger that Ota activity through any automatic way.. the reason i am keeping it both way is to make an option to rollback update ota or put a manual firmware (just for safety) – Shariq Azim Apr 14 '21 at 17:31

0 Answers0