Hi3861 OpenHarmony嵌入式应用入门--HTTPD

httpd 是 Apache HTTP Server 的守护进程名称,Apache HTTP Server 是一种广泛使用的开源网页服务器软件。

本项目是从LwIP中抽取的HTTP服务器代码;

`Hi3861 SDK`中已经包含了一份预编译的lwip,但没有开启HTTP服务器功能(静态库无法修改);

HTTP 服务器特性

目前已测试通过的功能有:

  1. 通过HTTP访问静态资源文件
  2. 通过cgi回调函数处理表单和页面跳转

静态资源文件:

  • 本服务器实现不支持实际的服务端本地文件系统访问;
  • 取而代之的是,一种简单的虚拟文件系统:
    • \\third_party\httpd\src\http\fs.c 文件提供了一套文件系统接口,使用数组直接存储文件数据
    • \\third_party\httpd\src\http\fsdata.c文件是由 makefsdata命令生成的虚拟文件系统元数据文件
    • makefsdata 命令行工具,用于将一个目录下的静态资源文件转换为 fsdata.c文件

代码编写

修改D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 

import("//build/lite/config/component/lite_component.gni")

lite_component("demo") {
  features = [
    #"base_00_helloworld:base_helloworld_example",
    #"base_01_led:base_led_example",
    #"base_02_loopkey:base_loopkey_example",
    #"base_03_irqkey:base_irqkey_example",
    #"base_04_adc:base_adc_example",
    #"base_05_pwm:base_pwm_example",
    #"base_06_ssd1306:base_ssd1306_example",
    #"kernel_01_task:kernel_task_example",
    #"kernel_02_timer:kernel_timer_example",
    #"kernel_03_event:kernel_event_example",
    #"kernel_04_mutex:kernel_mutex_example",
    #"kernel_05_semaphore_as_mutex:kernel_semaphore_as_mutex_example",
    #"kernel_06_semaphore_for_sync:kernel_semaphore_for_sync_example",
    #"kernel_07_semaphore_for_count:kernel_semaphore_for_count_example",
    #"kernel_08_message_queue:kernel_message_queue_example",
    #"wifi_09_hotspot:wifi_hotspot_example",
    #"wifi_10_sta:wifi_sta_example",
    #"tcp_11_server:tcp_server_example",
    #"tcp_12_client:tcp_client_example",
    #"udp_13_server:udp_server_example",
    #"udp_14_client:udp_client_example",
    #"network_15_mqtt:network_mqtt_example",
    #"network_16_sntp:network_sntp_example",
    "network_17_httpd:network_httpd_example",
  ]
}

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\network_17_httpd文件夹

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\network_17_httpd\BUILD.gn文件

# Copyright (c) 2020, HiHope Community.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

static_library("network_httpd_example") {
    sources = [
        "network_httpd_example.c",
        "wifi_connecter.c",


        "//third_party/httpd/src/core/altcp.c",
        "//third_party/httpd/src/core/altcp_tcp.c",
        "//third_party/httpd/src/http/fs.c",
        "//third_party/httpd/src/http/httpd.c",
        "//third_party/httpd/src/tcp_port.c",
        # "//third_party/httpd/src/pbuf_port.c",
    ]

    defines = [
        "LWIP_DEBUG",
        "HTTPD_DEBUG=0xA0",
        "LWIP_DBG_TYPES_ON=LWIP_DBG_ON",
        "LWIP_HTTPD_SSI"
    ]

    include_dirs = [
        "//third_party/httpd/include",
        "//third_party/httpd/include/lwip/apps",
        "//foundation/communication/wifi_lite/interfaces/wifiservice",
        "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include/",
    ]
}

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\network_17_httpd\wifi_connecter.h文件,该头文件包含wifi连接的宏。文件同network_16_sntp\wifi_connecter.h

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\network_17_httpd\wifi_connecter.c文件,文件同network_16_sntp\wifi_connecter.c

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\network_17_httpd\network_httpd_example.c文件

/*
 * Copyright (c) 2020, HiHope Community.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
// #include "wifiiot_at.h"

#include "httpd.h"
#include "wifi_connecter.h"

static int g_netId = -1;
#define STACK_SIZE  (4096)

#ifdef LWIP_HTTPD_CGI
const char *HelloHandler(int iIndex, int nParams, char *pcParam[], char *pcValue[])
{
    printf("HelloHandler\r\n");
    printf("iIndex = %d\r\n", iIndex);
    for (int i = 0; i < nParams; i++) {
        printf("pcParam[%d] = '%s'\r\n", i, pcParam[i]);
        printf("pcValue[%d] = '%s'\r\n", i, pcValue[i]);
    }
    return "/index.html"; // forward to home page.
}

static tCGI g_cgiHandlers[] = {
    { "/hello", HelloHandler },
};
#endif

#if LWIP_HTTPD_SSI
u16_t FooSsiHandler(
#if LWIP_HTTPD_SSI_RAW
    const char* tag,
#else /* LWIP_HTTPD_SSI_RAW */
    int tag,
#endif /* LWIP_HTTPD_SSI_RAW */
    char *pcInsert, int iInsertLen
#if LWIP_HTTPD_SSI_MULTIPART
    , u16_t currentTagPart, u16_t *nextTagPart
#endif /* LWIP_HTTPD_SSI_MULTIPART */
#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
    , void *connectionState
#endif /* LWIP_HTTPD_FILE_STATE */
)
{
    printf("FooSsiHandler\r\n");

#if LWIP_HTTPD_SSI_RAW
    printf("tag = %s\r\n", tag);
#else
    printf("tag = %d\r\n", tag);
#endif
    printf("insertLen = %d\r\n", iInsertLen);
    printf("insertText = %s\r\n", pcInsert);
    return 0;
}
#endif

static void HttpdTask(void)
{
    WifiDeviceConfig config = {0};

    // 准备AP的配置参数
    // strcpy(config.ssid, PARAM_HOTSPOT_SSID);
    // strcpy(config.preSharedKey, PARAM_HOTSPOT_PSK);
    strcpy_s(config.ssid, WIFI_MAX_SSID_LEN, PARAM_HOTSPOT_SSID);
    strcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, PARAM_HOTSPOT_PSK);
    config.securityType = PARAM_HOTSPOT_TYPE;

    g_netId = ConnectToHotspot(&config);
    printf("netId = %d\r\n", g_netId);

#ifdef LWIP_HTTPD_CGI
    http_set_cgi_handlers(g_cgiHandlers, LWIP_ARRAYSIZE(g_cgiHandlers));
#endif

#ifdef LWIP_HTTPD_SSI
    http_set_ssi_handler(FooSsiHandler, NULL, 0);
#endif

    httpd_init();
}

static void HttpdEntry(void)
{
    osThreadAttr_t attr = {0};

    attr.name = "HttpdTask";
    attr.stack_size = STACK_SIZE;
    attr.priority = osPriorityNormal;

    if (osThreadNew(HttpdTask, NULL, &attr) == NULL) {
        printf("[HttpdEntry] create HttpdTask failed!\n");
    }
}
SYS_RUN(HttpdEntry);

使用build,编译成功后,使用upload进行烧录。

访问网页

串口输出

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/797764.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

visual studio开发C++项目遇到的坑

文章目录 1.安装的时候&#xff0c;顺手安装了C模板&#xff0c;导致新建项目执行出问题2.生成的exe&#xff0c;打开闪退问题3.项目里宏的路径不对&#xff0c;导致后面编译没有输出4. vs编译ui&#xff0c;warning跳过&#xff0c;未成功5.vs编译.h&#xff0c;warning跳过&a…

javaweb学习day5--《HTML篇》Springboot的模块创建、HTML的相关知识点详解

一、前言 从今天开始&#xff0c;就要启动后端的学习了&#xff0c;Springboot会贯穿到底&#xff0c;一定要跟着小编严谨的去搭建Springboot环境&#xff0c;依赖添加的过程可能需要2分钟左右&#xff0c;读者们要耐心等待一下&#xff0c;搭建好Springboot之后才算正式的开始…

Unity3D 转换微信小游戏指引 03 微信SDK

Unity3D 转换微信小游戏指引系列&#xff08;第三期&#xff09; 微信SDK 初始化 首先&#xff0c;进行 SDK 初始化&#xff0c;需要引用命名空间 using WeChatWASM&#xff0c;调用 WX.InitSDK&#xff0c;在回调函数中进行游戏主逻辑的初始化。 using System.Collections…

0708,LINUX目录相关操作 + LINUX全导图

主要是冷气太足感冒了&#xff0c;加上少吃药抗药性差&#xff0c;全天昏迷&#xff0c;学傻了学傻了 01&#xff1a;简介 02&#xff1a; VIM编辑器 04&#xff1a;目录 05&#xff1a;文件 03&#xff1a;常用命令 06&#xff1a;进程 07&#xff1a;进程间的通信 cat t_c…

Keil出现警告:warning: #223-D: function “XXX“ declared implicitly

1、警告 \SYSTEMwarning: #223-D: function “FLASH_SetLatency” declared implicitly 2、原因 文件涉及调用stm32f10x_flash.h里的函数&#xff0c;但文件没有包含stm32f10x_flash.h 3、解决 1、点击魔法棒-》c/c》include paths-》包含头文件所在路径 2、直接在报错的文…

LeetCode 441, 57, 79

目录 441. 排列硬币题目链接标签思路代码 57. 插入区间题目链接标签思路两个区间的情况对每个区间的处理最终的处理 代码 79. 单词搜索题目链接标签原理思路代码 优化思路代码 441. 排列硬币 题目链接 441. 排列硬币 标签 数学 二分查找 思路 由于本题所返回的 答案在区间…

Qt中https的使用,报错TLS initialization failed和不能打开ssl.lib问题解决

前言 在现代应用程序中&#xff0c;安全地传输数据变得越来越重要。Qt提供了一套完整的网络API来支持HTTP和HTTPS通信。然而&#xff0c;在实际开发过程中&#xff0c;开发者可能会遇到SSL相关的错误&#xff0c;例如“TLS initialization failed”&#xff0c;cantt open ssl…

春招冲刺百题计划|双指针

Java基础复习 Java数组的声明与初始化Java ArrayListJava HashMapJava String 类Java LinkedListJava Deque继承LinkedListJava SetJava 队列优先队列:第二题用到了Java数组划分Java数组转ArrayListString 转数字String 这一部分&#xff0c;代码随想录写得超级好&#xff01…

LabVIEW阀门运动PCT测试

开发了一套基于LabVIEW的阀门运动PCT&#xff08;Pressure-Composition-Temperature&#xff09;测试方法。该系统通过控制阀门运动&#xff0c;实现对氢气吸附和解吸过程的精确测量和控制。所用硬件包括NI cDAQ-9174数据采集模块、Omega PX309压力传感器、SMC ITV2030电动调节…

【java算法专场】滑动窗口(下)

目录 水果成篮 算法分析 算法步骤 示例 算法代码 找到字符串中所有字母异位词 算法分析 算法步骤 示例 算法代码 优化 算法代码 串联所有单词的子串 算法分析 算法步骤 示例 算法代码 最小覆盖子串 算法分析 算法步骤 示例 算法代码 算法分析 这道题其实…

Python数据分析案例52——基于SSA-LSTM的风速预测(麻雀优化)

案例背景 又要开始更新时间序列水论文的系列的方法了&#xff0c;前面基于各种不同神经网络层&#xff0c;还有注意力机制做了一些缝合模型。 其实论文里面用的多的可能是优化算法和模态分解&#xff0c;这两个我还没出专门的例子&#xff0c;这几天正好出一个优化算法的例子来…

go-高效处理应用程序数据

一、背景 大型的应用程序为了后期的排障、运营等&#xff0c;会将一些请求、日志、性能指标等数据保存到存储系统中。为了满足这些需求&#xff0c;我们需要进行数据采集&#xff0c;将数据高效的传输到存储系统 二、问题 采集服务仅仅针对某个需求开发&#xff0c;需要修改…

树莓派pico入坑笔记,esp01/01s使用

目录 关于树莓派pico和circuitpython的更多玩法&#xff0c;请看树莓派pico专栏 说明 关于at指令 WiFi的at指令 UDP的at指令 样例程序 调试助手端输入指令 sta端程序 效果 进阶使用 库函数说明 样例代码 关于树莓派pico和circuitpython的更多玩法&#xff0c;请看树…

TensorFlow系列:第四讲:MobileNetV2实战

一. 加载数据集 编写工具类&#xff0c;实现数据集的加载 import keras""" 加载数据集工具类 """class DatasetLoader:def __init__(self, path_url, image_size(224, 224), batch_size32, class_modecategorical):self.path_url path_urlself…

H5的Canvas如何画N叉树数据结构

大家好。我是猿码叔叔&#xff0c;一位有着 5 年Java工作经验的北漂&#xff0c;业余时间喜欢瞎捣鼓&#xff0c;学习一些新东西来丰富自己。看过上一篇 Java 方法调用关系的老铁们&#xff0c;也许遗留了不少疑问&#xff0c;这Java方法调用关系可视化页面就这&#xff1f;这方…

护网HW面试——redis利用方式即复现

参考&#xff1a;https://xz.aliyun.com/t/13071 面试中经常会问到ssrf的打法&#xff0c;讲到ssrf那么就会讲到配合打内网的redis&#xff0c;本篇就介绍redis的打法。 未授权 原理&#xff1a; Redis默认情况下&#xff0c;会绑定在0.0.0.0:6379&#xff0c;如果没有采用相关…

基于SpringBoot的校园志愿者管理系统

你好呀&#xff0c;我是计算机学姐码农小野&#xff01;如果有相关需求&#xff0c;可以私信联系我。 开发语言&#xff1a;Java 数据库&#xff1a;MySQL 技术&#xff1a;SpringBoot框架 工具&#xff1a;MyEclipse、Tomcat 系统展示 首页 个人中心 志愿者管理 活动信息…

黑马头条微服务学习day01-环境搭建、SpringCloud微服务(注册发现、网关)

文章目录 项目介绍环境搭建项目背景业务功能技术栈说明 nacos服务器环境准备nacos安装 初始工程搭建环境准备主体结构 app登录需求分析表结构分析手动加密微服务搭建接口定义功能实现登录功能实现 Swagger使用app端网关nginx配置 项目介绍 环境搭建 项目背景 业务功能 技术栈说…

数据结构(Java):树二叉树

目录 1、树型结构 1.1 树的概念 1.2 如何判断树与非树 1.3 树的相关概念 1.4 树的表示形式 1.4.1 孩子兄弟表示法 2、二叉树 2.1 二叉树的概念 2.2 特殊的二叉树 2.3 二叉树的性质 2.4 二叉树的存储 2.5 二叉树的遍历 1、树型结构 1.1 树的概念 树型结构是一种非线…