這個 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) 。
假設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
`:;;;,` .:;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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。
// 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