STM32 W5500 Http Client Get Request Download Bin File Ideas and Implementation
STM32 W5500 Http Client Get Request Download Bin File Ideas and Implementation
0
Project description
Download request header information includes the following key information:
1. Request method + interface name + protocol and protocol version (GET /file/FLASH_OPER.bin_1.1.3 HTTP / 1.1 r n)
2. IP + port of file server host (example: 192.168.1.105:8888rn)
3. Connection status (Connection: Keep-Alive r n)
4. Applicant Name (User-Agent: W5500rn)
5. The encoding received by the requester (Accept-Encoding: gzip, deflate rn)
6. End of request header (rn)
The above is the analysis of the request.?The information returned by the file server is as follows:
Parsing the data returned from the file server, messages, and file content are not transmitted at once, but are transmitted multiple times continuously.
The returned message contains the following key points:
1. The status code returned (HTTP / 1.1 200 r n)
2. Receive Range Byte Stream (Accept-Ranges: bytes rn)
3. Content Length (Content: 3904rn)
4. Header tag (rn)
5. The length of the byte stream data and the length of the content are the same.
The above is based on the analysis of the file download process by the browser, then the file download process by STM32 W5500, simulating the browser file download, can theoretically be realized.
The HTTP protocol is an encapsulated protocol based on TCP.?The process of connecting the W5500 TCP client and server resume is not described here.
STM32 W5500 has several difficulties downloading files:
1. Analyze the message returned by the file server to determine if the return code is 200, only 200 represents success;?determine if it is a byte stream;?parse file size (length)
2. The byte stream of the file and the segmentation of the returned message, as well as the repeated transport of the data in the buffer array (after all, the W5500 can receive up to 2 Kbytes of data at a time).
3. The basis for judging whether the file download is complete.
STM32 W5500 request and receipt process:
That is, after sending a request message, continue to receive the information returned by the file server, the result is that the file byte stream is equal to the Content Length, the file download is successful, or various reasons fail. (connection timeout, read timeout, return Bad code, no byte stream, etc.).
Looks like I've already talked about it.?Below is the code to download files in STM32 W5500 Http GET mode (I test and download 4k/13k/67k files approx).?The log information for each branch is printed to the routine and the file is downloaded. The content is printed through the DMA serial port.?(For the project, please refer to my basic configuration article to download and then replace this main test function)
Finally, attach the representations of my test:
The number of bytes printed to the serial port is consistent with the Content-Length, and compared to the original bin file, the content is consistent.
