File tree 2 files changed +15
-7
lines changed
2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -91,20 +91,24 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
91
91
OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch () {
92
92
OTACloudProcessInterface::State res = Fetch;
93
93
int http_res = 0 ;
94
+ uint32_t start = millis ();
94
95
95
96
if (http_client->available () == 0 ) {
96
97
goto exit ;
97
98
}
98
99
99
- http_res = http_client->read (context->buffer , context->buf_len );
100
+ do {
101
+ http_res = http_client->read (context->buffer , context->buf_len );
100
102
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
+ }
106
108
107
- parseOta (context->buffer , http_res);
109
+ parseOta (context->buffer , http_res);
110
+ } while ((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
111
+ millis () - start < downloadTime);
108
112
109
113
// TODO verify that the information present in the ota header match the info in context
110
114
if (context->downloadState == OtaDownloadCompleted) {
Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
49
49
50
50
const char *username, *password;
51
51
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
+
52
56
enum OTADownloadState: uint8_t {
53
57
OtaDownloadHeader,
54
58
OtaDownloadFile,
You can’t perform that action at this time.
0 commit comments