-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Small improvements in update example #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
copercini
commented
Aug 1, 2017
- 100ms is too low to get server response
- 100ms is too low to get server response
- 100ms is too low to get server response
I used this sample to update my ESP32 firmware, I put my bin file on my server, check contentLength, and content type and herder OK. However, it always fails after some packets, |
@huyhl248 where is that data.readBytes code? how much is _bufferLen when it fails? |
Dear @me-no-dev , size_t UpdateClass::writeStream(Stream &data) {
size_t written = 0;
size_t toRead = 0;
if(hasError() || !isRunning())
return 0;
if(!_verifyHeader(data.peek())) {
_reset();
return 0;
}
log_e("data.available() %d SPI_FLASH_SEC_SIZE %d, _bufferLen %d, _buffer %d",data.available(),SPI_FLASH_SEC_SIZE, _bufferLen, _buffer);
while(remaining()) {
toRead = data.readBytes(_buffer + _bufferLen, (SPI_FLASH_SEC_SIZE - _bufferLen));
log_e("toRead %d",toRead);
if(toRead == 0) { //Timeout
delay(100);
toRead = data.readBytes(_buffer + _bufferLen, (SPI_FLASH_SEC_SIZE - _bufferLen));
if(toRead == 0) { //Timeout
_abort(UPDATE_ERROR_STREAM);
return written;
}
}
_bufferLen += toRead;
if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer())
return written;
written += toRead;
log_e("data.available() %d SPI_FLASH_SEC_SIZE %d, _bufferLen %d, _buffer %d",data.available(),SPI_FLASH_SEC_SIZE, _bufferLen, _buffer);
//delay(1000);
}
return written;
} And here is my log:
Please advise! |
Looks like we need to do more waiting before timeout. Still strange why data slows down, but a loop to 20 that trys to read more data once Timeout is detected could do. Can you try to implement that and report? if(toRead == 0) { //Timeout
uint8_t turn = 0;
while(toRead == 0 && turn++ < 20){
delay(100);
toRead = data.readBytes(_buffer + _bufferLen, (SPI_FLASH_SEC_SIZE - _bufferLen));
log_e("toRead[%u] %d",turn,toRead);
}
if(toRead == 0) { //Timeout
_abort(UPDATE_ERROR_STREAM);
return written;
}
} |
Dear @me-no-dev ,
Updated log:
Best regards, |
please add that debug line inside the loop :) check my updated comment/code above :) so we are sure that it waits for at least 2 seconds. or better yet, add this one: if(toRead == 0) { //Timeout
uint8_t turn = 0;
uint64_t tstarted = millis();
while(toRead == 0 && turn++ < 20){
delay(100);
toRead = data.readBytes(_buffer + _bufferLen, (SPI_FLASH_SEC_SIZE - _bufferLen));
log_e("toRead[%u] %d",turn,toRead);
}
if(toRead == 0) { //Timeout
log_e("Timeout after %lu ms without data!",millis() - tstarted);
_abort(UPDATE_ERROR_STREAM);
return written;
}
} |
Updated Code:
Updated log:
|
there seems to be something wrong with your server/connection. 22 seconds without getting more data is plenty for timeout ;) |
Thanks. |
I was getting pedeoric timeouts. 100ms is too short, implementing code in this thread fixes.. Refactored the code to this
|
@tonywestonuk
|
After this error occurred, I could not restart by ESP.restart();. Why? |
Have you tried downloading the update.bin, using a browser? it does appear to be stalling halfway through. |
Whats the MTU setting on your wifi network'? - Maybe its transmitting something that the M5Stack cant cope with, but your PC can? Try reducing it! (I am clutching at straws here!)... |
Using browser ok. I reduced MTU to 1360 (minimum of my router) but no change! |
Hi, I just tried the S3 update example. the 'contentType' verification is wrong now it's: when I change it to this, it works: |