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_RAWconst 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_RAWprintf("tag = %s\r\n", tag);
#elseprintf("tag = %d\r\n", tag);
#endifprintf("insertLen = %d\r\n", iInsertLen);printf("insertText = %s\r\n", pcInsert);return 0;
}
#endifstatic 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_CGIhttp_set_cgi_handlers(g_cgiHandlers, LWIP_ARRAYSIZE(g_cgiHandlers));
#endif#ifdef LWIP_HTTPD_SSIhttp_set_ssi_handler(FooSsiHandler, NULL, 0);
#endifhttpd_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进行烧录。

访问网页

串口输出

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Apache Doris:下一代实时数据仓库

Apache Doris&#xff1a;下一代实时数据仓库 概念架构设计快速的原因——其性能的架构设计、特性和机制基于成本的优化器面向列的数据库的快速点查询数据摄取数据更新服务可用性和数据可靠性跨集群复制多租户管理便于使用半结构化数据分析据仓一体分层存储 词条诞生技术概述适…

谷粒商城学习笔记-23-分布式组件-SpringCloud Alibaba-Nacos配置中心-简单示例

之前已经学习了使用Nacos作为注册中心&#xff0c;这一节学习Nacos另外一个核心功能&#xff1a;配置中心。 一&#xff0c;Nacos配置中心简介 Nacos是一个易于使用的平台&#xff0c;用于动态服务发现和配置管理。作为配置中心&#xff0c;Nacos提供了以下核心功能和优势&am…

集成运算放大器的内部电路结构

原文出自微信公众号【小小的电子之路】 在集成电路问世之前&#xff0c;放大电路都是由晶体管、二极管、电阻、电容等分立元件组成&#xff0c;称为晶体管放大电路&#xff0c;但是复杂的计算限制了这类电路的推广。随着集成电路行业的发展&#xff0c;晶体管放大电路被制作在半…

Vue3 前置知识

1. Vue3 简介 2020年9月18日&#xff0c;Vue.js发布版3.8版本&#xff0c;代号&#xff1a;one Piece(海贼王)经历了&#xff1a;4800次提交、40个RFC、600次PR、300贡献者官方发版地址&#xff1a;Release v3.0.0 One Piecevuejs/,core截止2023年10月&#xff0c;最新的公开版…

Python爬虫速成之路(3):下载图片

hello hello~ &#xff0c;这里是绝命Coding——老白~&#x1f496;&#x1f496; &#xff0c;欢迎大家点赞&#x1f973;&#x1f973;关注&#x1f4a5;&#x1f4a5;收藏&#x1f339;&#x1f339;&#x1f339; &#x1f4a5;个人主页&#xff1a;绝命Coding-CSDN博客 &a…

开源AI生成连续一致性儿童故事书; GraphRAG结合本地版Ollama;AI辅助老年人用餐;开源无代码AI工作流VectorVein

✨ 1: SEED-Story SEED-Story 是一种能生成包含一致性图像的多模态长篇故事的机器学习模型&#xff0c;配套数据集已开放。 SEED-Story 是一种多模态长故事生成模型&#xff0c;具备生成包含丰富且连贯的叙事文本和一致性高的人物和风格图像的能力。此模型基于 SEED-X 构建。…

论文阅读【时空+大模型】ST-LLM(MDM2024)

论文阅读【时空大模型】ST-LLM&#xff08;MDM2024&#xff09; 论文链接&#xff1a;Spatial-Temporal Large Language Model for Traffic Prediction 代码仓库&#xff1a;https://github.com/ChenxiLiu-HNU/ST-LLM 发表于MDM2024&#xff08;Mobile Data Management&#xf…

PGCCC|【PostgreSQL】PCP认证考试大纲#postgresql 认证

PostgreSQL Certified Professional PCP&#xff08;中级&#xff09; PCP目前在市场上非常紧缺&#xff0c;除了具备夯实的理论基础以外&#xff0c;要有很强的动手能力&#xff0c;获得“PCP&#xff08;中心&#xff09;“的学员&#xff0c;将能够进入企业的生产系统进行运…

c#中的特性

在C#中&#xff0c;特性&#xff08;Attributes&#xff09;是一种向程序元素&#xff08;如类、方法、属性等&#xff09;添加元数据的方式。特性可以用来提供关于程序元素的附加信息&#xff0c;这些信息可以在编译时和运行时被访问。 特性主要有以下几个用途&#xff1a; 提…

《C专家编程》 C++

抽象 就是观察一群数据&#xff0c;忽略不重要的区别&#xff0c;只记录关注的事务特征的关键数据项。比如有一群学生&#xff0c;关键数据项就是学号&#xff0c;身份证号&#xff0c;姓名等。 class student {int stu_num;int id_num;char name[10]; } 访问控制 this关键字…

DDColor - 黑白老照片一键AI上色工具,找回“失色“的记忆,老照片一键“回春” 本地一键整合包下载

DDColor 是一个由阿里达摩院研究的基于深度学习技术的图像上色模型&#xff0c;主要用于黑白照片的修复和上色。它能够自动将黑白或灰度图像着色&#xff0c;使图像更加生动逼真。 该模型采用了先进的神经网络架构和训练技术&#xff0c;能够识别图像中的物体和场景&#xf…

[MySQL][表的约束][二][主键][自增长][唯一键][外键]详细讲解

目录 1.主键2.自增长1.是什么&#xff1f;2.索引 3.唯一键4.外键1.为什么&#xff1f;2.是什么&#xff1f;3.如何理解外键约束&#xff1f; 5.综合案例 -- 阅读 1.主键 主键&#xff1a;primary key用来唯一的约束该字段里面的数据&#xff0c;不能重复&#xff0c;不能为空&a…

vscode编译环境配置-golang

1. 支持跳转 如果单测函数上方不显示run test | debug test&#xff0c;需要安装Code Debugger&#xff08;因为以前的go Test Explorer不再被维护了&#xff09; 2. 单测 指定单个用例测试 go test -v run TestXXXdlv 调试 需要安装匹配的go版本和delve版本&#xff08;如…

AirSim环境配置

AirSim简介 AirSim 是一款基于游戏引擎的开源跨平台仿真器,它可以用于无人机、无人车等机器人的物理和视觉仿真。它同时支持基于 PX4 和 ArduPilot 等飞行控制器的软件在环仿真,目前还支持基于PX4的硬件在环仿真。AirSim 是作为虚幻游戏引擎的插件而存在的,适配基于虚幻引擎…

负载均衡-轮询-两种简易实现

1、描述 下游可用的服务器目前有5个&#xff08;node&#xff09;&#xff0c;设计一个方法&#xff0c;方法没有任何参数&#xff0c;采用轮询的方式返回其中一个node&#xff1b; 2、使用环形链表 每次取下一个node即可。注意&#xff1a;需要保证线程安全&#xff01; // …

子数组问题

目录 最大子数组和 环形子数组的最大和 乘积最大子数组 乘数为正数的最长子数组长度 等差数列划分 最长湍流子数组 单词拆分 环绕字符串中唯一的子字符串 声明&#xff1a;接下来主要使用动态规划来解决问题&#xff01;&#xff01;&#xff01; 最大子数组和 题目 …

C 语言指针进阶

1.0 指针的定义 指针是内存中一个最小单元的编号&#xff08;内存单元的编号称之为地址【地址就是指针指针就是地址】&#xff09;指针通常是用来存放内存地址的一个变量。本质上指针就是地址&#xff1a;口语上说的指针起始是指针变量&#xff0c;指针变量就是一个变量&#…

ROS2从入门到精通5-1:详解代价地图与costmap插件编写(以距离场ESDF为例)

目录 0 专栏介绍1 代价地图介绍1.1 基本概念1.2 代价定义 2 代价地图配置2.1 通用配置2.2 障碍层配置2.3 静态层配置2.4 膨胀层配置 3 代价地图插件案例3.1 构造地图插件类3.2 注册并导出插件3.3 编译与使用插件 0 专栏介绍 本专栏旨在通过对ROS2的系统学习&#xff0c;掌握RO…

GIT使用_提交IDEA代码到GIT分支上

以下是本人常用的GIT提交与上传代码&#xff0c;请选择适配自己的方式&#xff0c;仅供参考。 第一步&#xff0c;一般来说&#xff0c;我们从GIT上拉下来项目分支代码后&#xff0c;做些修改什么的&#xff0c;相关的代码都会变色。当然我们提交的部分就是我们修改的部分。有的…

算法思想总结:字符串

一、最长公共前缀 . - 力扣&#xff08;LeetCode&#xff09; 思路1&#xff1a;两两比较 时间复杂度mn 实现findcomon返回两两比较后的公共前缀 class Solution { public:string longestCommonPrefix(vector<string>& strs) {//两两比较 string retstrs[0];size…