【Wio Terminal】使用WiFi(3)- Wi-F的高級使用

使用WiFi(3)

  • Wi-F的高級使用
    • HTTPClient 的使用
      • HTTP GET
      • HTTPs GET
      • HTTP POST
      • WebServer
      • HTTP Authentication Web Server
      • DNSServer
      • mDNS
      • mDNS-SD
      • WiFiManager

Wi-F的高級使用

本節介紹了一些WiFi的高級庫用法,如HTTPClient、DNSServer和WebServer庫。通過實現這些庫,您可以使用簡單的API開發物聯網項目。

請確保您已更新了最新的固件和依賴庫。
在這里插入圖片描述

HTTPClient 的使用

HTTPClient用于使對web服務器的HTTPGET、POST和PUT請求變得非常容易。這里有一些例子供您入門!

HTTP GET

這是一個使用HTTPClient進行簡單HTTP連接并將響應打印回串行監視器的示例。
在這里插入圖片描述

  • 將yourNetwork和yourPassword更改為你的WiFi ssid和密碼。
  • 將代碼上傳到Wio Terminal。
#include <rpcWiFi.h>
#include <HTTPClient.h>const char* ssid = "yourNetwork";
const char* password =  "yourPassword";void setup() {Serial.begin(115200);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) { //Check for the connectiondelay(500);Serial.println("Connecting..");}Serial.print("Connected to the WiFi network with IP: ");Serial.println(WiFi.localIP());
}void loop() {// wait for WiFi connectionif((WiFi.status() == WL_CONNECTED)) {HTTPClient http;Serial.print("[HTTP] begin...\n");// configure traged server and urlhttp.begin("http://www.example.com/index.html"); //HTTPSerial.print("[HTTP] GET...\n");// start connection and send HTTP headerint httpCode = http.GET();// httpCode will be negative on errorif(httpCode > 0) {// HTTP header has been send and Server response header has been handledSerial.printf("[HTTP] GET... code: %d\n", httpCode);// file found at serverif(httpCode == HTTP_CODE_OK) {String payload = http.getString();Serial.println(payload);}} else {Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());}http.end();}delay(5000);
}

HTTPs GET

這是使用HTTPClient庫的HTTPs連接。您可以參考此向您想要訪問的網站發送HTTPs GET請求!
您可以按照此鏈接查找網站的根CA。
在這里插入圖片描述

  • 將yourNetwork和yourPassword更改為你的WiFi ssid和密碼。
  • 將代碼上傳到Wio Terminal。
#include <rpcWiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>const char* ssid = "yourNetwork";
const char* password =  "yourPassword";const char* test_root_ca = \"-----BEGIN CERTIFICATE-----\n""MIIESjCCAzKgAwIBAgINAeO0mqGNiqmBJWlQuDANBgkqhkiG9w0BAQsFADBMMSAw\n""HgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMjETMBEGA1UEChMKR2xvYmFs\n""U2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xNzA2MTUwMDAwNDJaFw0yMTEy\n""MTUwMDAwNDJaMEIxCzAJBgNVBAYTAlVTMR4wHAYDVQQKExVHb29nbGUgVHJ1c3Qg\n""U2VydmljZXMxEzARBgNVBAMTCkdUUyBDQSAxTzEwggEiMA0GCSqGSIb3DQEBAQUA\n""A4IBDwAwggEKAoIBAQDQGM9F1IvN05zkQO9+tN1pIRvJzzyOTHW5DzEZhD2ePCnv\n""UA0Qk28FgICfKqC9EksC4T2fWBYk/jCfC3R3VZMdS/dN4ZKCEPZRrAzDsiKUDzRr\n""mBBJ5wudgzndIMYcLe/RGGFl5yODIKgjEv/SJH/UL+dEaltN11BmsK+eQmMF++Ac\n""xGNhr59qM/9il71I2dN8FGfcddwuaej4bXhp0LcQBbjxMcI7JP0aM3T4I+DsaxmK\n""FsbjzaTNC9uzpFlgOIg7rR25xoynUxv8vNmkq7zdPGHXkxWY7oG9j+JkRyBABk7X\n""rJfoucBZEqFJJSPk7XA0LKW0Y3z5oz2D0c1tJKwHAgMBAAGjggEzMIIBLzAOBgNV\n""HQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1Ud\n""EwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFJjR+G4Q68+b7GCfGJAboOt9Cf0rMB8G\n""A1UdIwQYMBaAFJviB1dnHB7AagbeWbSaLd/cGYYuMDUGCCsGAQUFBwEBBCkwJzAl\n""BggrBgEFBQcwAYYZaHR0cDovL29jc3AucGtpLmdvb2cvZ3NyMjAyBgNVHR8EKzAp\n""MCegJaAjhiFodHRwOi8vY3JsLnBraS5nb29nL2dzcjIvZ3NyMi5jcmwwPwYDVR0g\n""BDgwNjA0BgZngQwBAgIwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly9wa2kuZ29vZy9y\n""ZXBvc2l0b3J5LzANBgkqhkiG9w0BAQsFAAOCAQEAGoA+Nnn78y6pRjd9XlQWNa7H\n""TgiZ/r3RNGkmUmYHPQq6Scti9PEajvwRT2iWTHQr02fesqOqBY2ETUwgZQ+lltoN\n""FvhsO9tvBCOIazpswWC9aJ9xju4tWDQH8NVU6YZZ/XteDSGU9YzJqPjY8q3MDxrz\n""mqepBCf5o8mw/wJ4a2G6xzUr6Fb6T8McDO22PLRL6u3M4Tzs3A2M1j6bykJYi8wW\n""IRdAvKLWZu/axBVbzYmqmwkm5zLSDW5nIAJbELCQCZwMH56t2Dvqofxs6BBcCFIZ\n""USpxu6x6td0V7SvJCCosirSmIatj/9dSSVDQibet8q/7UK4v4ZUN80atnZz1yg==\n""-----END CERTIFICATE-----\n";WiFiClientSecure client;void setup() {Serial.begin(115200);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) { //Check for the connectiondelay(500);Serial.println("Connecting..");}Serial.print("Connected to the WiFi network with IP: ");Serial.println(WiFi.localIP());client.setCACert(test_root_ca);
}void loop() {if(&client) {{// Add a scoping block for HTTPClient https to make sure it is destroyed before WiFiClientSecure *client is HTTPClient https;Serial.print("[HTTPS] begin...\n");if (https.begin(client, "https://www.google.com/index.html")) {  // HTTPSSerial.print("[HTTPS] GET...\n");// start connection and send HTTP headerint httpCode = https.GET();// httpCode will be negative on errorif (httpCode > 0) {// HTTP header has been send and Server response header has been handledSerial.printf("[HTTPS] GET... code: %d\n", httpCode);// file found at serverif (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {String payload = https.getString();Serial.println(payload);}} else {Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());}https.end();} else {Serial.printf("[HTTPS] Unable to connect\n");}// End extra scoping block}} else {Serial.println("Unable to create client");}Serial.println();Serial.println("Waiting 10s before the next round...");delay(10000);
}

HTTP POST

這是一個使用Wio Terminal的HTTPClient向Web服務器發送HTTP POST請求的示例。在此演示中,我們使用python在個人電腦上設置一個簡單的web服務器,該服務器可以接收并響應HTTP請求。
在這里插入圖片描述
Python服務器端代碼

首先,我們需要在Python中使用pip安裝所需的bottle庫。在終端中運行以下命令以安裝bottle:

pip install bottle

導入bottle后,復制以下代碼并將其保存為simple-server.py。你也可以將端口更改為你喜歡的其他端口,但要確保它與Arduino端匹配。

from bottle import run, request, post@post('/')
def index():data = request.body.read()print(data)run(host='0.0.0.0', port=1880, debug=True)

Arduino代碼

  • 將yourNetwork和yourPassword更改為你的WiFi ssid和密碼。
  • 將代碼上傳到Wio Terminal。
  • 檢查終端,你可以看到來自Wio Terminal的傳入HTTP請求消息。
#include <rpcWiFi.h>
#include <HTTPClient.h>const char* ssid = "yourNetwork";
const char* password =  "yourPassword";// Change the following IP to your computer's IP running the server, make sure the Port also match
const char* yourLocalIp =  "http://10.0.0.233:1880/";void setup() {Serial.begin(115200);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) { //Check for the connectiondelay(500);Serial.println("Connecting..");}Serial.print("Connected to the WiFi network with IP: ");Serial.println(WiFi.localIP());
}void loop() {if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection statusHTTPClient http;http.begin(yourLocalIp);  //Specify destination for HTTP requesthttp.addHeader("Content-Type", "text/plain");             //Specify content-type headerint httpResponseCode = http.POST("Hello Bottle, from Wio Terminal");   //Send the actual POST requestif(httpResponseCode>0){Serial.print("HTTP Response Code: ");Serial.println(httpResponseCode);   //Print return code}else{Serial.print("Error on sending request: ");Serial.println(httpResponseCode);}http.end();  //Free resources}else{Serial.println("Error in WiFi connection");}delay(5000);  //Send a request every 5 seconds
}

WebServer

在WebServer庫的幫助下,你可以在Wio Terminal上設置并運行Web服務器。通過在與Wio Terminal連接到同一網絡的任何計算機上運行的瀏覽器訪問服務器,你可以從網頁上控制硬件,讀取傳感器的值等等!

簡單 HelloServer 示例
這將在連接的網絡上使用Wio Terminal設置一個簡單的Web服務器。
在這里插入圖片描述

  • 將yourNetwork和yourPassword更改為您的WiFi ssid和密碼。
  • 將代碼上傳到Wio Terminal。
  • 使用瀏覽器從同一網絡輸入Wio Terminal的IP地址來訪問web服務器。
#include <rpcWiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>const char *ssid = "yourNetwork";
const char *password = "yourPassword";WebServer server(80);const int led = 13;void handleRoot() {digitalWrite(led, 1);server.send(200, "text/plain", "hello from Wio Terminal!");digitalWrite(led, 0);
}void handleNotFound() {digitalWrite(led, 1);String message = "File Not Found\n\n";message += "URI: ";message += server.uri();message += "\nMethod: ";message += (server.method() == HTTP_GET) ? "GET" : "POST";message += "\nArguments: ";message += server.args();message += "\n";for (uint8_t i = 0; i < server.args(); i++) {message += " " + server.argName(i) + ": " + server.arg(i) + "\n";}server.send(404, "text/plain", message);digitalWrite(led, 0);
}void setup(void) {pinMode(led, OUTPUT);digitalWrite(led, 0);Serial.begin(115200);WiFi.mode(WIFI_STA);WiFi.begin(ssid, password);// Wait for connectionwhile (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());server.on("/", handleRoot);server.on("/inline", []() {server.send(200, "text/plain", "this works as well");});server.onNotFound(handleNotFound);server.begin();Serial.println("HTTP server started");
}void loop(void) {server.handleClient();
}

HTTP Authentication Web Server

這個示例設置了一個需要身份驗證過程的Web服務器,這在某些情況下出于安全考慮可能非常有用。
在這里插入圖片描述

  • 將yourNetwork和yourPassword更改為您的WiFi ssid和密碼。
  • 將代碼上傳到Wio Terminal。
  • 使用瀏覽器從同一網絡輸入Wio Terminal的IP地址來訪問Web服務器,并輸入預設的用戶名和密碼。
#include <rpcWiFi.h>
#include <WebServer.h>const char *ssid = "yourNetwork";
const char *password = "yourPassword";WebServer server(80);const char* www_username = "admin";
const char* www_password = "password";void setup() {Serial.begin(115200);WiFi.mode(WIFI_STA);WiFi.begin(ssid, password);if (WiFi.waitForConnectResult() != WL_CONNECTED) {Serial.println("WiFi Connect Failed! Rebooting...");delay(1000);NVIC_SystemReset(); // Reset Wio Terminal}server.on("/", []() {if (!server.authenticate(www_username, www_password)) {return server.requestAuthentication();}server.send(200, "text/plain", "Login OK");});server.begin();Serial.print("Open http://");Serial.print(WiFi.localIP());Serial.println("/ in your browser to see it working");
}void loop() {server.handleClient();
}

DNSServer

我們討論了WebServer,我們使用IP地址來訪問它。 但是,如果您想通過鍵入域名(例如www.google.com)來訪問它,則需要使用DNSServer。
在這里插入圖片描述

  • 使用DNSServer必須在AP模式下。
  • 引入相應的庫#include <DNSServer.h>。
  • 聲明DNSServer對象。
  • 使用start()方法啟動DNS服務器。
  • 使用processNextRequest()方法處理來自客戶端的請求。
  • 將代碼上傳到Wio Terminal,并將您的PC連接到DNSServer示例Wi-Fi。
  • 輸入www.wioterminal.com和www.wioterminal.com/p1。
#include <rpcWiFi.h>
#include <DNSServer.h>
#include <WebServer.h>IPAddress local_IP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);const byte DNS_PORT = 53;DNSServer dnsServer;
WebServer webserver(80);void handleRoot()
{webserver.send(200, "text/plain", "Root page accessed via domain name");
}void handleP1()
{webserver.send(200, "text/plain", "Page 1 accessed via domain name");
}void setup()
{WiFi.mode(WIFI_AP);WiFi.softAPConfig(local_IP, gateway, subnet);WiFi.softAP("DNSServer example");webserver.on("/", handleRoot);webserver.on("/p1", handleP1);dnsServer.start(DNS_PORT, "www.wioterminal.com", local_IP); //Start the DNS service, example.com is the registered domain name.webserver.begin();
}void loop()
{dnsServer.processNextRequest();webserver.handleClient();
}

mDNS

什么是Multicast DNS(mDNS)?

Multicast DNS(mDNS)協議在沒有本地名稱服務器的小型網絡中將主機名解析為IP地址。Multicast DNS專為小型網絡設計,旨在提高其用戶友好性。其想法是,用戶可以在秘密的局域網中連接設備而不會出現任何問題。

Install the Seeed_Arduino_rpcmDNS
下載Seeed_Arduino_rpcmDNS,并安裝到Arduino

mDNS Web Server示例
這是一個在Wio Terminal上設置mDNS Web服務器的示例,以便在同一網絡中連接的其他設備可以在定義的站點上瀏覽該Web服務器。
在這里插入圖片描述

  • 將yourNetwork和yourPassword更改為你的WiFi ssid和密碼。
  • 將代碼上傳到Wio Terminal。
  • 使用瀏覽器從同一網絡輸入http://WioTerminal.local/來訪問Web服務器,并輸入預設的用戶名和密碼。
#include <rpcWiFi.h>
#include <RPCmDNS.h>
#include <WiFiClient.h>const char* ssid     = "yourNetwork";
const char* password = "yourPassword";// TCP server at port 80 will respond to HTTP requests
WiFiServer server(80);void setup(void)
{  Serial.begin(115200);while(!Serial){;}Serial.printf("Setup Start \r\n");// Connect to WiFi networkWiFi.begin(ssid, password);Serial.println("");// Wait for connectionwhile (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.println("");Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());// Set up mDNS responder:// - first argument is the domain name, in this example//   the fully-qualified domain name is "esp8266.local"// - second argument is the IP address to advertise//   we send our IP address on the WiFi networkif (!MDNS.begin("WioTerminal")) {Serial.println("Error setting up MDNS responder!");while(1) {delay(1000);}}Serial.println("mDNS responder started");// Start TCP (HTTP) serverserver.begin();Serial.println("TCP server started");// Add service to MDNS-SDMDNS.addService("http", "tcp", 80);Serial.printf("Setup Done \r\n");
}void loop(void)
{// Check if a client has connectedWiFiClient client = server.available();if (!client) {return;}Serial.println("");Serial.println("New client");// Wait for data from client to become availablewhile(client.connected() && !client.available()){delay(1);}// Read the first line of HTTP requestString req = client.readStringUntil('\r');// First line of HTTP request looks like "GET /path HTTP/1.1"// Retrieve the "/path" part by finding the spacesint addr_start = req.indexOf(' ');int addr_end = req.indexOf(' ', addr_start + 1);if (addr_start == -1 || addr_end == -1) {Serial.print("Invalid request: ");Serial.println(req);return;}req = req.substring(addr_start + 1, addr_end);Serial.print("Request: ");Serial.println(req);String s;if (req == "/"){IPAddress ip = WiFi.localIP();String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from Wio Terminal at ";s += ipStr;s += "</html>\r\n\r\n";Serial.println("Sending 200");}else{s = "HTTP/1.1 404 Not Found\r\n\r\n";Serial.println("Sending 404");}client.print(s);client.stop();Serial.println("Done with client");
}

mDNS-SD

這是一個mDNS-SD(服務發現)示例,允許您發現同一網絡中的服務。

關于基于DNS的服務發現:
在這里插入圖片描述

  • 將 yourNetwork 和 yourPassword 更改為您的 WiFi ssid 和密碼。
  • 將代碼上傳到 Wio Terminal。
#include <rpcWiFi.h>
#include <RPCmDNS.h>
#include <WiFiClient.h>const char* ssid     = "yourNetwork";
const char* password = "yourPassword";// TCP server at port 80 will respond to HTTP requests
WiFiServer server(80);void setup(void)
{  Serial.begin(115200);while(!Serial){;}Serial.printf("Setup Start \r\n");// Connect to WiFi networkWiFi.begin(ssid, password);Serial.println("");// Wait for connectionwhile (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.println("");Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());// Set up mDNS responder:// - first argument is the domain name, in this example//   the fully-qualified domain name is "esp8266.local"// - second argument is the IP address to advertise//   we send our IP address on the WiFi networkif (!MDNS.begin("WioTerminal")) {Serial.println("Error setting up MDNS responder!");while(1) {delay(1000);}}Serial.println("mDNS responder started");// Start TCP (HTTP) serverserver.begin();Serial.println("TCP server started");// Add service to MDNS-SDMDNS.addService("http", "tcp", 80);Serial.printf("Setup Done \r\n");
}void loop(void)
{// Check if a client has connectedWiFiClient client = server.available();if (!client) {return;}Serial.println("");Serial.println("New client");// Wait for data from client to become availablewhile(client.connected() && !client.available()){delay(1);}// Read the first line of HTTP requestString req = client.readStringUntil('\r');// First line of HTTP request looks like "GET /path HTTP/1.1"// Retrieve the "/path" part by finding the spacesint addr_start = req.indexOf(' ');int addr_end = req.indexOf(' ', addr_start + 1);if (addr_start == -1 || addr_end == -1) {Serial.print("Invalid request: ");Serial.println(req);return;}req = req.substring(addr_start + 1, addr_end);Serial.print("Request: ");Serial.println(req);String s;if (req == "/"){IPAddress ip = WiFi.localIP();String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from Wio Terminal at ";s += ipStr;s += "</html>\r\n\r\n";Serial.println("Sending 200");}else{s = "HTTP/1.1 404 Not Found\r\n\r\n";Serial.println("Sending 404");}client.print(s);client.stop();Serial.println("Done with client");
}

WiFiManager

我們已經將廣為人知的WiFi管理器移植到Wio Terminal平臺上,這樣您就可以使用手機或其他設備為Wio Terminal配置WiFi設置了!

Install the Seeed_Arduino_rpcWiFiManager
下載Seeed_Arduino_rpcWiFiManager

WiFiManager Auto Connect示例
在這里插入圖片描述

這個示例是自動連接功能的演示。您可以使用此示例為Wio Terminal設置WiFi。

  • 將代碼上傳到Wio Terminal。
  • 如果Wio Terminal之前已經連接過WiFi,它將自動連接到同一網絡。如果它無法連接到任何WiFi,它將進入AP模式并發出WiFi信號。使用手機連接到此WiFi并輸入WiFi設置。
#include <rpcWiFi.h>
#include <DNSServer.h>
#include <WebServer.h>
#include <WiFiManager.h>void setup() {Serial.begin(115200);while(!Serial); // wait till Serial is openedWiFiManager wifiManager;// Uncomment the resetSettings() will wipe out the saved settings//wifiManager.resetSettings();//Fetches ssid and pass from RTL8720 and tries to connect//if it does not connect it starts an access point with the specified name//here  "AutoConnectAP"//and goes into a blocking loop awaiting configurationwifiManager.autoConnect("AutoConnectAP");//or use this for auto generated name ESP + ChipID//wifiManager.autoConnect();//if you get here you have connected to the WiFiSerial.println("connected...yeey :)");Serial.println(WiFi.localIP());
}void loop() {// put your main code here, to run repeatedly:
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/718341.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/718341.shtml
英文地址,請注明出處:http://en.pswp.cn/news/718341.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

美國亞利桑那州立大學宣布與OpenAI建立合作伙伴關系!

美國亞利桑那州立大學 (Arizona State University) 在官網宣布—— 將與OpenAI建立合作伙伴關系&#xff01; 該校也成為了第一個與OpenAI合作的高等教育機構。 來源&#xff1a;亞利桑那州立大學官網 亞利桑那州立大學校長表示&#xff1a; “我們認識到人工智能系統將持續…

高并發IO底層原理淺析(四)

Java NIO中的Selector&#xff08;選擇器&#xff09;是一個用于檢測多個非阻塞通道&#xff08;Channel&#xff09;是否準備就緒進行讀寫操作的關鍵組件&#xff0c;它實現了I/O多路復用技術。在單個線程中&#xff0c;Selector可以監聽和管理多個Channel上的事件&#xff0c…

Redis安全加固策略:配置文件權限設置 配置本地日志存儲目錄 連接超時時間限制

Redis安全加固策略&#xff1a;配置文件權限設置 & 配置本地日志存儲目錄 & 連接超時時間限制 1.1 配置文件權限設置1.2 配置本地日志存儲目錄1.3 連接超時時間限制 &#x1f496;The Begin&#x1f496;點點關注&#xff0c;收藏不迷路&#x1f496; 1.1 配置文件權限…

如何理解template<size_t N>?

template<size_t N> 是C中的模板參數&#xff0c;用于定一個非類型參數的值。它可以在編譯時確定&#xff0c;并且可以在編譯時進行計算和使用。 例如&#xff0c;我們可以定義一個模板函數&#xff0c;接受一個大小為N的數組作為參數&#xff1a; template<size_t …

Qt/事件分發器/事件過濾器

事件分發器 //事件分發器bool event(QEvent* e); //事件分發器&#xff1a;&#xff1a;用途 分發事件 bool MyLabel::event(QEvent* e) {if(e->type() QEvent::MouseButtonPress){//如果是鼠標摁下 攔截事件 不向下分發QMouseEvent* ev static_cast<QMouseEvent*>…

Qt-Qss 樣式表屬性大全

目錄 前言 源碼文件信息 QSS屬性大全 1.控件常用的屬性 2.控件常用屬性值 3.控件常用狀態 4.其他 前言 相信很大一部分開發者真的被Qt樣式表的屬性搞挺頭痛的&#xff01; 一方面Qss的示例Demo太過簡單&#xff0c; 另一方面&#xff0c;Qss的所有屬性在Qt的官方文…

軟考高級:逆向工程相關概念和例題

作者&#xff1a;明明如月學長&#xff0c; CSDN 博客專家&#xff0c;大廠高級 Java 工程師&#xff0c;《性能優化方法論》作者、《解鎖大廠思維&#xff1a;剖析《阿里巴巴Java開發手冊》》、《再學經典&#xff1a;《Effective Java》獨家解析》專欄作者。 熱門文章推薦&am…

Deeplearning4j【基礎 01】初識Java深度學習框架DL4J

初識Java深度學習框架DL4J 1.起因2.簡介3.組件3.1 Deeplearning4j/ScalNet3.1.1 Deeplearning4jf&#xff08;Java&#xff09;3.1.2 ScalNet&#xff08;Scala&#xff09; 3.2 ND4J/LibND4J3.3 SameDiff3.4 DataVec3.5 Arbiter3.6 RL4J 4.總結 內容來自網絡&#xff0c;基于官…

Redis--線程模型詳解

Redis線程模型 Redis內部使用的文件事件處理器&#xff08;基于Reactor模式開發的&#xff09;file event handler是單線程的&#xff0c;所以Redis線程模型才叫單線程模型&#xff0c;它采用IO多路復用機制同時監聽多個socket&#xff0c;當被監聽的socket準備好執行accep、r…

072:vue+cesium 實現下雪效果

第072個 點擊查看專欄目錄 本示例的目的是介紹如何在vue+cesium中實現下雪效果,這里使用著色器來實現實例特效。 直接復制下面的 vue+cesium源代碼,操作2分鐘即可運行實現效果. 文章目錄 示例效果配置方式示例源代碼(共120行)著色代碼實現心得:專欄目標示例效果

Python世界之附加

一、數據類型轉換 1.隱式類型轉換 在隱式類型轉換中&#xff0c;Python 會自動將一種數據類型轉換為另一種數據類型。 對兩種不同類型的數據進行運算&#xff0c;較低數據類型就會轉換為較高數據類型以避免數據丟失。 2.顯式類型轉換 在顯式類型轉換中&#xff0c;用戶將對…

Linux設置靜態IP地址

在Linux系統中設置靜態IP地址的步驟如下&#xff1a; 1.使用管理員權限登錄系統。 2.編輯網卡配置文件&#xff1a; 網卡配置文件通常位于 /etc/sysconfig/network-scripts/ 目錄下&#xff0c;可以使用命令 cd /etc/sysconfig/network-scripts 切換到該目錄。 …

Wifi技術知識

參考文章 https://www.163.com/dy/article/FDFT60T70550I80C.html https://www.zhihu.com/tardis/bd/art/485711752?source_id1001 wifi代數 以前大家看電腦手機路由器參數&#xff0c;WiFi都是802.11a/b/n/g/ac/ax&#xff0c;這學名讀起來有些麻煩&#xff0c;現在好了&…

第12屆智能計算與無線光通信國際會議(ICWOC 2024)即將召開!

2024年第12屆智能計算與無線光通信國際會議&#xff08;ICWOC 2024&#xff09;將于2024年6月21-23日在中國重慶召開。隨著深度學習等人工智能技術的不斷進步&#xff0c;以自動化、自治為特征的智能應用預計將激增。本屆會議主題為“光通信智能鏈接”&#xff0c;旨在為相關技…

ubuntu環境下docker容器詳細安裝使用

文章目錄 一、簡介二、ubuntu安裝docker1.刪除舊版本2.安裝方法一3. 安裝方法二&#xff08;推薦使用&#xff09;4.運行Docker容器5. 配置docker加速器 三、Docker鏡像操作1. 拉取鏡像2. 查看本地鏡像3. 刪除鏡像4. 鏡像打標簽5. Dockerfile生成鏡像 四、Docker容器操作1. 獲取…

Qt | TCP服務器端框架搭建

文章目錄 server.hserver.cppmain.cpptcpclientsocket.htcpclientsocket.cpptcpserver.htcpserver.cpp提示運行QTcpServer 是 Qt 框架中的一個類,用于實現 TCP 服務器。它提供了一種方便的方式來創建和管理 TCP 服務器,以便與客戶端進行通信。QTcpServer 類屬于 QtNetwork 模…

Webserver(1): C++實現線程池

在實現線程池之前&#xff0c;首先對線程池中所需要用到的互斥鎖、條件變量和信號量進行了簡單的封裝。 互斥鎖、條件變量和信號量封裝 locker.h頭文件如下&#xff08;已詳細注釋&#xff09; /* 這里面對互斥鎖&#xff0c;條件變量和信號量進行了封裝 保證工作隊列的線程…

微服務架構的流行框架之:Dubbo Spring Cloud

Dubbo Dubbo是一個高性能、輕量級的開源Java RPC&#xff08;Remote Procedure Call&#xff0c;遠程過程調用&#xff09;框架&#xff0c;由阿里巴巴開發并貢獻給了Apache基金會&#xff0c;成為Apache的頂級項目。Dubbo提供了RPC通信和服務治理的解決方案&#xff0c;使得構…

深入理解C語言中的變量和常量

變量和常量 1. 前言2. 預備知識2.1 printf和%d2.2 \n2.3 scanf2.4 scanf在vs中報錯2.5 extern2.6 數組的初始化 3. 變量和常量的區別4. 變量4.1 定義變量的方法4.2 變量的分類4.2.1 局部優先 4.3 變量的使用4.4 變量的作用域4.4.1 局部變量的作用域4.4.2 全局變量的作用域 4.5 …

機器學習|KNN和Kmeans

KNN和Kmeans KNN KNN-K個最近的鄰居&#xff0c;而K是可人先預設出來的。 所謂近朱者赤&#xff0c;近墨者黑。 可以選取離當前最近的K個樣本來作為輔助判斷&#xff0c;因為本樣本和最近的K個樣本應該是處于一種相似的狀態。 以下是一個蘋果和梨的識別任務。 圖上會出現一個未…