I'm trying to OTA update the ESP32 by letting it make a get request to a file on Azure blob storage.
For some unknown reason it won't let me use the WifiClient.connect() function, since it always returns a 0. So now I'm using the HTTPClient library to make a get request to a blob storage on Azure. I got it to make the request and now I'm trying to stream it into:
Update.writeStream();
But whenever I get to that part, it crashes and gives met the following message:
Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x00000000 PS : 0x00060630 A0 : 0x800d1a18 A1 : 0x3ffb1f30
A2 : 0x00000000 A3 : 0x3ffb1f64 A4 : 0x3ffc11b8 A5 : 0x00000000
A6 : 0x3ffbd484 A7 : 0x00000000 A8 : 0x800d3304 A9 : 0x3ffb1f10
A10 : 0x3ffb1f64 A11 : 0x3f40124c A12 : 0x00000001 A13 : 0x3ffbd44c
A14 : 0x00000000 A15 : 0x3ffc1678 SAR : 0x0000000a EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
Backtrace: 0x00000000:0x3ffb1f30 0x400d1a15:0x3ffb1f50 0x400d63bb:0x3ffb1fb0 0x40088b9d:0x3ffb1fd0
Here is the code:
http.begin("https://AZUREACCOUNT.blob.core.windows.net/CONTAINER/firmware.bin");
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
WiFiClient * stream = http.getStreamPtr();
unsigned long timeout = millis();
while (stream->available() == 0) {
if (millis() - timeout > 5000) {
Serial.println("Client Timeout !");
stream->stop();
return;
}
}
int contentLength = http.getSize();
if (Update.begin(contentLength)) {
Serial.println("Begin OTA. This may take 2 - 5 mins to complete. Things might be quite for a while.. Patience!");
// No activity would appear on the Serial monitor
// So be patient. This may take 2 - 5mins to complete
size_t written = Update.writeStream((WiFiClient &)stream);
if (written == contentLength) {
Serial.println("Written : " + String(written) + " successfully");
} else {
Serial.println("Written only : " + String(written) + "/" + String(contentLength) + ". Retry?" );
// retry??
// execOTA();
}
if (Update.end()) {
Serial.println("OTA done!");
if (Update.isFinished()) {
Serial.println("Update successfully completed. Rebooting.");
ESP.restart();
} else {
Serial.println("Update not finished? Something went wrong!");
}
} else {
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
}
}
else {
Serial.println("Not enough space");
}
How can I make this code work so that the device will GET the file from the Azure blob storage and update itself?
You have to find out why it is crashing. The Backtrace does not help you without a tool.
Stack
Please install this tool in your Arduino IDE:
https://github.com/me-no-dev/EspExceptionDecoder
And put your error inside it to get the calling stack and see where it is crashing. Probably it has nothing to do with the Update but only with the httpclient.
SSL:
You are calling a https
page, do you use the secureClient and do you use a SSL certificate? Without it, you will not be able to communicate over a secure connection.
And finally: VERBOSE
Compile with verbose mode active. It is really important to get every message when something does not work. And for the https, every info is very important to find out why it doesn't work like expected.
User contributions licensed under CC BY-SA 3.0