Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failed to update from github #10

Open
sagartec opened this issue May 1, 2024 · 4 comments
Open

Failed to update from github #10

sagartec opened this issue May 1, 2024 · 4 comments

Comments

@sagartec
Copy link

sagartec commented May 1, 2024

I have tried Basic-OTA-Example.ino example and updated the basic config like SSID and Password. then i updated the config json like follows,

{
  "Configurations": [
    {
      "Board": "ESP32_DEV",
      "Version": "1.0.0",
      "Device": "24:0A:C4:B0:0C:64",
      "URL": "https://github.com/sagartec/test/releases/download/test01/Blink.ino.bin"
    }
  ]
}

The binary is available publically but still code is not working for me, following are the serial prints. Am i missing anything?
I am using DOIT ESP32DEVKIT board.
Any help would really appreciated!!!

Connecting to WiFi 'hidden'.................

We are running version 0.0.9 of the sketch, Board='ESP32_DEV', Device='24:0A:C4:B0:0C:64'.
Checking https://github.com/sagartec/test/releases/download/test01/Basic-OTA-Example.json to see if an update is available...
CheckForOTAUpdate returned 302 (Unexpected HTTP response code)

But if we pretend like we're running version 0.0.0, we SHOULD see an update happen.
(If the update succeeds, the reboot should prevent us ever getting here.)
CheckOTAForUpdate returned 302 (Unexpected HTTP response code)

@mikalhart
Copy link
Owner

mikalhart commented May 1, 2024 via email

@nnangeroni
Copy link

I have also experienced failures to update that I've been unable to explain. Using similar loads in two different online directories, for example, updates always succeeded with one and always failed with the other, the only difference being the subdirectory name. Perhaps my problem stems from the same source.

@ctroncoso
Copy link

The link https://github.com/sagartec/test/releases/download/test01/Blink.ino.bin

redirects to : https://github.com/stechiez/test/releases/download/test01/Blink.ino.bin

which redirects to:
https://objects.githubusercontent.com/github-production-release-asset-2e65be/634512841/6e0eeb2b-da14-4c61-af6a-b0fc75547cb5?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240724%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240724T021345Z&X-Amz-Expires=300&X-Amz-Signature=b62530a16bdd4521cdd7575c85e93d4f2b936d2a5600985240b2a1181ac74d81&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=634512841&response-content-disposition=attachment%3B%20filename%3DBlink.ino.bin&response-content-type=application%2Foctet-stream

which returns a 200 with correct content-length: content-length: 237424
Note that this is a dynamic url with signatures, dates, and might not work after a few minutes.

Using releases might not be a good idea with github.
Just creating a "releases" folder on the repository might be a better way to go.
Either way, redirects handling would be a nice improvement.

@mrcodetastic
Copy link

This is a limitation of the underling esp32-arduino HTTPClient library. I don't think there's a solution to this one unless they've amended the library to support HTTP 302 redirection responses.

In the mean time you could potentially manage this in your own code, based on a Google Gemini suggestion:

#include <HTTPClient.h>

void handleRedirect(String originalUrl) {
  HTTPClient http;

  // Send the initial request
  http.begin(originalUrl);
  int httpCode = http.GET();

  if (httpCode == HTTP_CODE_MOVED_PERMANENTLY || httpCode == HTTP_CODE_FOUND) {
    String newUrl = http.getHeader("Location");
    http.end(); // Close the initial connection

    // Send the second request to the new URL
    http.begin(newUrl);
    httpCode = http.GET();

    if (httpCode == HTTP_CODE_OK) {
      String response = http.getString();
      // Process the final response here, e.g., parse JSON, extract text, etc.
      Serial.println(response);
    } else {
      Serial.printf("Error on second request: %d\n", httpCode);
    }
  } else {
    Serial.printf("Error on initial request: %d\n", httpCode);
  }

  http.end();
}```

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants