每10s刷新wifi

This commit is contained in:
2025-07-01 11:37:53 +08:00
parent 14bcb9f34b
commit a2f2124869
2 changed files with 29 additions and 15 deletions

View File

@ -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秒更新间隔
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]);
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]);
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

View File

@ -198,7 +198,7 @@ void WebServer_Init(void) {
String response = "<!DOCTYPE html><html><body><h2>Configuration Received</h2><p>Please wait while the device connects to WiFi...</p></body></html>";
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值