我正在尝试通过允许ESP32向Azure blob存储上的文件发出get请求来OTA更新ESP32。
由于某些未知原因,它不会让我使用WifiClient.connect()函数,因为它始终返回0。所以现在我正在使用HTTPClient库向Azure上的Blob存储发出get请求。我收到了它以发出请求,现在我正尝试将其流式传输到:
Update.writeStream();
但是,只要我提到那部分,它就会崩溃并给出以下消息:
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
代码如下:
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");
}
如何使此代码起作用,以便设备从Azure blob存储中获取文件并自我更新?
答案 0 :(得分:0)
您必须找出崩溃的原因。没有工具,Backtrace无法帮助您。
堆栈
请在您的Arduino IDE中安装此工具:
https://github.com/me-no-dev/EspExceptionDecoder
并将错误放入其中,以获取调用堆栈并查看崩溃的位置。可能与更新无关,而仅与httpclient有关。
SSL :
您正在调用expect
页面,是否使用secureClient和SSL证书?没有它,您将无法通过安全连接进行通信。
最后:详细
在详细模式处于活动状态时进行编译。当某件事情不起作用时,获取每条消息非常重要。对于https,每条信息都非常重要,以找出为什么它无法按预期工作。