@@ -82,6 +82,8 @@ int rp2040_connect_onOTARequest(char const * ota_url)
82
82
{
83
83
SFU::begin ();
84
84
85
+ remove (" /ota/UPDATE.BIN.LZSS" );
86
+
85
87
mbed_watchdog_reset ();
86
88
87
89
URI url (ota_url);
@@ -127,8 +129,13 @@ int rp2040_connect_onOTARequest(char const * ota_url)
127
129
128
130
/* Receive HTTP header. */
129
131
String http_header;
130
- for (bool is_header_complete = false ; client->connected () && !is_header_complete; )
132
+ bool is_header_complete = false ,
133
+ is_http_header_timeout = false ;
134
+ for (unsigned long const start = millis (); !is_header_complete;)
131
135
{
136
+ is_http_header_timeout = (millis () - start) > (10 *1000 );
137
+ if (is_http_header_timeout) break ;
138
+
132
139
if (client->available ())
133
140
{
134
141
mbed_watchdog_reset ();
@@ -141,6 +148,12 @@ int rp2040_connect_onOTARequest(char const * ota_url)
141
148
}
142
149
}
143
150
151
+ if (!is_header_complete) {
152
+ fclose (file);
153
+ DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
154
+ return static_cast <int >(OTAError::RP2040_HttpHeaderError);
155
+ }
156
+
144
157
/* Extract concent length from HTTP header. A typical entry looks like
145
158
* "Content-Length: 123456"
146
159
*/
@@ -161,9 +174,13 @@ int rp2040_connect_onOTARequest(char const * ota_url)
161
174
DEBUG_VERBOSE (" %s: Length of OTA binary according to HTTP header = %d bytes" , __FUNCTION__, content_length_val);
162
175
163
176
/* Receive as many bytes as are indicated by the HTTP header - or die trying. */
164
- for (int bytes_received = 0 ;
165
- (bytes_received < content_length_val) && client->connected ();)
177
+ int bytes_received = 0 ;
178
+ bool is_http_data_timeout = false ;
179
+ for (unsigned long const start = millis (); bytes_received < content_length_val;)
166
180
{
181
+ is_http_data_timeout = (millis () - start) > (60 *1000 );
182
+ if (is_http_data_timeout) break ;
183
+
167
184
if (client->available ())
168
185
{
169
186
mbed_watchdog_reset ();
@@ -181,10 +198,16 @@ int rp2040_connect_onOTARequest(char const * ota_url)
181
198
}
182
199
}
183
200
201
+ if (bytes_received != content_length_val) {
202
+ fclose (file);
203
+ DEBUG_ERROR (" %s: Error receiving HTTP data %s (%d bytes received, %d expected)" , __FUNCTION__, is_http_data_timeout ? " (timeout)" :" " , bytes_received, content_length_val);
204
+ return static_cast <int >(OTAError::RP2040_HttpDataError);
205
+ }
206
+
184
207
/* Determine length. */
185
208
int const file_len = ftell (file);
186
209
fclose (file);
187
- DEBUG_DEBUG (" %s: %d bytes received" , __FUNCTION__, file_len);
210
+ DEBUG_DEBUG (" %s: %d bytes received (%d expected) " , __FUNCTION__, file_len, content_length_val );
188
211
189
212
/* Perform the reset to reboot to SxU. */
190
213
NVIC_SystemReset ();
0 commit comments