每10s刷新wifi
This commit is contained in:
@ -114,23 +114,31 @@ void TJC_Show::showInfo() {
|
|||||||
sendCommand(str);
|
sendCommand(str);
|
||||||
|
|
||||||
// === wifi 页面信息 ===
|
// === wifi 页面信息 ===
|
||||||
char addr[64];
|
static unsigned long lastWiFiUpdateTime = 0; // 静态局部变量,保持状态
|
||||||
IPAddress ip;
|
const unsigned long wifiUpdateInterval = 10000; // 10秒更新间隔
|
||||||
|
|
||||||
if (WiFi.getMode() == WIFI_AP) { // AP模式
|
unsigned long currentTime = millis();
|
||||||
ip = WiFi.softAPIP();
|
if (currentTime - lastWiFiUpdateTime >= wifiUpdateInterval) {
|
||||||
snprintf(addr, sizeof(addr), "wifi.t0.txt=\"AP:%d.%d.%d.%d\"\xff\xff\xff", ip[0], ip[1], ip[2], ip[3]);
|
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);
|
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模式
|
lastWiFiUpdateTime = currentTime; // 更新最后更新时间
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
// void TJC_Show::processSerial() {
|
// void TJC_Show::processSerial() {
|
||||||
// #define FRAME_LENGTH 10
|
// #define FRAME_LENGTH 10
|
||||||
|
|||||||
@ -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>";
|
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);
|
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){
|
server.on("/data", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
//StaticJsonDocument<256> doc;
|
//StaticJsonDocument<256> doc;
|
||||||
@ -217,6 +217,12 @@ void WebServer_Init(void) {
|
|||||||
String json;
|
String json;
|
||||||
serializeJson(doc, json);
|
serializeJson(doc, json);
|
||||||
request->send(200, "application/json", 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值
|
// 设置Wiper值
|
||||||
|
|||||||
Reference in New Issue
Block a user