Netx web server application, based on S7G2 board, using SSP2.40 library. The file transfer on the board for firmware upgrade, fails due to timeout error of the nx_web_http_server_content_get() function. The number of bytes transferred, before error, varies depending on the number of buffers in the pool. As if the buffers are not released.
Below is the example code of the request_notify() function used which, for the test, receives the data without saving them
UINT request_notify(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr) { CHAR string[50]; UINT status=0; UINT error=0; NX_PACKET *resp_packet_ptr; /* send the graphics data */ if(strcmp((const char*)resource,(const char*)"/nxlogo.gif")==0) { nx_web_http_server_callback_data_send(server_ptr, (void *)nxlogo, nxlogosize); return(NX_WEB_HTTP_CALLBACK_COMPLETED); } if(strcmp((const char*)resource,(const char*)"/txlogo.gif")==0) { nx_web_http_server_callback_data_send(server_ptr, (void *)txlogo, txlogosize); return(NX_WEB_HTTP_CALLBACK_COMPLETED); } if(strcmp((const char*)resource,(const char*)"/favicon.ico")==0) { nx_web_http_server_callback_data_send(server_ptr, (void *)favicon, faviconsize); return(NX_WEB_HTTP_CALLBACK_COMPLETED); } /* return requested resource or query */ if(strcmp((const char*)resource,(const char*)"/")==0) { ... ... return html page ... return(NX_WEB_HTTP_CALLBACK_COMPLETED); }else if(request_type == NX_WEB_HTTP_SERVER_POST_REQUEST){ if(strcmp((const char*)resource,(const char*)"/API/FILE")==0){ copiedLen = 0; receivedLen = 0; offset = 0; status = nx_web_http_server_content_length_get(packet_ptr, &contentLen); remainingLen = contentLen; receive_buffer = 0; if(!status && contentLen && ((receive_buffer = malloc(1024)) != NULL)){ while(remainingLen && (status == NX_SUCCESS)) { if((status = nx_web_http_server_content_get(server_ptr, packet_ptr, receivedLen, receive_buffer, 1024, &copiedLen)) == NX_SUCCESS) { receivedLen += copiedLen; remainingLen -= copiedLen; }else{ // timeout error free(receive_buffer); return(NX_WEB_HTTP_TIMEOUT); } } free(receive_buffer); return(NX_WEB_HTTP_CALLBACK_COMPLETED); return(NX_WEB_HTTP_CALLBACK_COMPLETED); } } } return(NX_SUCCESS); }
According to the documentation with the nx_web_http_server_content_get() function I should receive all the data, without doing anything else.
I thank anyone who can give me any suggestions, since this problem has been blocking the development of my application from quite time already.
Hi dgl,
Can you check if the discussions and sample codes in this thread helps: https://community.renesas.com/mcu-mpu/embedded-system-platform/f/forum/8083/upload-a-file-through-html?
JBIf this response, or one provided by another user, answers your question, please verify the answer. Thank you!Renesas Engineering Community Moderatorhttps://community.renesas.com/https://academy.renesas.com/https://en-support.renesas.com/knowledgeBase/
The discussions and sample code in that thread helped me. They suggested me to enable MULTIPART management (NX_WEB_HTTP_MULTIPART_ENABLE = enabled) and use the relative services, with positive results, even transferring files of a some megabytes. In my implementation I had used the nx_web_http_server_content_get() service, which doesn't work, for files larger than 10220 bytes (with the default pool of 16 buffers), perhaps because it was misused, but I didn't find any example code of request_notify() that uses it. Final question: should I always use multipart management? And when and how do you use the nx_web_http_server_content_get() service?Thanks anyway for solving my problem.
Unfortunately, by enabling TLSv1.2 I can only transfer files of around 1k in size, for larger sizes the nx_web_http_server_get_entity_header() function fails.
After some tests, I can say that, with a file size smaller than my buffer size, everything works fine. With slightly larger file sizes the nx_packet_data_extract_offset() function has problems. In fact, the bytes to be extracted exceed the size of my buffer. But, increasing the file size even more, it is the nx_web_http_server_get_entity_header() function that returns error NX_WEB_HTTP_NOT_FOUND 0x30006 /* HTTP request not found */. It seems that, with the secure connection, the server tries to buffer all the frame to be able to decrypt it and therefore with large dimensions it goes out of buffer. Sometimes it also happens to go to Default_Handler().Below, the code I refer to that disabling the secure connection works fine, even for files of a few Mbytes.
UCHAR buffer[4096]; UCHAR header_buffer[1024]; UINT status, packetLen; request_notify(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr) { UINT receivedLen, copiedLen, offset, status, packetLen; // ... // ... if(request_type == NX_WEB_HTTP_SERVER_POST_REQUEST){ receivedLen = 0; memset(header_buffer, 0, sizeof(header_buffer)); /* Process multipart data. */ if(nx_web_http_server_get_entity_header(server_ptr, &packet_ptr, header_buffer, sizeof(header_buffer)) == NX_SUCCESS) { offset=0; packetLen=0; while ((status = nx_web_http_server_get_entity_content(server_ptr, &packet_ptr, &offset, &packetLen)) == NX_SUCCESS) { memset(buffer, 0, sizeof(buffer)); status = nx_packet_data_extract_offset(packet_ptr, offset, buffer, packetLen, &copiedLen); receivedLen += copiedLen; } } } // ... // ... }
My last problem is the same as discussed in the thread: community.renesas.com/.../difference-in-packet-size-for-http-and -https-server/99684#99684not solved yet. In my case, with a pool of 64 buffers of 1568 bytes, it is possible to transfer files of about 4Mbytes.
Hey dgl! Apologies for the delay in response.A little hard to guess what could be wrong here, but could you try enabling IP fragmentation? This is something which was mentioned here in this thread: https://learn.microsoft.com/en-us/answers/questions/307872/azure-netx-maximum-recived-packet-size. Kindly give it a try and let me know if it helps or not.Regards,JayeshIf this response, or one provided by another user, answers your question, please verify the answer. Thank you!Renesas Engineering Community Moderatorshttps://community.renesas.com/https://academy.renesas.com/en-support.renesas.com/.../
In the last code reported, in case of secure connection (TLS), the reception buffer[4096] passed to the nx_packet_data_extract_offset() function must have dimensions of at least 16K.Enabling IP fragmentation does not solve the problems. The only solution to transfer large files, some Mbytes, is to sufficiently increase the number of buffers in pool0, to 64 or more, subtracting memory to the application.