diff --git a/data/index.json b/data/index.json index 1b6413ad..0f12c670 100644 --- a/data/index.json +++ b/data/index.json @@ -23,12 +23,6 @@ "action": "/?set.device", "class": "btn btn-block btn-default" }, - { - "type": "link", - "title": "Список других устройств в сети", - "action": "/?set.udp", - "class": "btn btn-block btn-default" - }, { "type": "link", "title": "Конфигурация WIFI", diff --git a/include/udp_.h b/include/udp_.h deleted file mode 100644 index 6583878c..00000000 --- a/include/udp_.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -extern void udpInit(); -extern bool isUdpEnabled(); -extern void loopUdp(); -extern void handleUdp_esp32(); -extern void do_udp_data_parse(); -extern void add_dev_in_list(String filename, String id, String dev_name, String ip); -extern void send_mqtt_to_udp(); \ No newline at end of file diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index e4255cb7..aee15885 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -45,7 +45,7 @@ void spaceCmdExecute(String &cmdStr) { void loopCmdExecute() { if (orderBuf.length()) { String tmp = selectToMarker(orderBuf, ","); //выделяем первую команду rel 5 1, - SerialPrint("I","module","do: " + tmp); + SerialPrint("I","CMD","do: " + tmp); sCmd.readStr(tmp); //выполняем orderBuf = deleteBeforeDelimiter(orderBuf, ","); //осекаем } diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp index baa82d6d..5d7fe2ba 100644 --- a/src/Utils/FileUtils.cpp +++ b/src/Utils/FileUtils.cpp @@ -9,7 +9,7 @@ const String filepath(const String& filename) { bool fileSystemInit() { if (!LittleFS.begin()) { - SerialPrint("[E]","module","init"); + SerialPrint("[E]","Files","init"); return false; } return true; @@ -19,10 +19,10 @@ void removeFile(const String& filename) { String path = filepath(filename); if (LittleFS.exists(path)) { if (!LittleFS.remove(path)) { - SerialPrint("[E]","module","remove " + path); + SerialPrint("[E]","Files","remove " + path); } } else { - SerialPrint("I","module","not exist" + path); + SerialPrint("I","Files","not exist" + path); } } @@ -30,7 +30,7 @@ File seekFile(const String& filename, size_t position) { String path = filepath(filename); auto file = LittleFS.open(path, "r"); if (!file) { - SerialPrint("[E]","module","open " + path); + SerialPrint("[E]","Files","open " + path); } // поставим курсор в начало файла file.seek(position, SeekSet); @@ -76,14 +76,14 @@ const String addFile(const String& filename, const String& str) { bool copyFile(const String& src, const String& dst, bool overwrite) { String srcPath = filepath(src); String dstPath = filepath(dst); - SerialPrint("I","module","copy " + srcPath + " to " + dstPath); + SerialPrint("I","Files","copy " + srcPath + " to " + dstPath); if (!LittleFS.exists(srcPath)) { - SerialPrint("[E]","module","not exist: " + srcPath); + SerialPrint("[E]","Files","not exist: " + srcPath); return false; } if (LittleFS.exists(dstPath)) { if (!overwrite) { - SerialPrint("[E]","module","already exist: " + dstPath); + SerialPrint("[E]","Files","already exist: " + dstPath); return false; } LittleFS.remove(dstPath); diff --git a/src/Utils/SysUtils.cpp b/src/Utils/SysUtils.cpp index c2713a63..48704aea 100644 --- a/src/Utils/SysUtils.cpp +++ b/src/Utils/SysUtils.cpp @@ -24,7 +24,7 @@ const String getChipId() { void setChipId() { chipId = getChipId(); - SerialPrint("I","module","id: " + chipId); + SerialPrint("I","System","id: " + chipId); } #ifdef ESP8266 diff --git a/src/Web.cpp b/src/Web.cpp index ed391616..570ec3ef 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -272,6 +272,7 @@ void web_init() { } else if (lastVersion == -2) { msg = F("Устройство не подключено к роутеру!"); } + // else if (lastVersion == "") { //msg = F("Нажмите на кнопку \"обновить прошивку\" повторно..."); //} else if (lastVersion == "less") { diff --git a/src/WebServer.cpp b/src/WebServer.cpp index 9a8e7df0..810a1add 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -29,17 +29,17 @@ void init() { server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str()); server.onNotFound([](AsyncWebServerRequest *request) { - SerialPrint("[E]","module","not found:\n" + getRequestInfo(request)); + SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request)); request->send(404); }); server.onFileUpload([](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) { // TODO if (!index) { - SerialPrint("I","module","start upload " + filename); + SerialPrint("I","WebServer","start upload " + filename); } if (final) { - SerialPrint("I","module","finish upload: " + prettyBytes(index + len)); + SerialPrint("I","WebServer","finish upload: " + prettyBytes(index + len)); } }); @@ -60,7 +60,7 @@ void init() { server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest *request) { String cmdStr = request->getParam("command")->value(); - SerialPrint("I","module","do: " + cmdStr); + SerialPrint("I","WebServer","do: " + cmdStr); loopCmdAdd(cmdStr); request->send(200, "text/html", "OK"); }); diff --git a/src/Widgets.cpp b/src/Widgets.cpp index 32e1285d..13c58db1 100644 --- a/src/Widgets.cpp +++ b/src/Widgets.cpp @@ -7,7 +7,7 @@ bool loadWidget(const String& filename, String& buf) { buf = readFile(getWidgetFile(filename), 2048); bool res = !(buf == "Failed" || buf == "Large"); if (!res) { - SerialPrint("[E]","module","on load" + filename); + SerialPrint("[E]","Widgets","on load" + filename); } return res; } diff --git a/src/main.cpp b/src/main.cpp index 9022ead4..c2056a34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,49 +35,45 @@ void setup() { myNotAsincActions = new NotAsinc(do_LAST); myScenario = new Scenario(); - SerialPrint("I","FS","FS"); + SerialPrint("I","FS","FS Init"); fileSystemInit(); - SerialPrint("I","Conf","Config"); + SerialPrint("I","Conf","Config Init"); loadConfig(); - SerialPrint("I","Time","Clock"); + SerialPrint("I","Time","Clock Init"); clock_init(); - SerialPrint("I","CMD","Commands"); + SerialPrint("I","CMD","Commands Init"); cmd_init(); - SerialPrint("I","Sensors","Sensors"); + SerialPrint("I","Sensors","Sensors Init"); sensorsInit(); - SerialPrint("I","Init","Init"); + SerialPrint("I","Init","Init Init"); all_init(); - SerialPrint("I","WIFI","Network"); + SerialPrint("I","WIFI","Network Init"); startSTAMode(); - SerialPrint("I","Uptime","Uptime"); + SerialPrint("I","Uptime","Uptime Init"); uptime_init(); - SerialPrint("I","Update","Updater"); + SerialPrint("I","Update","Updater Init"); upgradeInit(); - SerialPrint("I","HTTP","HttpServer"); + SerialPrint("I","HTTP","HttpServer Init"); HttpServer::init(); - SerialPrint("I","Web","WebAdmin"); + SerialPrint("I","Web","WebAdmin Init"); web_init(); - SerialPrint("I","Stat","InitSt"); + SerialPrint("I","Stat","Stat Init"); initSt(); - SerialPrint("I","UDP","asyncUdpInit"); + SerialPrint("I","UDP","Udp Init"); asyncUdpInit(); - -#ifdef UDP_ENABLED - SerialPrint("I","module","Broadcast UDP"); - udpInit(); -#endif + #ifdef SSDP_EN SerialPrint("I","SSDP","Ssdp Init"); SsdpInit(); diff --git a/src/udp_.cpp b/src/udp_.cpp deleted file mode 100644 index d605eb6d..00000000 --- a/src/udp_.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#include "Class/NotAsinc.h" -#include "udp.h" -#include "udp_.h" -#include "Global.h" - - -#ifdef ESP8266 -IPAddress udp_multicastIP(255, 255, 255, 255); -WiFiUDP udp; -#endif -#ifdef ESP32 -IPAddress udp_multicastIP(239, 255, 255, 255); -AsyncUDP udp; -#endif -String remote_ip; -String received; -int udp_period; -boolean udp_busy = false; -unsigned int udp_port = 4210; - - -#ifdef UDP_ENABLED -void udpInit() { - myNotAsincActions->add( - do_UDPDATAPARSE, [&](void*) { - do_udp_data_parse(); - }, - nullptr); - - myNotAsincActions->add( - do_MQTTUDP, [&](void*) { - send_mqtt_to_udp(); - }, - nullptr); - - removeFile("dev.csv"); - addFileLn("dev.csv", "device id;device name;ip address"); - -#ifdef ESP8266 - udp.begin(udp_port); -#endif - - handleUdp_esp32(); - - randomSeed(micros()); - udp_period = random(50000, 60000); - - ts.add( - UDP, udp_period, [&](void*) { - if (jsonReadBool(configSetupJson, "udponoff") && isNetworkActive() && !udp_busy) { - SerialPrint("I","module","send info"); - String payload = "iotm;"; - payload += chipId; - payload += ";"; - payload += jsonReadStr(configSetupJson, "name"); -#ifdef ESP8266 - udp.beginPacketMulticast(udp_multicastIP, udp_port, WiFi.localIP()); - udp.write(payload.c_str()); - udp.endPacket(); -#endif -#ifdef ESP32 - udp.broadcast(line_to_send.c_str()); -#endif - } - }, - nullptr, false); -} - -bool isUdpEnabled() { - return jsonReadBool(configSetupJson, "udponoff") && isNetworkActive(); -} - -void loopUdp() { -#ifdef ESP8266 - if (!isUdpEnabled()) { - return; - } - - int packetSize = udp.parsePacket(); - if (!packetSize) { - return; - } - - char udp_packet[255]; - remote_ip = udp.remoteIP().toString(); - - SerialPrint("I","module",prettyBytes(packetSize) + " from " + remote_ip + ":" + udp.remotePort()); - - int len = udp.read(udp_packet, 255); - if (len) { - udp_packet[len] = '\x00'; - } - received = String(udp_packet); - if (received.indexOf("iotm;") >= 0 || received.indexOf("mqttServer") >= 0) { - myNotAsincActions->make(do_UDPDATAPARSE); - } -#endif - ; -} - -void handleUdp_esp32() { -#ifdef ESP32 - if (udp.listenMulticast(udp_multicastIP, udp_port)) { - udp.onPacket([](AsyncUDPPacket packet) { - received = (char*)packet.data(); - remote_ip = packet.remoteIP().toString(); - if (jsonReadStr(configSetupJson, "udponoff") == "1") { - if (received.indexOf("iotm;") >= 0) { - myNotAsincActions->make(do_UDPDATAPARSE); - } - if (received.indexOf("mqttServer") >= 0) { - myNotAsincActions->make(do_UDPDATAPARSE); - } - } - }); - } -#endif -} - -void do_udp_data_parse() { - if (received.indexOf("mqttServer") >= 0) { - SerialPrint("I","module","received setting"); - jsonWriteStr(configSetupJson, "mqttServer", jsonReadStr(received, "mqttServer")); - jsonWriteInt(configSetupJson, "mqttPort", jsonReadInt(received, "mqttPort")); - jsonWriteStr(configSetupJson, "mqttPrefix", jsonReadStr(received, "mqttPrefix")); - jsonWriteStr(configSetupJson, "mqttUser", jsonReadStr(received, "mqttUser")); - jsonWriteStr(configSetupJson, "mqttPass", jsonReadStr(received, "mqttPass")); - saveConfig(); - myNotAsincActions->make(do_MQTTPARAMSCHANGED); - } - if (received.indexOf("iotm;") >= 0) { - add_dev_in_list("dev.csv", selectFromMarkerToMarker(received, ";", 1), selectFromMarkerToMarker(received, ";", 2), received); - } -} - -void add_dev_in_list(String filename, String id, String dev_name, String ip) { - auto file = seekFile("/" + filename); - if (!file.find(id.c_str())) { - addFileLn(filename, id + ";" + dev_name + "; " + ip + ""); - } -} - -void send_mqtt_to_udp() { - if (!isUdpEnabled()) { - return; - } - udp_busy = true; - String data = "{}"; - jsonWriteStr(data, "mqttServer", jsonReadStr(configSetupJson, "mqttServer")); - jsonWriteInt(data, "mqttPort", jsonReadInt(configSetupJson, "mqttPort")); - jsonWriteStr(data, "mqttPrefix", jsonReadStr(configSetupJson, "mqttPrefix")); - jsonWriteStr(data, "mqttUser", jsonReadStr(configSetupJson, "mqttUser")); - jsonWriteStr(data, "mqttPass", jsonReadStr(configSetupJson, "mqttPass")); -#ifdef ESP8266 - udp.beginPacketMulticast(udp_multicastIP, udp_port, WiFi.localIP()); - udp.write(data.c_str()); - udp.endPacket(); -#endif -#ifdef ESP32 - udp.broadcast(mqtt_data.c_str()); -#endif - SerialPrint("I","module","sent info"); - udp_busy = false; -} - -#endif \ No newline at end of file