ayushsharma82 / ElegantOTA

OTA updates made slick and simple for everyone!
https://elegantota.pro
GNU Affero General Public License v3.0
643 stars 119 forks source link

Upload failed Server returned status code 0 / callbacks not shown in serial #230

Open juanmartin84 opened 3 weeks ago

juanmartin84 commented 3 weeks ago

Hello, i'm using ElegantOTA.h version 3.0.0 with AsyncDemo code in platformio. After select the file.bin to apload nothing is shown in serial monitor.

10:43:39.699 > IP address: 192.168.1.18
10:43:39.715 > HTTP server started

At the end in the browser appears "Upload failed Server returned status code 0"

image

Below the .ini file

board_build.flash_mode = dio
board_upload.flash_size = 4MB

board_build.f_cpu = 240000000L ;set clock frequency to 240MHz
board_build.f_flash = 80000000L ; set flash frequency to 80MHz
board_build.partitions = partition_table_HUGE_APP.csv ;https://github.com/espressif/arduino-esp32/tree/master/tools/partitions
board_build.filesystem = littlefs

upload_speed = 921600
upload_port = COM[34]; COM3 or COM4

lib_deps = 
  mathieucarbou/ESPAsyncWebServer@^3.1.1
  mathieucarbou/AsyncTCP@^3.2.3
  bblanchon/ArduinoJson@^7.1.0
  knolleary/PubSubClient@^2.8
  fbiego/ESP32Time@^2.0.6
  adafruit/Adafruit ADS1X15@^2.5.0

lib_compat_mode = strict

Below the code:

AsyncWebServer otaServer(80);

unsigned long ota_progress_millis = 0;

void onOTAStart(void) {
  // Log when OTA has started
  Serial.println("OTA update started!");
  // <Add your own code here>
}

void onOTAProgress(size_t current, size_t final) {
  // Log every 1 second
  if (millis() - ota_progress_millis > 1000) {
    ota_progress_millis = millis();
    Serial.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final);
  }
}

void onOTAEnd(bool success) {
  // Log when OTA has finished
  if (success) {
    Serial.println("OTA update finished successfully!");
  } else {
    Serial.println("There was an error during OTA update!");
  }
  // <Add your own code here>
}

void otaSetup(void) {

  String RouterSSID = ReadEpromMaster(0,16,"RouterSSID");//setupWifi
  String RouterPASS = ReadEpromMaster(16,32,"RouterPASS");//setupWifi
  delay(10);

  WiFi.begin(RouterSSID.c_str(), RouterPASS.c_str());
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(RouterSSID);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  otaServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(200, "text/plain", "Hi! This is ElegantOTA AsyncDemo.");
  });

  ElegantOTA.begin(&otaServer);    // Start ElegantOTA
  // ElegantOTA callbacks
  ElegantOTA.onStart(onOTAStart);
  ElegantOTA.onProgress(onOTAProgress);
  ElegantOTA.onEnd(onOTAEnd);

  otaServer.begin();
  Serial.println("HTTP server started");
}

void otaLoop(void) {
  ElegantOTA.loop();
}

What can be happening? Thanks

ayushsharma82 commented 3 weeks ago

@juanmartin84 You are using "Huge App" partition table, it doesn't contain any partition for OTA updates.

board_build.partitions = partition_table_HUGE_APP.csv ;https://github.com/espressif/arduino-esp32/tree/master/tools/partitions
mathieucarbou commented 3 weeks ago

@juanmartin84 : for big firmwares (more than 2Mb) you can use MycilaSafeBoot which allows to have a smaller recovery partition used for OTA flash and a bigger app partition, more than 3Mb / 7Mb depending on the flash size (4Mb or 8Mb). MycilaSafeBoot includes ElegantOTA.

https://github.com/mathieucarbou/MycilaSafeBoot

juanmartin84 commented 3 weeks ago

Hello @ayushsharma82 @mathieucarbou , thanks for recommendations. I used this in the .ini file and since I have16mb flash available and seems to be working.

board_upload.flash_size = 16MB
board_build.partitions = app3M_spiffs9M_fact512k_16MB.csv
board_build.filesystem = littlefs

Best regards

Gifford47 commented 2 weeks ago

Hi! @ayushsharma82 @mathieucarbou I have the same issue with an ESP32 S3. INI:

[env:HCP_Giffordv2a]
board = adafruit_feather_esp32s3        # https://docs.platformio.org/en/latest/frameworks/espidf.html#boards
build_flags = ${env:esp32.build_flags} -D SENSORS -D USE_HCSR501 -D USE_BME

I also get "status code 0". which partition type have i to use?

mathieucarbou commented 2 weeks ago

Example of one I like to use:

# Name,   Type, SubType, Offset,   Size,    Flags
nvs,      data, nvs,     0x9000,   0x5000,
otadata,  data, ota,     0xE000,   0x2000,
app0,     app,  ota_0,   0x10000,  0x1F0000,
app1,     app,  ota_1,   0x200000, 0x1F0000,
spiffs,   data, spiffs,  0x3F0000, 0x10000,

which can also be written as:

# Name   ,Type ,SubType  ,Offset ,Size  ,Flags
nvs      ,data ,nvs      ,36K    ,20K   ,
otadata  ,data ,ota      ,56K    ,8K    ,
app0     ,app  ,ota_0    ,64K    ,1984K ,
app1     ,app  ,ota_1    ,2048K  ,1984K ,
spiffs   ,data ,spiffs   ,4032K  ,64K   ,

But you can decide to reduce the ota size, add a coredump, etc.

But in my bigger apps, I use MycilaSafeboot and I have then a huge app partition of 3.2Mb for a 4Mb flash

# Name   ,Type ,SubType  ,Offset ,Size  ,Flags
nvs      ,data ,nvs      ,36K    ,20K   ,
otadata  ,data ,ota      ,56K    ,8K    ,
safeboot ,app  ,factory  ,64K    ,640K  ,
app      ,app  ,ota_0    ,704K   ,3264K ,
spiffs   ,data ,spiffs   ,3968K  ,64K   ,
coredump ,data ,coredump ,4032K  ,64K   ,

And 7.3Mb for a 8Mb flash

# Name   ,Type ,SubType  ,Offset ,Size  ,Flags
nvs      ,data ,nvs      ,36K    ,20K   ,
otadata  ,data ,ota      ,56K    ,8K    ,
safeboot ,app  ,factory  ,64K    ,640K  ,
app      ,app  ,ota_0    ,704K   ,7312K ,
spiffs   ,data ,spiffs   ,8128K  ,64K   ,
coredump ,data ,coredump ,8192K  ,64K   ,
Gifford47 commented 2 weeks ago

thx, now it works!