1

I'am asking this question, because in my ESP-01 OTA upload always fail. In fact update won't even start. When update was triggered esp wifi led(build in blue) indicates "working" , but after cca one second esp reset itself. And The original program remains and starts again...

4
  • what Flash size did you select in Tools menu?
    – Juraj
    Commented Oct 17, 2020 at 10:21
  • 1MB(FS:none, OTA:~502KB).... according as I read in tutorial, that OTA has to be at least half of memory for propper running...
    – Sahasrar
    Commented Oct 17, 2020 at 11:35
  • try to turn off firewall on PC
    – Juraj
    Commented Oct 17, 2020 at 11:52
  • I tried, but with no effect...
    – Sahasrar
    Commented Oct 17, 2020 at 13:07

2 Answers 2

3

Yes, 1MB is fine for OTA. There are, though, a few caveats when working with OTA that you must observe regardless of the flash size:

  1. The maximum OTA program size is less than half the available flash size. Typically it is about 500kB. Two copies need to be stored in flash, plus the partition table and NVRAM. The rest of the flash on larger chips is most often dedicated to FS storage.
  2. The device must first be programmed through USB with an OTA-compatible partition layout.
  3. After programming through USB it must be manually reset or power cycled to set the boot mode correctly.
  4. You can not change the partition layout over OTA programming. You need to make sure you have the same partition layout selected as when you originally programmed through USB.
  5. ArduinoOTA.handle(); has to be called very regularly to handle the programming request. You can't have any blocking code in your sketch that might stop that from being called.

Observe all those and you should be able to program over WiFi with no problems.

5
  • I programmed it via USB, program works, OTA was shown in Tools>port options. Program still running... LED blinking... But when I press Upload code to device via OTA port ESP freeze and after few second IDE report error: No Answer, but very strange thing is that original program crashes and esp is unprogrammed... Than i have to upload code again with USB
    – Sahasrar
    Commented Oct 17, 2020 at 18:57
  • And have you taken point 5 into account?
    – Majenko
    Commented Oct 17, 2020 at 18:58
  • every point of your advice is fulfilled... My code is about 210 KB
    – Sahasrar
    Commented Oct 17, 2020 at 18:59
  • In my void loop is only ArduinoOTA.handle(); no more rows...
    – Sahasrar
    Commented Oct 17, 2020 at 19:00
  • @Sahasrar, point 3.?
    – Juraj
    Commented Oct 18, 2020 at 5:29
2

For OTA uploads, the size of the compiled (old sketch + new sketch) should not exceed the flash size.

Due to this, large sketches (more than 500KB with 1MB flash) cannot be OTA uploaded directly if the sketch size exceeds half of the flash size.

However, this restriction can be circumvented by first uploading a sketch only with OTA features as given below:


#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

char ssid[] = "xxxxxxxx"; //WiFI user id
char pass[] = "yyyyyy";   //WiFi password

#define OTA_Host_Name "ESP01S-EMPTY-OTA"

void setup()  {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);

  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    delay(5000);
    ESP.restart();
  }
  ArduinoOTA.setHostname(OTA_Host_Name);
  ArduinoOTA.begin();
}

void loop() {
  ArduinoOTA.handle();
}

This script will compile to around 300KB. Once this script is uploaded in flash, a script with upto 700KB can be uploaded through OTA to a 1MB flash!

Upload this script first. Then restart the controller and choose "ESP01S-EMPTY-OTA" as the port and upload the new updated script that you wish to upload!

IMPORTANT: Firewall must be turned OFF during OTA uploads.

1
  • are you sure? the partitions are selected in Tools menu. can it be changed with OTA?
    – Juraj
    Commented Dec 4, 2021 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.