From a2f2124869f532581744f53b01b645fe4b2d2a26 Mon Sep 17 00:00:00 2001 From: chenxin Date: Tue, 1 Jul 2025 11:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F10s=E5=88=B7=E6=96=B0wifi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TJC_Show.cpp | 36 ++++++++++++++++++++++-------------- src/main.cpp | 8 +++++++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/TJC_Show.cpp b/src/TJC_Show.cpp index 724547e..0c04dcf 100644 --- a/src/TJC_Show.cpp +++ b/src/TJC_Show.cpp @@ -114,23 +114,31 @@ void TJC_Show::showInfo() { sendCommand(str); // === wifi 页面信息 === - char addr[64]; - IPAddress ip; + static unsigned long lastWiFiUpdateTime = 0; // 静态局部变量,保持状态 + const unsigned long wifiUpdateInterval = 10000; // 10秒更新间隔 + + unsigned long currentTime = millis(); + if (currentTime - lastWiFiUpdateTime >= wifiUpdateInterval) { + char addr[64]; + IPAddress ip; - if (WiFi.getMode() == WIFI_AP) { // AP模式 - ip = WiFi.softAPIP(); - snprintf(addr, sizeof(addr), "wifi.t0.txt=\"AP:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); + if (WiFi.getMode() == WIFI_AP) { // AP模式 + ip = WiFi.softAPIP(); + snprintf(addr, sizeof(addr), "wifi.t0.txt=\"AP:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); + sendCommand(addr); + //Serial.printf("wifi.t0.txt=\"AP:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); + } else if (WiFi.getMode() == WIFI_STA) { // STA模式 + ip = WiFi.localIP(); + snprintf(addr, sizeof(addr), "wifi.t0.txt=\"STA:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); + sendCommand(addr); + //Serial.printf("wifi.t0.txt=\"STA:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); + } + + snprintf(addr, sizeof(addr), "wifi.qr0.txt=\"http://%d.%d.%d.%d/\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); sendCommand(addr); - //Serial.printf("wifi.t0.txt=\"AP:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); - } else if (WiFi.getMode() == WIFI_STA) { // STA模式 - ip = WiFi.localIP(); - snprintf(addr, sizeof(addr), "wifi.t0.txt=\"STA:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); - sendCommand(addr); - //Serial.printf("wifi.t0.txt=\"STA:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); + + lastWiFiUpdateTime = currentTime; // 更新最后更新时间 } - - snprintf(addr, sizeof(addr), "wifi.qr0.txt=\"http://%d.%d.%d.%d/\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]); - sendCommand(addr); } // void TJC_Show::processSerial() { // #define FRAME_LENGTH 10 diff --git a/src/main.cpp b/src/main.cpp index f719f2c..e4cc526 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -198,7 +198,7 @@ void WebServer_Init(void) { String response = "

Configuration Received

Please wait while the device connects to WiFi...

"; request->send(200, "text/html", response); }); - +// int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData); // 合并数据接口 server.on("/data", HTTP_GET, [](AsyncWebServerRequest *request){ //StaticJsonDocument<256> doc; @@ -217,6 +217,12 @@ void WebServer_Init(void) { String json; serializeJson(doc, json); request->send(200, "application/json", json); + // uint8_t *bufferfosend; + // int lentofpack=IRIS_Protocol_Pack(0x00, json.length(), (uint8_t*)json.c_str(),bufferfosend); + // Serial1.write(bufferfosend,lentofpack); + // delete[] bufferfosend; + + }); // 设置Wiper值