欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 闪电麦昆 语音控制齿轮行进轨迹,ESP32搭配语音控制板,串口通信,附视频演示地址

闪电麦昆 语音控制齿轮行进轨迹,ESP32搭配语音控制板,串口通信,附视频演示地址

2025/4/20 11:19:35 来源:https://blog.csdn.net/github_35631540/article/details/140189789  浏览:    关键词:闪电麦昆 语音控制齿轮行进轨迹,ESP32搭配语音控制板,串口通信,附视频演示地址

演示地址 https://www.bilibili.com/video/BV1cW421d79L/?vd_source=b8515e53f6d4c564b541d98dcc9df990

语音控制板的配置
在这里插入图片描述

web展示页面
在这里插入图片描述

esp32 程序

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <LittleFS.h>
#include <WebSocketsServer.h>ESP8266WebServer server(80);
WebSocketsServer webSocket = WebSocketsServer(81); // WebSocket服务器在端口81上运行void setup() {Serial.begin(115200);WiFi.softAP("ESP8266-AP", "12345678");// 初始化LittleFSif (!LittleFS.begin()) {Serial.println("An Error has occurred while mounting LittleFS");return;}server.on("/", HTTP_GET, handleRoot);server.on("/paper-full.min.js", HTTP_GET, handleJS);server.on("/chilun.svg", HTTP_GET, handleSVG); // 添加路由处理SVG请求server.begin();Serial.println("HTTP server started");webSocket.begin(); // 启动WebSocket服务器webSocket.onEvent(webSocketEvent); // 注册WebSocket事件处理函数
}void handleRoot() {File file = LittleFS.open("/index.html", "r");if (!file) {Serial.println("File not found");return;}server.streamFile(file, "text/html");file.close();
}void handleJS() {File file = LittleFS.open("/paper-full.min.js", "r"); // 打开JavaScript文件if (!file) {Serial.println("File not found");return;}server.streamFile(file, "application/javascript"); // 确保MIME类型是正确的file.close();
}// 处理SVG文件的请求
void handleSVG() {File file = LittleFS.open("/chilun.svg", "r");if (!file) {Serial.println("File not found");return;}server.streamFile(file, "image/svg+xml"); // 确保MIME类型设置为SVGfile.close();
}// WebSocket事件处理函数
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {switch(type) {case WStype_DISCONNECTED:Serial.printf("[%u] Disconnected!\n", num);break;case WStype_CONNECTED:{IPAddress ip = webSocket.remoteIP(num);Serial.printf("[%u] Connected from %d.%d.%d.%d\n", num, ip[0], ip[1], ip[2], ip[3]);webSocket.sendTXT(num, "Hello from ESP8266"); // 向连接的客户端发送消息}break;case WStype_TEXT:{Serial.printf("[%u] Received Text: %s\n", num, payload);// 将接收到的消息广播给所有连接的客户端String message = String((char *)payload); // 将payload转换为String对象,以便处理webSocket.broadcastTXT(message); // 使用broadcastTXT直接广播消息}}
}void loop() {server.handleClient();webSocket.loop(); // 确保处理WebSocket事件// 检查串口是否有数据读取if (Serial.available() > 0) {String data = Serial.readString(); // 读取串口数据Serial.print("Received from Serial: "); // 打印接收到的消息Serial.println(data); // 显示串口接收到的数据webSocket.broadcastTXT(data); // 将读取到的数据发送给所有WebSocket客户端}
}

在这里插入图片描述

参考资料
https://github.com/earlephilhower/arduino-littlefs-upload

https://github.com/earlephilhower/arduino-esp8266littlefs-plugin

https://github.com/lorol/arduino-esp32fs-plugin

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词