首页
ESP32系列
ESP32-S2
ESP32-S2模拟HID鼠标键盘
ESP32编程
Web控制ESP32-S2模拟HID鼠标
ESP32简介
ESP32驱动WS2812灯
本文档由 内网文摘 发布,转载请注明出处
-
+
首页
Web控制ESP32-S2模拟HID鼠标
```cpp /* ESP32 Web Server - STA Mode 从web控制的模拟HID鼠标移动 localnetwork.cn */ #include <WiFi.h> #include <WebServer.h> #include "hidcomposite.h" HIDcomposite device; // SSID & Password const char* ssid = "a1"; // Enter your SSID here const char* password = "12345678"; //Enter your Password here WebServer server(80); // Object of WebServer(HTTP port, 80 is defult) void setup() { Serial.begin(9600); Serial.println("Try Connecting to "); Serial.println(ssid); device.begin(); // Connect to your wi-fi modem WiFi.begin(ssid, password); // Check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected successfully"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); //Show ESP32 IP on serial server.on("/", HTTP_GET, handle_root); server.on("/2", HTTP_GET, handle_root2); server.on("/hid_u", HTTP_POST, hid_u); server.on("/hid_d", HTTP_POST, hid_d); server.on("/hid_l", HTTP_POST, hid_l); server.on("/hid_r", HTTP_POST, hid_r); server.begin(); Serial.println("HTTP server started"); delay(100); } void loop() { server.handleClient(); } // HTML & CSS contents which display on web server String HTML = "<!DOCTYPE html>\ <html>\ <body>\ <h1>My First Web Server with ESP32 - Station Mode</h1>\ </body>\ </html>"; // Handle root url (/) void handle_root() { server.send(200, "text/html", HTML); } //控制上下左右网页 String HTML2 = "<form action=\"/hid_u\" method=\"POST\"><input type=\"submit\" value=\"Toggle LED\"></form><form action=\"/hid_d\" method=\"POST\"><input type=\"submit\" value=\"Toggle LEDYellow\"></form><form action=\"/hid_l\" method=\"POST\"><input type=\"submit\" value=\"Toggle LEDWhite\"></form><form action=\"/hid_r\" method=\"POST\"><input type=\"submit\" value=\"Toggle LEDBlue\"></form>"; void handle_root2() { server.send(200, "text/html", HTML2); } void hid_u() { Serial.println("执行上移"); device.move(0, 150); //move移动 server.send(200, "text/html", HTML2); } void hid_d() { Serial.println("执行下移"); device.move(0, -150); //move移动 server.send(200, "text/html", HTML2); } void hid_l() { Serial.println("执行左移"); device.move(150, 0); //move移动 server.send(200, "text/html", HTML2); } void hid_r() { Serial.println("执行右移"); device.move(-150, 0); //move移动 server.send(200, "text/html", HTML2); } ```
local
2021年11月15日 11:24
分享文档
收藏文档
上一篇
下一篇
微信扫一扫
复制链接
手机扫一扫进行分享
复制链接
关于 LocalNetwork
LocalNetwork
是由mrdoc开源
LocalNetwork.cn
修改的在线文档系统,作为个人和小型团队的云笔记、文档和知识库管理工具。
如果此文档给你或你的团队带来了帮助,欢迎支持作者持续投入精力更新和维护!内网文摘 & LocalNetwork
>>>主页
logo
logo
下载Markdown文件
分享
链接
类型
密码
更新密码