-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feature/HTTPUpdate-headers: add response headers with sketch and flash sizes, and a SHA256 #2116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/HTTPUpdate-headers: add response headers with sketch and flash sizes, and a SHA256 #2116
Conversation
Nice :) |
BTW those |
@me-no-dev thnx for the compliment and for the SHA256 idea. I created a new PR for removing the F() macro's. |
I'm trying to use the httpupdate demo with AWS S3 bucket.
I'm trying different things but can't get it right:
connection refused, connection closed, core panic,.... but nothing that works. Any suggestions? |
Can you post your full sketch? I am not familiar with AWS S3, does it check the HTTP request headers that are sent? |
Maybe the error is caused because you miss http:// in front of the url? |
Hi Jeroen, I tried all sorts of combinations, I think the problem is something else. the non secured http download from the 'upload' library uses [(http://espfirmware.s3-eu-west-1.amazonaws.com/AWS_S3_OTA_Update_WKE.ino.doitESP32devkitV1.bin) this is the code from the 'update' library that works, it's the identical example sketch just modified wifi name and SSID, and AWS URL: Upload: Build & upload // Check the bottom of this sketch for sample serial monitor log, during and after successful OTA Update #include <WiFi.h> WiFiClient client; // Variables to validate // Your SSID and PSWD that the chip needs // S3 Bucket Config void execOTA() {
// Serial.print(String("GET ") + bin + " HTTP/1.1\r\n" +
} else { // OTA Logic // Check what is the contentLength and if content type is // check contentLength and content type
} else { // Utility to extract header value from headers void setup() { Serial.println("Connecting to " + String(SSID)); // Connect to provided SSID and PSWD // Wait for connection to establish // Connection Succeed // Execute OTA Update void loop() { |
The error had nothing to do with the HTTPUpdate library. It was caused by PR #2148 in the function WiFiClient::available() Testing on your URL your firmware is downloaded. I get an error though: I suspect this has something to do with this: I do not understand that issue completely, but could you compile the test sketch that you want to serve from AWS and the sketch you are running both with the latest core? I will do another PR to do a few additional checks in HTTPUpdate(), but this does not cause your trouble. |
the sketch in AWS was probably not compiled with the latest core, I'll update the bin file and let you know. |
The server could check what version you are requesting on several ways:
|
hi Jeroen, now the binary file in AWS is compiled with latest firmware 1,0,1-rc. I don't see any update possibility to use your latest changes to httpupdate library. What is the best way? Anyway, when I run the httpupdate sketch, it returns: HTTP_UPDATE_FAILD Error (-100): Not Enough space |
@TLS1000 Is it true that your sketch checks the chip id and will fail if it isn't a predefined value? In that case I succeeded in downloading your sketch. I get:
The Not enough space issue is because recently a function was added to check the free space. This checks the free space of the memory partition where the sketch is running in. However the ESP32 has a second partition, and that size should be used. I am going to ask the developers to add a function to get the size of the other partition and will make a PR afterwards. If you want to try it now you can make the changes yourself. Just edit two files. You can find these files in a sub directory where you installed the ESP32 Arduino core. The path is hardware/espressif/esp32/libraries/ Edit WiFi/src/WiFiClient.cpp find
Replace this whole function with:
Next edit HTTPUpdate/src/HTTPUpdate.cpp Find the line
Replace with
That should do the trick! |
Yes, I create bin files that only work on one board, since the files are public on AWS... If you see that message it means the OTA was successful. One thing I found out is that AWS S3 puts an 'ETag' in the response header, from what I understood some sort of CRC/MD5 of the file. Via the ETag in the response header the ESP can also check if there is different version available. I store the ETag in EEPROM so it's still available after OTA. |
That's nice :) |
I think I finally understand what you want. The AWS is just a file server, so you can not control the response headers sent. If you store the ETag in EEPROM you could compare it with the ETag presently served at AWS using your URL. If they differ you know the sketch has to be updated.
This gives the following output:
Don't forget to set your WiFi password! |
haha, and I thought you understood me the whole way :-) EEPROM library is also doing great stuff for me with functions like the EEPROM.writeString() and readString() to easily write and read the ETag value. Now cracking the hornbill AWS IOT library and I can do both remote process monitoring and firmware update. |
:-D, you're welcome, good luck with the IoT library! |
This PR is a follow up of some of the left overs still to do in PR #1979.
The request headers x-ESP32-free-space, x-ESP32-sketch-size and x-ESP32-chip-size are added. Because a SHA256 is already supported by the core functions while a MD5 isn't, a x-ESP32-sketch-sha256 is added instead of a x-ESP32-sketch-md5 header.
Logging for sketch size and free sketch space is added.
For a sketch the length is checked to fit in the free space before flashing starts. For SPIFFS this feature is still “to do”. This is not essential, the size is checked later by Updater::begin().
Because peekBytes() is not implemented in WiFiClient, only the magic header byte 0xE9 is checked. After this magic byte follow bytes that indicate the length of the sketch to be uploaded. This length could be checked with the available length. This is also not essential, the library checks if it fits in another step (at Updater::begin()).
WiFiUDP::stopAll()and WiFiClient::stopAllExcept(tcp) as called in the ESP8266 version of the library are not called in this library, because these functions are not implemented (yet). As I recall correctly these functions were introduced due to issues with the ESP8266 WiFi chip. I did not encounter any issues on my ESP32 not calling these functions.