Nuttx运行webserver

基本概念

涉及的点比较多,大概罗列一下,每个点都有很多的知识点。。。

  • 前端三大件(HTML+CSS+JavaScript)
  • 超文本传输协议(HTTP,HyperText Transfer Protocol)
  • 服务器端调用外部程序规范(CGI,Common Gateway Interface)
  • 统一资源标识符(URI,Uniform Resource Identifier)

配置NUTTX

我使用的nuttx版本是7.26,下面直接开始配置:
!!!需要注意的是确保TCP/IP网络协议栈已经正常运行起来了
可以尝试PING下目标主板确认

  1. 配置webserver example
> Application Configuration > Examples
 [*] uIP web server example
          (0xc0a80a1e) Device IP					//IP地址
          (0xc0a80a01) Default Router IP		    //网关
          (0xffffff00) Network Mask                 //子网掩码
          [*]   No hardware MAC 					//无MAC地址,在代码中会手动填一个
  1. 配置 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

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章