HTTP_CLIENT: - allways getting "content_length=-1" in all OTA example, and OTA_VALIDATE_FAILED at the end.

Mikhail Zarzhevskiy
Posts: 3
Joined: Sun Jan 03, 2021 8:02 pm

HTTP_CLIENT: - allways getting "content_length=-1" in all OTA example, and OTA_VALIDATE_FAILED at the end.

Postby Mikhail Zarzhevskiy » Mon Jan 04, 2021 4:12 pm

Dear colleagues,
please advice : what is wrong in my implementation - I've tried all OTA example - all with the same negativ result.
Because of the difference in a binary data length and headers of the sent and recieved files , it looks to me that I'm getting a wrong immage from server...? Being a beginner in this environment, i ask for advice how to fix this problem and make OTA to work. Other programs from ESP examples with Bluetooth and WiFi works perfect by me, but OTA ...upsets me )))

Environment:

Operating System: Windows 7pro
Using an IDE : Eclipse IDE for C/C++ : Version: 2020-09 (4.17.0); Build id: 20200910-1200
HTTP Server : OpenSSL 1.1.1i
Python 3.7.9
Git version 2.29.1.windows.1
ESP-IDF v4.1-dirty

Compil log:
=========================================
# Espressif ESP32 Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 16K,
otadata, data, ota, 0xd000, 8K,
phy_init, data, phy, 0xf000, 4K,
factory, app, factory, 0x10000, 1M,
ota_0, app, ota_0, 0x110000, 1M,
ota_1, app, ota_1, 0x210000, 1M,
========================================
On the server side:

C:\eclipse-workspace\SERVER>openssl s_server -WWW -key ca_key.pem -cert ca_cert.
pem -port 8070
Using default temp DH parameters
ACCEPT
hello_world.bin


Here is a log from serial port terminal:

.[0;32mI (7705) native_ota_example: Starting OTA example.[0m
D (7705) esp_ota_ops: found ota app max = 2.[0m
D (7715) esp_ota_ops: finding factory app....[0m
.[0;32mI (7715) native_ota_example: Running partition type 0 subtype 0 (offset 0x00010000).[0m (запуск программы в factory )

(here I connect to my server - openssl s_server -WWW -key ca_key.pem -cert ca_cert.pem -port 8070)

D (7725) HTTP_CLIENT: Begin connect to: https://192.168.8.103:8070.[0m
D (7735) esp-tls: host:192.168.8.103: strlen 13.[0m
D (7925) esp-tls: handshake in progress....[0m
D (9895) HTTP_CLIENT: Write header[3]: GET /hello_world.bin HTTP/1.1 User-Agent: ESP32 HTTP Client/1.0 Host: 192.168.8.103 Content-Length: 0 .[0m
D (9935) HTTP_CLIENT: on_message_begin.[0m
D (9935) HTTP_CLIENT: HEADER=Content-type:text/plain.[0m
D (9935) HTTP_CLIENT: http_on_headers_complete, status=200, offset=45, nread=45.[0m
D (9945) HTTP_CLIENррT: http_on_body 467.[0m
D (9945) HTTP_CLIENT: content_length = -1.[0m (!!!!??? Here starts a problem )
.[0;32mI (9955) native_ota_example: Writing to partition subtype 16 at offset 0x110000.[0m
D (9955) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (9965) HTTP_CLIENT: need_read=557, byte_to_read=512, rlen=512, ridx=467.[0m
D (9975) HTTP_CLIENT: http_on_body 512.[0m
D (9975) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (9985) HTTP_CLIENT: need_read=45, byte_to_read=45, rlen=45, ridx=979.[0m
D (9985) HTTP_CLIENT: http_on_body 45.[0m
.[0;32mI (9995) native_ota_example: New firmware version: 1.[0m
.[0;32mI (9995) native_ota_example: Running firmware version: 1.[0m
D (10005) esp_ota_ops: Invalid otadata[-1].[0m
.[0;32mI (14915) native_ota_example: esp_ota_begin succeeded.[0m
D (14925) native_ota_example: Written image length 1024.[0m
D (14925) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (14925) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (14935) HTTP_CLIENT: http_on_body 512.[0m
D (14935) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (14945) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (14955) HTTP_CLIENT: http_on_body 512.[0m
D (14975) native_ota_example: Written image length 2048.[0m
D (14975) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (14975) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (14985) HTTP_CLIENT: http_on_body 512.[0m
D (14985) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (14995) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (15005) HTTP_CLIENT: http_on_body 512.[0m
D (15025) native_ota_example: Written image length 3072.[0m
D (15025) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15025) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (15025) HTTP_CLIENT: http_on_body 512.[0m
D (15035) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15045) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (15045) HTTP_CLIENT: http_on_body 512.[0m
D (15065) native_ota_example: Written image length 4096.[0m
D (15065) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15065) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (15075) HTTP_CLIENT: http_on_body 512.[0m
D (15075) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15085) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (15095) HTTP_CLIENT: http_on_body 512.[0m
D (15115) native_ota_example: Written image length 5120.[0m
D (15115) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15115) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (15125) HTTP_CLIENT: http_on_body 512.[0m
D (15125) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15135) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (15135) HTTP_CLIENT: http_on_body 512.[0m
D (15165) native_ota_example: Written image length 6144.[0m
D (15165) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15165) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (15165) HTTP_CLIENT: http_on_body 512.[0m
D (15175) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15175) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (15185) HTTP_CLIENT: http_on_body 512.[0m
D (15205) native_ota_example: Written image length 7168.[0m
D (15205) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15205) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=512, ridx=0.[0m
D (15215) HTTP_CLIENT: http_on_body 512.[0m
D (15215) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15225) HTTP_CLIENT: need_read=512, byte_to_read=512, rlen=512, ridx=512.[0m
D (15235) HTTP_CLIENT: http_on_body 512.[0m
D (15255) native_ota_example: Written image length 8192.[0m
D (15255) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15255) HTTP_CLIENT: need_read=1024, byte_to_read=512, rlen=30, ridx=0.[0m
D (15265) HTTP_CLIENT: http_on_body 30.[0m
D (15265) HTTP_CLIENT: is_data_remain=1, is_chunked=1, content_length=-1.[0m
D (15275) HTTP_CLIENT: need_read=994, byte_to_read=512, rlen=-1, ridx=30.[0m
D (15275) HTTP_CLIENT: http_on_message_complete, parser=3ffc70d8.[0m
D (15285) HTTP_CLIENT: esp_transport_read returned:-1 and errno:128 .[0m
D (15295) native_ota_example: Written image length 8222.[0m

(But the Written image length 8222 is smaller then the lenth of hello_world.bin -144Kb)

D (15295) HTTP_CLIENT: is_data_remain=0, is_chunked=1, content_length=-1.[0m
.[0;31mE (15305) native_ota_example: Connection closed, errno = 128.[0m
.[0;32mI (15305) native_ota_example: Total Write binary data length: 8222.[0m
D (15315) esp_image: reading image header @ 0x110000.[0m
D (15325) esp_image: image header: 0xe9 0x06 0x02 0x01 40081078.[0m

(and image header differs from image header in hello_world.bin - 0xe9 0x06 0x02 0x10 78100840ee )

V (15325) esp_image: loading segment header 0 at offset 0x110018.[0m
V (15335) esp_image: segment data length 0x5558 data starts 0x110020.[0m
V (15345) esp_image: segment 0 map_segment 1 segment_data_offs 0x110020 load_addr 0x3f400020.[0m
.[0;32mI (15345) esp_image: segment 0: paddr=0x00110020 vaddr=0x3f400020 size=0x05558 ( 21848) map.[0m
D (15355) esp_image: free data page_count 0x0000003d.[0m
V (15375) esp_image: loading segment header 1 at offset 0x115578.[0m
V (15375) esp_image: segment data length 0xffffffff data starts 0x115580.[0m
.[0;31mE (15375) esp_image: invalid segment length 0xffffffff.[0m
.[0;31mE (15385) native_ota_example: Image validation failed, image is corrupted.[0m
.[0;31mE (15385) native_ota_example: esp_ota_end failed (ESP_ERR_OTA_VALIDATE_FAILED)!.[0m
.[0;31mE (15405) native_ota_example: Exiting task due to fatal error....[0m

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: HTTP_CLIENT: - allways getting "content_length=-1" in all OTA example, and OTA_VALIDATE_FAILED at the end.

Postby boarchuz » Tue Jan 05, 2021 10:02 am

Your server is using chunked encoding but it's not supported in native_ota_example.

Anannmam
Posts: 1
Joined: Tue Jan 05, 2021 8:34 pm

Re: HTTP_CLIENT: - allways getting "content_length=-1" in all OTA example, and OTA_VALIDATE_FAILED at the end.

Postby Anannmam » Tue Jan 05, 2021 8:35 pm

Cool. Thanks for the Thread

Mikhail Zarzhevskiy
Posts: 3
Joined: Sun Jan 03, 2021 8:02 pm

Re: HTTP_CLIENT: - allways getting "content_length=-1" in all OTA example, and OTA_VALIDATE_FAILED at the end.

Postby Mikhail Zarzhevskiy » Sun Jan 10, 2021 10:14 pm

boarchuz wrote:
Tue Jan 05, 2021 10:02 am
Your server is using chunked encoding but it's not supported in native_ota_example.
Thank you very mach! Your not cleared me the problem.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 123 guests