Skip to main content
Visitor II
June 30, 2023
Solved

AzureRTOS + HTTP WebServer and MULTIPART transfer

  • June 30, 2023
  • 1 reply
  • 1572 views

Hi All,

I've succesfully implemented an HTTP WebServer into our application running AzureRTOS on a STM32F429.
I'm now moving to data transfer over HTTP, in order to have a Web page (entry point) for transfering a binary file (encrypted) to remote update the board on the field.
The flow is something as follow:
Web Page -> load file (encrypted) -> save file payload in binary on ext flash (in raw, no FS).
Then issue a reboot (bootlaoder will read the file & calculate the crc) and then flash the MCU if everything match.

In order to transfer correctly the file i had to enable NX_HTTP_MULTIPART_ENABLE , but i was wondering if there's a good point to start with some example (docs are not so exaustive).

Right now for receving the file i do :

 

UCHAR buffer[1440] = { 0 }; 
if ( strcmp(resource, "/upload.php") == 0 && request_type == NX_WEB_HTTP_SERVER_POST_REQUEST )
 {
 ULONG len = 0;
 ULONG offset = 0;

 fwu_start();

 while( nx_web_http_server_get_entity_header(server_ptr,&packet_ptr, buffer, sizeof(buffer)) == NX_SUCCESS )
 {
 while( nx_web_http_server_get_entity_content(server_ptr, &packet_ptr, &offset,&len) == NX_SUCCESS )
 {
 nx_packet_data_extract_offset(packet_ptr,offset, buffer, len, &len);
 buffer[len] = 0;
 fwu_raw_write((uint8_t*)buffer, (size_t)len);
 }
 }

 nx_web_http_server_type_get(server_ptr, server_ptr -> nx_web_http_server_request_resource, temp_string, &string_length);
 status = nx_web_http_server_callback_generate_response_header(server_ptr, &resp_packet_ptr, NX_WEB_HTTP_STATUS_OK,
 0, "", NX_NULL); 
 if(status == NX_SUCCESS)
 {
 status =nx_web_http_server_callback_packet_send(server_ptr, resp_packet_ptr);
 if(status != NX_SUCCESS)
 {
 nx_packet_release(resp_packet_ptr);
 return status;
 }
 
 }
 else
 {
 return NX_SUCCESS;
 }
 }

 

Is there any better way to do that? is that the right way?

 

Thanks all in advance

 

Davide

    This topic has been closed for replies.
    Best answer by Davide Dalfra

    For those who will fall into this post looking for a solution, i can confirm the one i posted here is working.
    Spent few days across MS documentation and example, fixed some stuff at my side too but that's working correctly.

    Thanks

    Davide

    1 reply

    Davide DalfraAuthorAnswer
    Visitor II
    July 9, 2023

    For those who will fall into this post looking for a solution, i can confirm the one i posted here is working.
    Spent few days across MS documentation and example, fixed some stuff at my side too but that's working correctly.

    Thanks

    Davide