File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -91,20 +91,24 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
9191OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch () {
9292 OTACloudProcessInterface::State res = Fetch;
9393 int http_res = 0 ;
94+ uint32_t start = millis ();
9495
95- if (http_client->available () == 0 ) {
96- goto exit;
97- }
96+ do {
97+ if (http_client->available () == 0 ) {
98+ goto exit;
99+ }
98100
99- http_res = http_client->read (context->buffer , context->buf_len );
101+ http_res = http_client->read (context->buffer , context->buf_len );
100102
101- if (http_res < 0 ) {
102- DEBUG_VERBOSE (" OTA ERROR: Download read error %d" , http_res);
103- res = OtaDownloadFail;
104- goto exit;
105- }
103+ if (http_res < 0 ) {
104+ DEBUG_VERBOSE (" OTA ERROR: Download read error %d" , http_res);
105+ res = OtaDownloadFail;
106+ goto exit;
107+ }
106108
107- parseOta (context->buffer , http_res);
109+ parseOta (context->buffer , http_res);
110+ } while ((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
111+ millis () - start < downloadTime);
108112
109113 // TODO verify that the information present in the ota header match the info in context
110114 if (context->downloadState == OtaDownloadCompleted) {
Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
4949
5050 const char *username, *password;
5151
52+ // The amount of time that each iteration of Fetch has to take at least
53+ // This mitigate the issues arising from tasks run in main loop that are using all the computing time
54+ static constexpr uint32_t downloadTime = 100 ;
55+
5256 enum OTADownloadState: uint8_t {
5357 OtaDownloadHeader,
5458 OtaDownloadFile,
You can’t perform that action at this time.
0 commit comments