esp_http_client_read with offset for advanced OTA

mbastida
Posts: 7
Joined: Wed Jul 06, 2022 6:55 am

esp_http_client_read with offset for advanced OTA

Postby mbastida » Thu Dec 14, 2023 7:35 am

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()
?

MicroController
Posts: 1688
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: esp_http_client_read with offset for advanced OTA

Postby MicroController » 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.

mbastida
Posts: 7
Joined: Wed Jul 06, 2022 6:55 am

Re: esp_http_client_read with offset for advanced OTA

Postby mbastida » Thu Dec 14, 2023 2:02 pm

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

MicroController
Posts: 1688
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: esp_http_client_read with offset for advanced OTA

Postby MicroController » Thu Dec 14, 2023 2:38 pm

Dunno which server you use, but pretty much all off-the-shelf (linux) webservers should support this out-of-the-box.

leschge
Posts: 37
Joined: Fri May 06, 2022 1:38 pm

Re: esp_http_client_read with offset for advanced OTA

Postby leschge » Fri Dec 15, 2023 1:31 pm

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

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 82 guests