diff --git a/.gitignore b/.gitignore index 398eab0e..4d29626c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ $PROJECT_DIR/ # OS generated files .DS_Store + +# Jetbrains IDE +.idea/ diff --git a/ESP32_AP-Flasher/include/tag_db.h b/ESP32_AP-Flasher/include/tag_db.h index 5b7e065e..5798cf7f 100644 --- a/ESP32_AP-Flasher/include/tag_db.h +++ b/ESP32_AP-Flasher/include/tag_db.h @@ -73,6 +73,7 @@ struct Config { uint8_t sleepTime1; uint8_t sleepTime2; uint8_t ble; + uint8_t discovery; String repo; String env; }; diff --git a/ESP32_AP-Flasher/include/udp.h b/ESP32_AP-Flasher/include/udp.h index c76edcda..30e37347 100644 --- a/ESP32_AP-Flasher/include/udp.h +++ b/ESP32_AP-Flasher/include/udp.h @@ -1,26 +1,30 @@ #include #include "AsyncUDP.h" - +#include "tag_db.h" #ifndef defudpcomm #define defudpcomm +extern Config config; + class UDPcomm { - public: - UDPcomm(); - ~UDPcomm(); - void init(); - void getAPList(); - void netProcessDataReq(struct espAvailDataReq* eadr); - void netProcessXferComplete(struct espXferComplete* xfc); - void netProcessXferTimeout(struct espXferComplete* xfc); - void netSendDataAvail(struct pendingData* pending); - void netTaginfo(struct TagInfo* taginfoitem); - private: - AsyncUDP udp; - void processPacket(AsyncUDPPacket packet); + public: + UDPcomm(); + ~UDPcomm(); + void init(); + void getAPList(); + void netProcessDataReq(struct espAvailDataReq* eadr); + void netProcessXferComplete(struct espXferComplete* xfc); + void netProcessXferTimeout(struct espXferComplete* xfc); + void netSendDataAvail(struct pendingData* pending); + void netTaginfo(struct TagInfo* taginfoitem); + + private: + AsyncUDP udp; + void processPacket(AsyncUDPPacket packet); + void writeUdpPacket(uint8_t* buffer, uint16_t len, IPAddress senderIP); }; #endif -void init_udp(); \ No newline at end of file +void init_udp(); diff --git a/ESP32_AP-Flasher/src/tag_db.cpp b/ESP32_AP-Flasher/src/tag_db.cpp index 348d8bbb..5191f329 100644 --- a/ESP32_AP-Flasher/src/tag_db.cpp +++ b/ESP32_AP-Flasher/src/tag_db.cpp @@ -308,7 +308,7 @@ void clearPending(tagRecord* taginfo) { } void initAPconfig() { - DynamicJsonDocument APconfig(500); + DynamicJsonDocument APconfig(768); File configFile = contentFS->open("/current/apconfig.json", "r"); if (configFile) { DeserializationError error = deserializeJson(APconfig, configFile); @@ -333,6 +333,7 @@ void initAPconfig() { config.sleepTime1 = APconfig.containsKey("sleeptime1") ? APconfig["sleeptime1"] : 0; config.sleepTime2 = APconfig.containsKey("sleeptime2") ? APconfig["sleeptime2"] : 0; config.ble = APconfig.containsKey("ble") ? APconfig["ble"] : 0; + config.discovery = APconfig.containsKey("discovery") ? APconfig["discovery"] : 0; #ifdef BLE_ONLY config.ble = true; #endif @@ -370,6 +371,7 @@ void saveAPconfig() { APconfig["ble"] = config.ble; APconfig["repo"] = config.repo; APconfig["env"] = config.env; + APconfig["discovery"] = config.discovery; serializeJsonPretty(APconfig, configFile); configFile.close(); xSemaphoreGive(fsMutex); diff --git a/ESP32_AP-Flasher/src/udp.cpp b/ESP32_AP-Flasher/src/udp.cpp index 6502f5c9..f548b906 100644 --- a/ESP32_AP-Flasher/src/udp.cpp +++ b/ESP32_AP-Flasher/src/udp.cpp @@ -31,12 +31,22 @@ UDPcomm::~UDPcomm() { } void UDPcomm::init() { - if (udp.listenMulticast(UDPIP, UDPPORT)) { - udp.onPacket([this](AsyncUDPPacket packet) { - if (packet.remoteIP() != WiFi.localIP()) { - this->processPacket(packet); - } - }); + if (config.discovery == 0) { + if (udp.listenMulticast(UDPIP, UDPPORT)) { + udp.onPacket([this](AsyncUDPPacket packet) { + if (packet.remoteIP() != WiFi.localIP()) { + this->processPacket(packet); + } + }); + } + } else { + if (udp.listen(UDPPORT)) { + udp.onPacket([this](AsyncUDPPacket packet) { + if (packet.isBroadcast() && packet.remoteIP() != WiFi.localIP()) { + this->processPacket(packet); + } + }); + } } setAPchannel(); } @@ -87,7 +97,7 @@ void UDPcomm::processPacket(AsyncUDPPacket packet) { uint8_t buffer[sizeof(struct APlist) + 1]; buffer[0] = PKT_APLIST_REPLY; memcpy(buffer + 1, &APitem, sizeof(struct APlist)); - udp.writeTo(buffer, sizeof(buffer), senderIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), senderIP); break; } case PKT_APLIST_REPLY: { @@ -158,40 +168,48 @@ void UDPcomm::getAPList() { uint8_t buffer[sizeof(struct APlist) + 1]; buffer[0] = PKT_APLIST_REQ; memcpy(buffer + 1, &APitem, sizeof(struct APlist)); - udp.writeTo(buffer, sizeof(buffer), UDPIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), UDPIP); } void UDPcomm::netProcessDataReq(struct espAvailDataReq* eadr) { uint8_t buffer[sizeof(struct espAvailDataReq) + 1]; buffer[0] = PKT_AVAIL_DATA_INFO; memcpy(buffer + 1, eadr, sizeof(struct espAvailDataReq)); - udp.writeTo(buffer, sizeof(buffer), UDPIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), UDPIP); } void UDPcomm::netProcessXferComplete(struct espXferComplete* xfc) { uint8_t buffer[sizeof(struct espXferComplete) + 1]; buffer[0] = PKT_XFER_COMPLETE; memcpy(buffer + 1, xfc, sizeof(struct espXferComplete)); - udp.writeTo(buffer, sizeof(buffer), UDPIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), UDPIP); } void UDPcomm::netProcessXferTimeout(struct espXferComplete* xfc) { uint8_t buffer[sizeof(struct espXferComplete) + 1]; buffer[0] = PKT_XFER_TIMEOUT; memcpy(buffer + 1, xfc, sizeof(struct espXferComplete)); - udp.writeTo(buffer, sizeof(buffer), UDPIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), UDPIP); } void UDPcomm::netSendDataAvail(struct pendingData* pending) { uint8_t buffer[sizeof(struct pendingData) + 1]; buffer[0] = PKT_AVAIL_DATA_REQ; memcpy(buffer + 1, pending, sizeof(struct pendingData)); - udp.writeTo(buffer, sizeof(buffer), UDPIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), UDPIP); } void UDPcomm::netTaginfo(struct TagInfo* taginfoitem) { uint8_t buffer[sizeof(struct TagInfo) + 1]; buffer[0] = PKT_TAGINFO; memcpy(buffer + 1, taginfoitem, sizeof(struct TagInfo)); - udp.writeTo(buffer, sizeof(buffer), UDPIP, UDPPORT); + writeUdpPacket(buffer, sizeof(buffer), UDPIP); +} + +void UDPcomm::writeUdpPacket(uint8_t *buffer, uint16_t len, IPAddress senderIP) { + if (config.discovery == 0) { + udp.writeTo(buffer, len, senderIP, UDPPORT); + } else { + udp.broadcastTo(buffer, len, UDPPORT); + } } diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index ac937b1d..f724b7a5 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -312,7 +312,7 @@ void init_web() { Serial.println("getQueueItem: no queue item"); request->send(404, "text/plain", "File not found"); return; - } + } if (queueItem->data == nullptr) { fs::File file = contentFS->open(queueItem->filename); if (file) { @@ -517,7 +517,7 @@ void init_web() { udpsync.getAPList(); AsyncResponseStream *response = request->beginResponseStream("application/json"); - response->print("{"); + response->print("{"); #ifdef C6_OTA_FLASHING response->print("\"C6\": \"1\", "); #else @@ -625,6 +625,9 @@ void init_web() { setenv("TZ", config.timeZone, 1); tzset(); } + if (request->hasParam("discovery", true)) { + config.discovery = static_cast(request->getParam("discovery", true)->value().toInt()); + } if (request->hasParam("repo", true)) { config.repo = request->getParam("repo", true)->value(); } @@ -988,4 +991,4 @@ void dotagDBUpload(AsyncWebServerRequest *request, String filename, size_t index loadDB("/current/tagDBrestored.json"); request->send(200, "text/plain", "Ok, restored."); } -} \ No newline at end of file +} diff --git a/ESP32_AP-Flasher/wwwroot/index.html b/ESP32_AP-Flasher/wwwroot/index.html index b30ab625..e856ce32 100644 --- a/ESP32_AP-Flasher/wwwroot/index.html +++ b/ESP32_AP-Flasher/wwwroot/index.html @@ -234,7 +234,7 @@

Mode



- With automatic flash, a tag is flashed to the latest firmware as soon as you connect it. + With automatic flash, a tag is flashed to the latest firmware as soon as you connect it. It sets the mac automatically, tries to recognize the type, and starts flashing. Currently, Solum M2 tags only.



@@ -375,7 +375,7 @@ options:

@@ -400,7 +400,7 @@ options:

+

+ + +

diff --git a/ESP32_AP-Flasher/wwwroot/main.js b/ESP32_AP-Flasher/wwwroot/main.js index 19132aa6..af85726a 100644 --- a/ESP32_AP-Flasher/wwwroot/main.js +++ b/ESP32_AP-Flasher/wwwroot/main.js @@ -784,6 +784,7 @@ document.addEventListener("loadTab", function (event) { $("#apctimezone").value = data.timezone; $("#apcnight1").value = data.sleeptime1; $("#apcnight2").value = data.sleeptime2; + $("#apcdiscovery").value = data.discovery; } }) $('#apcfgmsg').innerHTML = ''; @@ -821,7 +822,7 @@ $('#apcfgsave').onclick = function () { formData.append('timezone', $('#apctimezone').value); formData.append('sleeptime1', $('#apcnight1').value); formData.append('sleeptime2', $('#apcnight2').value); - + formData.append('discovery', $('#apcdiscovery').value) fetch("save_apcfg", { method: "POST", body: formData