Skip to content

Commit 895f4c1

Browse files
sverreknutsenpennam
authored andcommitted
Bug fix for failed read of OTA header due to not yet recived bytes.
1 parent 370828b commit 895f4c1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Arduino_ESP32_OTA.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,25 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
182182
DEBUG_VERBOSE("%s: Length of OTA binary according to HTTP header = %d bytes", __FUNCTION__, content_length_val);
183183

184184
/* Read the OTA header ... */
185-
_client->read(_ota_header.buf, sizeof(OtaHeader));
185+
bool is_http_data_timeout = false;
186+
for(int i = 0; i < sizeof(OtaHeader) && !is_http_data_timeout; i++)
187+
{
188+
for(unsigned long const start = millis();;)
189+
{
190+
is_http_data_timeout = (millis() - start) > ARDUINO_ESP32_OTA_BINARY_BYTE_RECEIVE_TIMEOUT_ms;
191+
if (is_http_data_timeout)
192+
{
193+
DEBUG_ERROR("%s: timeout waiting data", __FUNCTION__);
194+
break;
195+
}
196+
if (_client->available())
197+
{
198+
_ota_header.buf[i] = _client->read();
199+
break;
200+
}
201+
}
202+
}
203+
//_client->read(_ota_header.buf, sizeof(OtaHeader));
186204

187205
/* ... and check first length ... */
188206
if (_ota_header.header.len != (content_length_val - sizeof(_ota_header.header.len) - sizeof(_ota_header.header.crc32))) {

0 commit comments

Comments
 (0)