这个 WiFiWebServer_RTL8720 库是一个简单但完整的 WebServer 库,适用于Realtek RTL8720DN、RTL8722DM 和 RTL8722CSM 板。
这些功能与ESP32 WebServer
和ESP8266WebServer
库的功能相似且兼容,使从 ESP8266/ESP32 移植草图变得更加容易。
WiFiWebServer_RTL8720 库还提供高级HTTP 和 WebSocket 客户端,其功能与ArduinoHttpClient 库类似且兼容
该图书馆提供以下支持:
它基于并修改自:
WiFiWebServer_RTL8720.h
标头中的WiFiWebServer
类是一个简单的 Web 服务器,它知道如何处理 GET 和 POST 等 HTTP 请求,并且一次只能支持一个客户端。
该WiFiWebServer_RTL8720 库当前支持以下板:
Arduino IDE 1.8.19+
。Arduino AmebaD core 3.1.4+
。Functional-Vlpp library v1.0.2+
使用服务器的 lambda 函数。要安装。查看最好、最简单的方法是使用Arduino Library Manager
。搜索WiFiWebServer_RTL8720 ,然后选择/安装最新版本。您还可以使用此链接获取更详细的说明。
WiFiWebServer_RTL8720-main.zip
。WiFiWebServer_RTL8720-main
目录WiFiWebServer_RTL8720-main
文件夹复制到 Arduino 库目录,例如~/Arduino/libraries/
。为了避免与 PROGMEM 相关的编译错误,您必须将文件 Realtek AmebaD core pgmspace.h 复制到 Realtek AmebaD 目录(~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace)。 h)。
假设Realtek AmebaD核心版本是3.1.4。必须将此文件复制到目录中:
~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h
每当安装新版本时,请记住将此文件复制到新版本目录中。例如,新版本是 x.yy.zz 必须将此文件复制到目录中:
~/.arduino15/packages/realtek/hardware/AmebaD/x.yy.zz/cores/ambd/avr/pgmspace.h
WiFiWebServer server ( 80 );
创建 WiFiWebServer 类对象。
参数:
主机端口号: int port
(默认为标准HTTP端口80)
启动服务器
void begin ();
处理传入的客户端请求
void handleClient ();
禁用服务器
void close ();
void stop ();
两种方法功能相同
客户端请求处理程序
void on ();
void addHandler ();
void onNotFound ();
void onFileUpload ();
例子:
server.on( " / " , handlerFunction);
server.onNotFound(handlerFunction); // called when handler is not assigned
server.onFileUpload(handlerFunction); // handle file uploads
向客户端发送响应
void send ();
void send_P ();
Parameters:
code
- HTTP 响应代码,可以是200
或404
等。
content_type
- HTTP 内容类型,如"text/plain"
或"image/png"
等。
content
- 实际内容主体
获取有关请求参数的信息
const String & arg ();
const String & argName ();
int args ();
bool hasArg ();
Function usage:
arg
- 获取请求参数值,使用arg("plain")
获取 POST 正文
argName
- 获取请求参数名称
args
- 获取参数计数
hasArg
- 检查参数是否存在
获取有关请求标头的信息
const String & header ();
const String & headerName ();
const String & hostHeader ();
int headers ();
bool hasHeader ();
Function usage:
header
- 获取请求头值
headerName
- 获取请求标头名称
hostHeader
- 获取请求主机标头(如果可用),否则为空字符串
headers
- 获取标题计数
hasHeader
- 检查标头是否存在
验证
bool authenticate ();
void requestAuthentication ();
Function usage:
authenticate
- 服务器身份验证,如果客户端已通过身份验证,则返回 true,否则返回 false
requestAuthentication
- 向客户端发送身份验证失败响应
Example Usage:
if (!server.authenticate(username, password))
{
server. requestAuthentication ();
}
const String& uri (); // get the current uri
HTTPMethod method (); // get the current method
WiFiClient client (); // get the current client
HTTPUpload& upload (); // get the current upload
void setContentLength (); // set content length
void sendHeader (); // send HTTP header
void sendContent (); // send content
void sendContent_P ();
void collectHeaders (); // set the request headers to collect
void serveStatic ();
size_t streamFile ();
WiFiWebServer_RTL8720/examples/AdvancedWebServer/AdvancedWebServer.ino
74723f4 中的第 40 至 245 行
WiFiWebServer_RTL8720/examples/AdvancedWebServer/defines.h
74723f4 中的第 11 至 42 行
以下是在Rtlduino RTL8720DN上运行示例AdvancedWebServer时的调试终端输出和屏幕截图
Starting AdvancedServer on Rtlduino RTL8720DN with RTL8720DN
WiFiWebServer_RTL8720 v1 .1.2
interface 0 is initialized
interface 1 is initialized
Initializing WIFI ...
WIFI initialized
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet1
RTL8721D[Driver]: set ssid [HueNet1]
RTL8721D[Driver]: rtw_set_wpa_ie[ 1160 ]: AuthKeyMgmt = 0x2
RTL8721D[Driver]: rtw_restruct_sec_ie[ 4225 ]: no pmksa cached
RTL8721D[Driver]: start auth to 68 : 7f : 74 : 94 :f4:a5
RTL8721D[Driver]: auth alg = 2
RTL8721D[Driver]:
OnAuthClient:algthm = 0 , seq = 2 , status = 0 , sae_msg_len = 11
RTL8721D[Driver]: auth success, start assoc
RTL8721D[Driver]: association success (res= 1 )
RTL8721D[Driver]: ClientSendEAPOL[1624]: no use cache pmksa
RTL8721D[Driver]: ClientSendEAPOL[1624]: no use cache pmksa
RTL8721D[Driver]: set pairwise key to hw: alg:4(WEP40- 1 WEP104- 5 TKIP- 2 AES- 4 )
RTL8721D[Driver]: set group key to hw: alg:2(WEP40- 1 WEP104- 5 TKIP- 2 AES- 4 ) keyid:1
Interface 0 IP address : 192.168.2.117
[INFO] Listen socket successfully
[INFO] Socket conntect successfully
HTTP server started @ 192.168.2.117
[INFO] Accept connection successfully
A client connected to this server :
[PORT]: 36912
[IP]:192.168.2.30
[INFO] Accept connection successfully
A client connected to this server :
[PORT]: 36914
[IP]:192.168.2.30
[WIFI] String Len = 0, extend to 2048
[INFO] Accept connection successfully
以下是在Rtlduino RTL8720DN上运行示例WebClient时的调试终端输出和屏幕截图
Starting WebClientRepeating on Rtlduino RTL8720DN with RTL8720DN
WiFiWebServer_RTL8720 v1 .1.2
interface 0 is initialized
interface 1 is initialized
Initializing WIFI ...
WIFI initialized
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet1
RTL8721D[Driver]: set ssid [HueNet1]
RTL8721D[Driver]: rtw_set_wpa_ie[ 1160 ]: AuthKeyMgmt = 0x2
RTL8721D[Driver]: rtw_restruct_sec_ie[ 4225 ]: no pmksa cached
RTL8721D[Driver]: start auth to 68 : 7f : 74 : 94 :f4:a5
RTL8721D[Driver]: auth alg = 2
RTL8721D[Driver]:
OnAuthClient:algthm = 0 , seq = 2 , status = 0 , sae_msg_len = 11
RTL8721D[Driver]: auth success, start assoc
RTL8721D[Driver]: association success (res= 1 )
RTL8721D[Driver]: ClientSendEAPOL[1624]: no use cache pmksa
RTL8721D[Driver]: ClientSendEAPOL[1624]: no use cache pmksa
RTL8721D[Driver]: set pairwise key to hw: alg:4(WEP40- 1 WEP104- 5 TKIP- 2 AES- 4 )
RTL8721D[Driver]: set group key to hw: alg:2(WEP40- 1 WEP104- 5 TKIP- 2 AES- 4 ) keyid:1
Interface 0 IP address : 192.168.2.117You're connected to the network, IP = 192.168.2.117
SSID: HueNet1, Signal strength (RSSI):-26 dBm
[INFO]server_drv.cpp: start_client
[INFO] Create socket successfully
[INFO] Connect to Server successfully!
Connecting...
HTTP/1.1 200 OK
Date: Thu, 28 Apr 2022 02:46:07 GMT
Content-Type: text/plain
Content-Length: 2263
Connection: close
x-amz-id-2: 0v2VZitmKPb1GvH/Of2rACgGVIyluvsMCTX1kbkYKmtOMZMLlHXAT1n7wdAcMiFQ6LPQ1Qy2tSg=
x-amz-request-id: 72CSXT4AMDTCDJYE
Last-Modified: Wed, 23 Feb 2022 14:56:42 GMT
ETag: "667cf48afcc12c38c8c1637947a04224"
CF-Cache-Status: DYNAMIC
Report-To: { " endpoints " :[{ " url " : " https://a.nel.cloudflare.com/report/v3?s=vdeduIIMRyhO44T972z7Z0qfco3T5svA5zYhyMJqQE5hTNGvTxTg%2B8S8e90uedVsSDo5oj73gg%2BxEoPfXW1%2FUCfu6XkFt6oLuf9zjLCo%2BSe58OLsZhr25mZ3MxPD%2ByY%3D " }], " group " : " cf-nel " , " max_age " : 604800 }
NEL: { " success_fraction " : 0 , " report_to " : " cf-nel " , " max_age " : 604800 }
Server: cloudflare
CF-RAY: 702c77389848b671-YWG
alt-svc: h3= " :443 " ; ma= 86400 , h3- 29 = " :443 " ; ma= 86400
`:;;;,` .:;;:.
.;;;;;;;;;;;` :;;;;;;;;;;: TM
`;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;;
:;;;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; ;; .;; ;; ,;, ;; ;;;, ;; ;;
;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;;
;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;
以下是在Rtlduino RTL8720DN上运行示例ScanNetworks时的调试终端输出和屏幕截图
Starting ScanNetworks on Rtlduino RTL8720DN with RTL8720DN
WiFiWebServer_RTL8720 v1 .1.2
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet_5G
You ' re connected to the network, IP = 192.168.2.152
MAC address: 69:4E:06:60:C9:94
Scanning available networks...
Number of available networks:19
0) HueNet Signal: -26 dBm Encryption: WPA2_PSK
1) HueNet_5G Signal: -32 dBm Encryption: WPA2_PSK
2) HueNetTek Signal: -32 dBm Encryption: WPA2_PSK
3) HueNetTek_5G Signal: -33 dBm Encryption: WPA2_PSK
4) HueNet1 Signal: -36 dBm Encryption: WPA2_PSK
5) HueNet2 Signal: -58 dBm Encryption: WPA2_PSK
6) HueNet2_5G Signal: -60 dBm Encryption: WPA2_PSK
7) guest_24 Signal: -64 dBm Encryption: WPA2_PSK
8) bacau Signal: -65 dBm Encryption: WPA2_PSK
9) guest_5 Signal: -77 dBm Encryption: WPA2_PSK
10) pitesti Signal: -77 dBm Encryption: WPA2_PSK
以下是在Rtlduino RTL8720DN上运行示例MQTTClient_Auth时的调试终端输出和屏幕截图
Starting MQTTClient_Auth on Rtlduino RTL8720DN with RTL8720DN
WiFiWebServer_RTL8720 v1 .1.2
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet_5G
Connected! IP address: 192.168.2.152
Attempting MQTT connection to broker.emqx.io...connected
Message Send : MQTT_Pub => Hello from MQTTClient_Auth on Rtlduino RTL8720DN with RTL8720DN
Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on Rtlduino RTL8720DN with RTL8720DN
Message Send : MQTT_Pub => Hello from MQTTClient_Auth on Rtlduino RTL8720DN with RTL8720DN
Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on Rtlduino RTL8720DN with RTL8720DN
以下是在Rtlduino RTL8720DN上运行示例MQTT_ThingStream时的调试终端输出和屏幕截图
Start MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
WiFiWebServer_RTL8720 v1 .1.2
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet_5G
Connected! IP address: 192.168.2.152
***************************************
STM32_Pub
***************************************
Attempting MQTT connection to broker.emqx.io
...connected
Published connection message successfully!
Subscribed to: STM32_Sub
MQTT Message Send : STM32_Pub => Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message receive [STM32_Pub] Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message Send : STM32_Pub => Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message receive [STM32_Pub] Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message Send : STM32_Pub => Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message receive [STM32_Pub] Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message Send : STM32_Pub => Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
MQTT Message receive [STM32_Pub] Hello from MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN
以下是在Rtlduino RTL8720DN上运行示例WiFiUdpNTPClient时的调试终端输出和屏幕截图
Starting WiFiUdpNTPClient on Rtlduino RTL8720DN with RTL8720DN
WiFiWebServer_RTL8720 v1 .1.2
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet_5G
Connected! IP address: 192.168.2.152
SSID: HueNet1, Signal strength (RSSI):-39 dBm
Starting connection to server...
Listening on port 2390
packet received
Seconds since Jan 1 1900 = 3835239949
Unix time = 1626251149
The UTC time is 8:25:49
packet received
Seconds since Jan 1 1900 = 3835239960
Unix time = 1626251160
The UTC time is 8:26:00
packet received
Seconds since Jan 1 1900 = 3835239971
Unix time = 1626251171
The UTC time is 8:26:11
默认情况下,串行上启用调试。调试级别从 0 到 4。要禁用,请将WIFI_LOGLEVEL更改为 0
// Use this to output debug msgs to Serial
# define DEBUG_WIFI_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
# define _WIFI_LOGLEVEL_ 1
如果您遇到编译错误,通常情况下,您可能需要安装较新版本的板核心,应用库的补丁、包的补丁或该库的最新版本。
该 WiFiWebServer_RTL8720 库当前支持以下板:
该图书馆提供以下支持:
将问题提交至:WiFiWebServer_RTL8720 issues
arduino.cc
更改为arduino.tips
allman
样式添加 astyle。重新设计图书馆️️ 伊万·格罗霍特科夫 | ️ 阿德里安·麦克尤恩 |
如果您想为这个项目做出贡献:
版权所有 (c) 2021 - Khoi Hoang