diff --git a/ESP32_AP-Flasher/include/newproto.h b/ESP32_AP-Flasher/include/newproto.h index 90a95986..8b6abcce 100644 --- a/ESP32_AP-Flasher/include/newproto.h +++ b/ESP32_AP-Flasher/include/newproto.h @@ -16,7 +16,7 @@ extern void processDataReq(struct espAvailDataReq* adr, bool local); extern bool sendTagCommand(const uint8_t* dst, uint8_t cmd, bool local); extern bool sendAPSegmentedData(const uint8_t* dst, String data, uint16_t icons, bool inverted, bool local); extern bool showAPSegmentedInfo(const uint8_t* dst, bool local); -extern void updateTaginfoitem(struct TagInfo* taginfoitem); +extern void updateTaginfoitem(struct TagInfo* taginfoitem, IPAddress remoteIP); bool checkMirror(struct tagRecord* taginfo, struct pendingData* pending); void refreshAllPending(); diff --git a/ESP32_AP-Flasher/include/ota.h b/ESP32_AP-Flasher/include/ota.h index 5754c798..5bbce278 100644 --- a/ESP32_AP-Flasher/include/ota.h +++ b/ESP32_AP-Flasher/include/ota.h @@ -4,7 +4,6 @@ void handleSysinfoRequest(AsyncWebServerRequest* request); void handleCheckFile(AsyncWebServerRequest* request); -void handleGetExtUrl(AsyncWebServerRequest* request); void handleLittleFSUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final); void handleUpdateOTA(AsyncWebServerRequest* request); void firmwareUpdateTask(void* parameter); diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp index 357edea9..11b315a3 100644 --- a/ESP32_AP-Flasher/src/main.cpp +++ b/ESP32_AP-Flasher/src/main.cpp @@ -140,7 +140,6 @@ void setup() { updateBrightnessFromConfig(); init_web(); - init_udp(); #ifdef HAS_RGB_LED rgbIdle(); diff --git a/ESP32_AP-Flasher/src/newproto.cpp b/ESP32_AP-Flasher/src/newproto.cpp index f759c09a..47b7af5e 100644 --- a/ESP32_AP-Flasher/src/newproto.cpp +++ b/ESP32_AP-Flasher/src/newproto.cpp @@ -324,8 +324,8 @@ void prepareExternalDataAvail(struct pendingData* pending, IPAddress remoteIP) { return; } } - taginfo->contentMode = 12; - taginfo->nextupdate = 3216153600; + // taginfo->contentMode = 12; + // taginfo->nextupdate = 3216153600; checkMirror(taginfo, pending); sendDataAvail(pending); @@ -616,7 +616,7 @@ bool sendTagCommand(const uint8_t* dst, uint8_t cmd, bool local) { } } -void updateTaginfoitem(struct TagInfo* taginfoitem) { +void updateTaginfoitem(struct TagInfo* taginfoitem, IPAddress remoteIP) { tagRecord* taginfo = tagRecord::findByMAC(taginfoitem->mac); if (taginfo == nullptr) { @@ -647,7 +647,7 @@ void updateTaginfoitem(struct TagInfo* taginfoitem) { char hexmac[17]; mac2hex(taginfo->mac, hexmac); if (taginfo->contentMode != 12 && taginfoitem->contentMode != 12) { - wsLog("Remote AP takes control over tag " + String(hexmac)); + wsLog("Remote AP at " + remoteIP.toString() + " takes control over tag " + String(hexmac)); taginfo->contentMode = 12; } diff --git a/ESP32_AP-Flasher/src/ota.cpp b/ESP32_AP-Flasher/src/ota.cpp index c3aff0b8..f899622c 100644 --- a/ESP32_AP-Flasher/src/ota.cpp +++ b/ESP32_AP-Flasher/src/ota.cpp @@ -81,35 +81,6 @@ void handleCheckFile(AsyncWebServerRequest* request) { request->send(200, "application/json", jsonResponse); } -void handleGetExtUrl(AsyncWebServerRequest* request) { - if (request->hasParam("url")) { - const String url = request->getParam("url")->value(); - HTTPClient http; - http.begin(url); - http.setConnectTimeout(5000); - http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); - const int httpResponseCode = http.GET(); - if (httpResponseCode > 0) { - Serial.println(httpResponseCode); - const String contentType = http.header("Content-Type"); - const size_t contentLength = http.getSize(); - if (contentLength > 0) { - String content = http.getString(); - AsyncWebServerResponse* response = request->beginResponse(200, contentType, content); - request->send(response); - } else { - request->send(500, "text/plain", "no size header"); - } - } else { - request->send(httpResponseCode, "text/plain", "Failed to fetch URL"); - wsSerial(http.errorToString(httpResponseCode)); - } - http.end(); - } else { - request->send(400, "text/plain", "Missing 'url' parameter"); - } -} - void handleLittleFSUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final) { bool error = false; if (!index) { diff --git a/ESP32_AP-Flasher/src/udp.cpp b/ESP32_AP-Flasher/src/udp.cpp index bfa1ffe4..ac73ac30 100644 --- a/ESP32_AP-Flasher/src/udp.cpp +++ b/ESP32_AP-Flasher/src/udp.cpp @@ -43,6 +43,7 @@ void UDPcomm::init() { void UDPcomm::processPacket(AsyncUDPPacket packet) { if (config.runStatus == RUNSTATUS_STOP) return; + IPAddress senderIP = packet.remoteIP(); switch (packet.data()[0]) { case PKT_AVAIL_DATA_INFO: { @@ -70,12 +71,10 @@ void UDPcomm::processPacket(AsyncUDPPacket packet) { pendingData pending; memset(&pending, 0, sizeof(pendingData)); memcpy(&pending, &packet.data()[1], std::min(packet.length() - 1, sizeof(pendingData))); - prepareExternalDataAvail(&pending, packet.remoteIP()); + prepareExternalDataAvail(&pending, senderIP); break; } case PKT_APLIST_REQ: { - IPAddress senderIP = packet.remoteIP(); - APlist APitem; APitem.src = WiFi.localIP(); strcpy(APitem.alias, config.alias); @@ -103,10 +102,10 @@ void UDPcomm::processPacket(AsyncUDPPacket packet) { case PKT_TAGINFO: { uint16_t syncversion = (packet.data()[2] << 8) | packet.data()[1]; if (syncversion != SYNC_VERSION) { - wsErr("Got a packet from " + packet.remoteIP().toString() + " with mismatched udp sync version. Update firmware!"); + wsErr("Got a packet from " + senderIP.toString() + " with mismatched udp sync version. Update firmware!"); } else { TagInfo* taginfoitem = (TagInfo*)&packet.data()[1]; - updateTaginfoitem(taginfoitem); + updateTaginfoitem(taginfoitem, senderIP); } } } diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index ae2b85cf..d87ecabb 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -497,7 +497,6 @@ void init_web() { server.on("/sysinfo", HTTP_GET, handleSysinfoRequest); server.on("/check_file", HTTP_GET, handleCheckFile); - server.on("/getexturl", HTTP_GET, handleGetExtUrl); server.on("/rollback", HTTP_POST, handleRollback); server.on("/update_actions", HTTP_POST, handleUpdateActions); server.on("/update_ota", HTTP_POST, [](AsyncWebServerRequest *request) { diff --git a/ESP32_AP-Flasher/src/wifimanager.cpp b/ESP32_AP-Flasher/src/wifimanager.cpp index 038411dc..86ffc9d5 100644 --- a/ESP32_AP-Flasher/src/wifimanager.cpp +++ b/ESP32_AP-Flasher/src/wifimanager.cpp @@ -200,6 +200,7 @@ void WifiManager::WiFiEvent(WiFiEvent_t event) { break; case ARDUINO_EVENT_WIFI_STA_GOT_IP: eventname = "Obtained IP address: " + String(WiFi.localIP().toString().c_str()); + init_udp(); break; case ARDUINO_EVENT_WIFI_STA_LOST_IP: eventname = "Lost IP address and IP address is reset to 0"; diff --git a/ESP32_AP-Flasher/wwwroot/index.html b/ESP32_AP-Flasher/wwwroot/index.html index b52214a4..2ba962c9 100644 --- a/ESP32_AP-Flasher/wwwroot/index.html +++ b/ESP32_AP-Flasher/wwwroot/index.html @@ -243,7 +243,7 @@ to save file system space">