stm32+lwip(四):网页服务器测试
ST官方有l(wèi)wip的例程,下載地址如下:
https://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-library-expansion/stsw-stm32070.html
本文例子參考ST官方給出的例程。
一、準(zhǔn)備
ST例程文檔關(guān)于lwip的介紹如下:
?
由此可以看到LWIP有三種API,在本文中,使用Raw API。
HTTP協(xié)議是建立在TCP協(xié)議之上的一種應(yīng)用,本文用到的TCP Raw API如下:
二、移植官方例程
官方例程在stsw-stm32070\STM32F4x7_ETH_LwIP_V1.1.1\Project\Standalone\httpserver目錄下,拷貝以下文件到我們工程:
?
fs.c/h是文件的操作
fs.data.c/h存放了網(wǎng)頁(yè)的數(shù)據(jù)
httpd.c/h是網(wǎng)頁(yè)服務(wù)器
httpd_cgi_ssi.c?是cgi和ssi的處理
將httpd_cgi_ssi.c中關(guān)于硬件操作的代碼刪掉,或者找到宏LWIP_HTTPD_SSI和宏LWIP_HTTPD_CGI將SSI和CGI功能禁掉,然后在主程序中增加httpd_init()。
上電運(yùn)行后可以看到ST官方例子的網(wǎng)頁(yè):
?
三、打印網(wǎng)頁(yè)接收數(shù)據(jù)
在httpd.c中的http_recv函數(shù)中增加以下黃色部分代碼:
?
然后當(dāng)在瀏覽器打開192.168.2.8時(shí),串口輸出以下數(shù)據(jù):
get msg from 192:168:2:194 port:55329: GET / HTTP/1.1 Host: 192.168.2.8 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9get msg from 192:168:2:194 port:55330: GET /STM32F4x7_files/ST.gif HTTP/1.1 Host: 192.168.2.8 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: image/webp,image/apng,image/*,*/*;q=0.8 Referer: http://192.168.2.8/ Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9get msg from 192:168:2:194 port:55331: GET /STM32F4x7_files/stm32.jpg HTTP/1.1 Host: 192.168.2.8 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: image/webp,image/apng,image/*,*/*;q=0.8 Referer: http://192.168.2.8/ Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9get msg from 192:168:2:194 port:55332: GET /inchtml-pages-stm32_connectivity_files/pixel.gif HTTP/1.1 Host: 192.168.2.8 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: image/webp,image/apng,image/*,*/*;q=0.8 Referer: http://192.168.2.8/ Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9get msg from 192:168:2:194 port:55334: GET /favicon.ico HTTP/1.1 Host: 192.168.2.8 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: image/webp,image/apng,image/*,*/*;q=0.8 Referer: http://192.168.2.8/ Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9由此可以看出,打開了網(wǎng)頁(yè)服務(wù)器地址,會(huì)給網(wǎng)頁(yè)服務(wù)器發(fā)送GET / HTTP/1.1命令,網(wǎng)頁(yè)服務(wù)器會(huì)根據(jù)這個(gè)命令找到index.html,然后給瀏覽器返回網(wǎng)頁(yè)數(shù)據(jù)。由于網(wǎng)頁(yè)數(shù)據(jù)中又包含了一些照片資源,因此瀏覽器再給網(wǎng)頁(yè)服務(wù)器發(fā)送
GET /STM32F4x7_files/ST.gif HTTP/1.1 GET /STM32F4x7_files/stm32.jpg HTTP/1.1 GET /inchtml-pages-stm32_connectivity_files/pixel.gif HTTP/1.1 GET /favicon.ico HTTP/1.1以獲取照片資源。
四、最后
本文測(cè)試了網(wǎng)頁(yè)服務(wù)器功能,能正常打開預(yù)置網(wǎng)頁(yè),后續(xù)開發(fā)嵌入式網(wǎng)頁(yè)可以根據(jù)ST例程進(jìn)行修改,同時(shí)加上了SSI和CGI可以做到一些簡(jiǎn)單的交互。
?
github:https://github.com/54zorb/stm32-lwip
總結(jié)
以上是生活随笔為你收集整理的stm32+lwip(四):网页服务器测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python框架django的使用_Dj
- 下一篇: VS系列之【 产品密钥 – 所有版本】