Page 1 of 1

esp_http_client_read with offset for advanced OTA

Posted: Thu Dec 14, 2023 7:35 am
by mbastida
Good morning,

We currently are successfully using OTA via LTE on a handful of devices pretty reliably.

However, there's something with the LTE connection (or the modem library, or our own code) that makes the connection unreliable when performing OTA.
To solve that we want to perfect the OTA system and make it multi-session. This means that if in one connection it downloads 500KB of binary and then it crashes on the next try it will start downloading from that 500KB rather than starting from zero.

Now to the technicalities (and the question): For OTA write we have

Code: Select all

esp_ota_write_offset()
. But I don't see the alternative for

Code: Select all

esp_http_client_read()
. I don't even know if it is possible on the HTTP protocol to download a file only from a certain point and not the beggining.
So, the question: Is there any function similar to

Code: Select all

esp_http_client_read_offset()
?

Re: esp_http_client_read with offset for advanced OTA

Posted: Thu Dec 14, 2023 8:49 am
by MicroController
mbastida wrote:
Thu Dec 14, 2023 7:35 am
I don't even know if it is possible on the HTTP protocol to download a file only from a certain point and not the beggining.
So, the question: Is there any function similar to

Code: Select all

esp_http_client_read_offset()
?
HTTP range requests can do this. You should be able to leverage this just by adding a "Range" header to your request.

Re: esp_http_client_read with offset for advanced OTA

Posted: Thu Dec 14, 2023 2:02 pm
by mbastida
MicroController wrote:
Thu Dec 14, 2023 8:49 am
mbastida wrote:
Thu Dec 14, 2023 7:35 am
I don't even know if it is possible on the HTTP protocol to download a file only from a certain point and not the beggining.
So, the question: Is there any function similar to

Code: Select all

esp_http_client_read_offset()
?
HTTP range requests can do this. You should be able to leverage this just by adding a "Range" header to your request.
Didn't want to change things server-side but it seems like this is the only option.

Thanks! Will try this route

Re: esp_http_client_read with offset for advanced OTA

Posted: Thu Dec 14, 2023 2:38 pm
by MicroController
Dunno which server you use, but pretty much all off-the-shelf (linux) webservers should support this out-of-the-box.

Re: esp_http_client_read with offset for advanced OTA

Posted: Fri Dec 15, 2023 1:31 pm
by leschge
You can use esp_http_client_read() for chunked download, it returns the bytes as int that have been read. With this you can continue a download after network issues have been resolved. I am not sure if extra steps need to be done on the server side.

You have to add the "Range" header using esp_http_client_set_header(httpClientHandle, "Range", your_range); according to https://developer.mozilla.org/en-US/doc ... ders/Range