Skip to content

Commit bf9c57c

Browse files
committed
OTA: make fetch blocking for real and also wait for data
1 parent 45b1120 commit bf9c57c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/ota/interface/OTAInterfaceDefault.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,25 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
9393
uint32_t start = millis();
9494

9595
do {
96-
if(http_client->available() == 0) {
97-
goto exit;
98-
}
99-
100-
http_res = http_client->read(context->buffer, context->buf_len);
96+
if(http_client->available()) {
97+
http_res = http_client->read(context->buffer, context->buf_len);
10198

102-
if(http_res < 0) {
103-
DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res);
104-
res = OtaDownloadFail;
105-
goto exit;
106-
}
99+
if(http_res < 0) {
100+
DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res);
101+
res = OtaDownloadFail;
102+
goto exit;
103+
}
107104

108-
parseOta(context->buffer, http_res);
105+
parseOta(context->buffer, http_res);
109106

110-
if(context->writeError) {
111-
DEBUG_VERBOSE("OTA ERROR: File write error");
112-
res = ErrorWriteUpdateFileFail;
113-
goto exit;
107+
if(context->writeError) {
108+
DEBUG_VERBOSE("OTA ERROR: File write error");
109+
res = ErrorWriteUpdateFileFail;
110+
goto exit;
111+
}
112+
} else {
113+
/* Avoid tight loop and allow yield */
114+
delay(1);
114115
}
115116
} while((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
116117
millis() - start < downloadTime);

0 commit comments

Comments
 (0)