基本概念
涉及的點比較多,大概羅列一下,每個點都有很多的知識點。。。
- 前端三大件(HTML+CSS+JavaScript)
- 超文本傳輸協議(HTTP,HyperText Transfer Protocol)
- 服務器端調用外部程序規範(CGI,Common Gateway Interface)
- 統一資源標識符(URI,Uniform Resource Identifier)
配置NUTTX
我使用的nuttx版本是7.26,下面直接開始配置:
!!!需要注意的是確保TCP/IP網絡協議棧已經正常運行起來了
可以嘗試PING下目標主板確認
- 配置webserver example
> Application Configuration > Examples
[*] uIP web server example
(0xc0a80a1e) Device IP //IP地址
(0xc0a80a01) Default Router IP //網關
(0xffffff00) Network Mask //子網掩碼
[*] No hardware MAC //無MAC地址,在代碼中會手動填一個
- 配置 Network Utilities
[*] uIP web server
[ ] Single Connection
-*- Disable %! scripting
(64) Maximum size of a path
[*] URL/CGI function mapping //CGI映射,處理一些GET命令的時候會有用
() Error Path
[ ] Disabled the SERVER header
(0) Receive Timeout (sec)
File Transfer Method (sendfile()) ---> //文件傳輸方法一定選sendfile,不然編寫號的html無法下發
//如果配置了File mmap-ing 一定要打開[*] File mapping emulation
(/fs/microsd/hp) Location of the files //服務的根目錄地址,根據自己掛的路徑確定
[*] Keepalive Disable
拷貝資源到根目錄下
我是掛載了一個SD卡在/fs/microsd,然後在SD卡里面建立了一個文件夾hp,所以根目錄就是/fs/microsd/sd.
文件裏面的內容如下:
!!!這個資源我是隨便在網絡上下載的HTML模板,nuttx 的webserver 對資源沒有特別的要求,不要過大就OK(名稱過長,路徑過深)
如果只是測試建議手寫一個 index.html即可
$ ll
total 68K
drwxrwxr-x 6 peng peng 4.0K 6月 6 16:17 assets
-rw-rw-r-- 1 peng peng 17K 6月 6 16:17 elements.html
-rw-rw-r-- 1 peng peng 2.7K 6月 6 16:17 generic.html
drwxrwxr-x 2 peng peng 4.0K 6月 6 16:17 images
-rw-rw-r-- 1 peng peng 9.0K 7月 24 17:39 index.html
-rw-rw-r-- 1 peng peng 17K 6月 6 16:17 LICENSE.txt
-rw-rw-r-- 1 peng peng 1.2K 6月 6 16:17 README.txt
測試
編譯過後在終端輸入一下指令:
nsh> webserver
Starting webserver
在瀏覽器地址欄中填入:
http://192.168.10.30/index.html