嵌入式web boa移植总结

Boa 移植说明

  1. 官方下载:Boa Webserver
  2. ./configure ;或者直接修改 ./configure --host=arm-linux CC=arm-linux-gnueabihf-gcc
  3. 更改Makefile的gcc编译连接为arm-linux-gnueabihf-gcc,更改defines.h中SERVER_ROOT 为开发板指定目录(关联查找boa.conf);
  4. 然后 make并修复编译报错;
  5. copy系统文件/etc/mine.types(关联解析html) 、压缩包里/example/boa.conf(联网配置)、/src/boa(编译后执行文件) 进开发板指定目录;// 建议放入/usr/local
  6. 修改boa.conf内的ServerName为本机IP,MimeTypes路径"默认/etc/",DocumentRoot路径"默认/var/www"。其他为默认配置;
  7. 通过上述交叉编译链编译cgi文件: arm-linux-gnueabihf-gcc -o test.cgi test.c;//cgi包括post和get两个method,分别对应上传与下载数据内容
  8. 书写test.html文件,cgi文件与html文件均放入上述指定目录下;//需要专业前端人员来写最好
  9. 保证PC与板子在同一网段直连,输入ipxxx/test.html,可以看到hello word;
  10. 执行脚本放入/etc/init.d下实现开机自启动
  11. 后续建议与网页交互通过json的形式,上载文件以及下发参数用json标准化,源码使用github上的cjson.c与cjson.h,路径:https://github.com/DaveGamble/cJSON,json的解析与应用可自行百度学习
  12. 在CGI响应执行一些linux系统命令system()时,务必加上路径/sbin/

CGI例程:同时处理上载与下载数据

int main(void)
{
    tagHardware_Info tHardware_Info;
    char *method=NULL;
    char buff[MAX_BUFF_LEN]={0};// WATCH OUT  MAX 500BYTE
    int file_size=0;
    int len=0;
    int ret=0;
    char cmdip[40]={0};

    fprintf(stdout, "Content-Type: application/json\r\n");
    fprintf(stdout, "Access-Control-Allow-Origin:*\r\n\r\n");
    
    method = getenv("REQUEST_METHOD");
    if(!memcmp(method,"POST",4))//IN
    {
        fscanf(stdin, "%s",buff);

        memset(&tHardware_Info, 0, sizeof(tagHardware_Info));
        if(json_hardware_process(buff, &tHardware_Info))
        {
            fprintf(stdout,"{json Hardware Process Error!}\n");
            return -1;
        }

        if(write_hardwate_file(&tHardware_Info))
        {
            fprintf(stdout,"{json Write Hardware File Error!}\n");
            return -1;
        }
        
        if(write_boa_file(&tHardware_Info))
        {
            fprintf(stdout, "{Write BOA File Error!}\n");
            return -1;
        }

        len=strlen((char *)tHardware_Info.cIp)+20;
        ret=snprintf(cmdip,len+1,"/sbin/ifconfig eth0 %s",tHardware_Info.cIp);
        if(ret!=len)
        {
            fprintf(stdout, "ip cmd snprintf fail, ret:%d,len:%d \n",ret,len);
            return -1;
        }
        system(cmdip);
    
        fprintf(stdout, "{Set Success!}\n");
        
    }
    else if(!memcmp(method,"GET",3))//OUT
    {

        file_size=Get_File_Size(HARD_CFG_PATH);
        if((file_size<=0)||(file_size>=MAX_BUFF_LEN))
        {
            fprintf(stdout, "File Read Error!\n");
            return -1;
        }

        if(File_Read(HARD_CFG_PATH, buff, file_size))
        {
            fprintf(stdout, "File Read Error!\n");
            return -1;
        }
        
        fprintf(stdout, "%s\n",buff);
    }
    else
    {
        fprintf(stdout,"System Error!!!method = %s\n",method);
    }

    return 0;
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
嵌入式web服务器boa框架的基础上, 使用C语言cgi, 或者Python脚本, 结合HTML + javascript + ajax 的嵌入式web系统的开发实例 html 中使用javascritp + ajax 从C语言生成的cgi文件的get, set 一些值. boa服务器的相关配置参数说明: http://www.cnblogs.com/liuweiqiang/p/3859130.html boa安装包文件名: boa-for-hi3516a.tar.gz boa.conf 文件的保存路径: cat /etc/boa/boa.conf boa可 执行文件的路径: /usr/local/bin/boa, 可以设置为: 系统启动的时候, 这个进程自动启动 boa.conf 文件的重要参数 保存html文件的目录 DocumentRoot /www 可以将这个目录, 设置为samb共享文件夹的目录, 方便修改调试 修改完成以后, 肯定要重启boa进程的 保存python脚本, 或者C语言cgi文件的目录 ScriptAlias /cgi-bin/ /var/www/cgi-bin/ 说明: cgi-bin/ 后面的斜杠, 一定要加上 可以将这个目录, 设置为samb共享文件夹的目录, 方便修改调试 修改完成以后, 肯定要重启boa进程的 html文件文件中, 调用python脚本的时候, 指定的路径, 需要有: /cgi-bin, 比如: var url = "/cgi-bin/getuser.py"; 这个是python 或者 var url = "/cgi-bin/output.cgi"; 这个是C语言 说明: 如果发现, html文件, 修改了, 可是在浏览器中, 查看html源代码的时候, 这个代码, 还是旧的, 那么可以通过清空"IE浏览器", "360浏览器"的浏览记录 以上, javascript 可以调用python 同样, 也可以调用C语言生成的cgi文件(其实, 就是可执行文件) C语言 + Html 例子 C语言 CGI实例 http://blog.csdn.net/ajrm0925/article/details/8810342 http://blog.csdn.net/liang890319/article/details/6277900 http://blog.csdn.net/gnefniu/article/details/42432657 上传文件: http://blog.csdn.net/yu_xiang/article/details/7996670 查找文件 find . -type f -name "boa.conf" -print -mount find . -type f -name "boa" -print -mount 四、嵌入式web服务器boa的配置和使用 嵌入式web服务器boa的配置文件为boa.conf, 在boa-0.94.13目录下面,复制该文件到文件 系统的/etc/boa目录下面,打开boa.conf,修改为如下内容: Port 80 User root Group root ErrorLog /dev/console AccessLog /dev/null ServerName SoftEmbed.com DocumentRoot /www DirectoryIndex index.html KeepAliveMax 1000 KeepAliveTimeout 10 MimeTypes /etc/mime.types DefaultType text/plain CGIPath /bin:/usr/bin:/usr/local/bin ScriptAlias /cgi-bin/ /www/cgi-bin/ 几个重要配置参数如下: DocumentRoot: 存放html文档的主目录; DirectoryIndex: 默认返回的html文档; ScriptAlias:cgi脚本虚拟路径对应的实际路径,/www/cgi-bin/为cgi脚本存放的实际路径; 其他配置选项的意义请参考相关资料。 复制boa可执行文件到/usr/sbin目录中, 启动boa进程 重新制作文件系统,系统启动后,在客户端浏览器上输入开发板的ip 地址,例如: http://192.168.0.218, 就可以看到显示的测试网页了,如下图所示 CGI getenv函数的参数详解: http://www.cnblogs.com/ser0632/p/5498228.html s = getenv("环境变量名"); 取得环境变量内容 putenv改变或增加环境变量 int putenv(const char * string); setenv(改变或增加环境变量) http://www.jb51.net/article/71940.htm
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值