OTA problem on esp

I can’t get OTA to work to my esp8266. My code is long and I’ll show it if needed, but it is pretty much the sample OTA code after I get wifi set up and working. I’m setting up WiFi up as an AP, starting a webserver, dns, and mdns before connecting as a STA and then starting OTA.

When I try the OTA, pio says …

Looking for upload port...
Use manually specified: 192.168.1.235
Uploading .pioenvs/d1_mini/firmware.bin
15:28:48 [DEBUG]: Options: {'esp_ip': '192.168.1.235', 'host_port': 49136, 'image': '.pioenvs/d1_mini/firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 8266, 'spiffs': False, 'debug': True, 'progress': True}
15:28:48 [INFO]: Starting on 0.0.0.0:49136
15:28:48 [INFO]: Upload size: 290144
15:28:48 [INFO]: Sending invitation to: 192.168.1.235
15:28:49 [INFO]: Waiting for device...
15:28:59 [ERROR]: No response from device
*** [upload] Error 1

Meanwhile my debug serial port output says this immediately upon trying the OTA …

OTA updating firmware
OTA Error[2]: Connect Failed
OTA Error[4]: End Failed

I get ArduinoOTA.onStart, then ArduinoOTA.getCommand works, and then I get the two ArduinoOTA.onError calls.

In summary, the esp seems to work fine and starts processing the update but pio doesn’t think there is any response from the esp.

I updated the ArduinoOTA from github because of the getCommand bug (which should really be fixed). Yesterday I refreshed pio by deleting ~/.platformio.

Any ideas for what I should try next?

Edit: this is my env …

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
build_flags = -Wl,-Tesp8266.flash.1m64.ld
upload_port = 192.168.1.235

You might need to share your code.

You need this in setup:

 ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH)
      type = "sketch";
    else // U_SPIFFS
      type = "filesystem";

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();

and also this in your loop:

ArduinoOTA.handle();

And of course you need to include :

#include <ArduinoOTA.h>

Ensure there are no delays in your code to block the ESP from seeing your request.

Thanks. I’ve already implemented ESP8266httpUpdate and it works fine.

hi I’m getting the same error. Would you be able to explain how you fix it ?