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...

Sahasrar
  • 161
  • 1
  • 8

2 Answers2

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.

Majenko
  • 103,876
  • 5
  • 75
  • 133
  • 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 Oct 17 '20 at 18:57
  • And have you taken point 5 into account? – Majenko Oct 17 '20 at 18:58
  • every point of your advice is fulfilled... My code is about 210 KB – Sahasrar Oct 17 '20 at 18:59
  • In my void loop is only ArduinoOTA.handle(); no more rows... – Sahasrar Oct 17 '20 at 19:00
  • @Sahasrar, point 3.? – Juraj Oct 18 '20 at 05: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.

sempaiscuba
  • 1,033
  • 8
  • 20
  • 32