mikalhart / ESP32-OTA-Pull

An ESP32/Arduino library for doing easy "pull"-based OTA ("Over The Air") updates
MIT License
44 stars 15 forks source link

Errors returned with known good server files #6

Closed nnangeroni closed 9 months ago

nnangeroni commented 9 months ago

First of all, a huge thanks for PullOTA!

I’m able to use it with the example app, but in my project, using the same proven-good server files, I keep getting “CheckForOTAUpdate returned -1 (Profile matched, but update not applicable)”. My code:

  ESP32OTAPull ota;
  ota.SetCallback(callback_percent);
  Serial.printf("   Retrieving %s\n", JSON_URL);
  int ret = ota.CheckForOTAUpdate(JSON_URL, VERSION);
  Serial.printf("   CheckForOTAUpdate returned %d (%s)\n", ret, errtext(ret));

JSON_URL and VERSION worked in the example file. I tried adjusting VERSION codes, to no avail.

I tried editing CheckForOTAUpdate() in ESP32OTAPull.h to:

    int CheckForOTAUpdate(const char* JSON_URL, const char *CurrentVersion, ActionType Action = UPDATE_AND_BOOT)
        { 
        return DoOTAUpdate("https://roadrunnercomfort.com/updates/1.0.7.bin", UPDATE_AND_BOOT);
    }

And got “CheckForOTAUpdate returned 4 (Update fail (no OTA partition?))”. So I tried again, with:

int CheckForOTAUpdate()
    {
    return DoOTAUpdate("https://roadrunnercomfort.com/updates/RRC-1.0.7.bin", UPDATE_AND_BOOT);
    }

This time I got “CheckForOTAUpdate returned -11 (Unknown error)”

Any clues to get this working would be most welcome, thanks!

mikalhart commented 9 months ago

Hi Nancy... could I get you to share your value for VERSION and the contents of the file you've posted to JSON_URL? (Obfuscate any sensitive bits if you need to.)

I get bit by that -1 return code often myself, and it invariably is because I've made a mistake in the JSON.

The return code 4 probably means that you didn't correctly set the Partition Scheme to one that includes and OTA partition (also a common mistake!)

Return code -11 is an HTTP timeout. Let's think about this later.

nnangeroni commented 9 months ago

mikalhart, Thanks for responding. JSON_URL file is:

{
  "Configurations": [
    {
    "URL": "https://roadrunnercomfort.com/updates/RRC1.0.7.bin"
    }
  ]
}

I've also tried JSON_URL file:

{
  "Configurations": [
    {
    "Version": "1.1.1",
    "URL": "https://roadrunnercomfort.com/updates/RRC1.0.7.bin"
    }
  ]
}

...with VERSION 1.0.8. My Partition scheme is set to "Large OTA with minimal SPIFFS". (I have been using a push OTA update for some time.)

nnangeroni commented 9 months ago

Further thought: I'm using Core0 for BLE scanning tasks, and there seems to be some relationship between my usage of the two cores and these error messages. I'm still exploring this.

nnangeroni commented 9 months ago

When I add a dummy Core1 task, the error returned changes to "HTTP GET failure". Here's that code:

In setup():

  xTaskCreatePinnedToCore(
    C1_mainLoop,   /* Task function. */
    "TaskCore1",   /* name of task. */
    2000,          /* Stack size of task */
    NULL,          /* parameter of the task */
    0,             /* priority of the task */
    &TaskCore1,    /* Task handle to keep track of created task */
    1);            /* pin task to core 1 */

void C1_mainLoop( void * pvParameters  ) {
  for (;;) {
  }
}

If I reduce that stack size to 500, the error code returns to -1. I'm running an ESP32-Pico-Kit; I don't know how the stack size might be influencing OTA-Pull operation.

I'm happy to share as much code as you care to look at. Thanks again for your kind help.

mikalhart commented 9 months ago

Nancy, I modified the Basic-OTA-Example sketch to point to a "Nancy.json" I created, that's identical to (one of) yours:

{
    "Configurations": [
      {
        "Version": "1.0.7",
        "URL": "https://roadrunnercomfort.com/updates/RRC1.0.7.bin"
      }
    ]
  }

When I do

#define VERSION "1.0.8"
int ret = ota.CheckForOTAUpdate(JSON_URL, VERSION);

... it returns -1, as expected. 1.0.8 is not less than 1.0.7.

But the next bit, pretending the current version is 0.0.0, it succeeds:

ret = ota.CheckForOTAUpdate(JSON_URL, "0.0.0");
mikalhart commented 9 months ago

Ah, I just thought of something. If you are doing Bluetooth scanning on a different core, you wouldn't expect ESP32-OTA-Pull to work reliably. WiFi and Bluetooth use the same frequency and antenna in ESP32, and you can't (easily) have them work together. (I realize this doesn't explain the HTTP failure when your 2nd core is just idling.)

nnangeroni commented 9 months ago

Thank you again for your help.

My prior debugging led me to disable scanning while OTA updating and vice versa, so there should be no interference.

But my JSON file is:

{
  "Configurations": [
    {
    "Version": "1.1.1",
    "URL": "https://roadrunnercomfort.com/updates/RRC1.0.7.bin"
    }
  ]
}

I'm not sure why you're seeing "Version": "1.0.7".

I tried changing my update call to:

ret = ota.CheckForOTAUpdate(JSON_URL, "0.0.0"); This produced the same result. I've also tried leaving Version out (your code seems to treat that the same as a later version), with no change in outcome.

The attached file, Basic-OTA-test, updates correctly. It includes a dummy Core0 task.

If you have any further ideas or suggestions I'd be most grateful.

Thanks! Basic-OTA-test.zip

mikalhart commented 9 months ago

Hi Nancy--

I took your posted sketch and -- after the usual tiny modification of SSID/Wifi password, etc. -- it ran fine. It downloaded the json from roadrunnercomfort.com and then performed the OTA update (because 1.1.1 > 1.0.0).

I wonder... do you have the latest library? A few months ago I changed how version worked from numeric to string versions.

One more tip. Try running the sketch after a clean power reset, i.e. unplug and reconnect the power supply. I find that sometimes the WiFi or HTTP states aren't always cleared if you dont.

Good luck!

nnangeroni commented 9 months ago

Mikal, Thanks again for your time and attention! It is a privilege to be able to discuss this with you.

I do indeed have the latest ESP32OTAPull.h version; I see that you updated the example JSON file syntax (looked like indentations only changed?), I updated mine to match, and changed the extension to ".json". I still get "update not applicable".

I understand you may have had enough of this issue. Could I interest you in being compensated for further help? Getting this working is very important to me, I'm working on a product to encourage more climate-friendly behavior (see RoadrunnerComfort.com). Please email me at nancy@nangeroni.net so we can hold that discussion privately.

The file I previously attached (Basic-OTA-test.zip) is the one that DOES work properly for me. I will be happy to send you one that does not work including all but sensitive portions via email, I don't want to post it here for public access (although I look forward to sharing the solution here). Again, please email me at nancy@nangeroni.net.

Wishing you kindnesses, Nancy

nnangeroni commented 9 months ago

I've gotten Pull OTA working on my controller now; the biggest factor was probably my load size reduction from 96% of available flash to 67%, which I achieved by replacing my BLE code with NimBLE (shout out to h2zero!). There were issues with error codes in Pull OTA which I'm sure will be resolved soon, but I want to give a HUGE thanks to Mikal for his help in getting this up and running.