From d9ab7ed1b7f57a27843bde598397ff871973f710 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Mon, 7 Feb 2022 16:36:29 +0100 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D1=83?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=B9=D1=81=D1=82=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/DeviceList.h | 4 ++++ include/Main.h | 1 + src/DeviceList.cpp | 11 +++++++++++ src/EspFileSystem.cpp | 1 + src/Global.cpp | 2 +- src/Main.cpp | 4 ++++ src/WsServer.cpp | 4 ++-- 7 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 include/DeviceList.h create mode 100644 src/DeviceList.cpp diff --git a/include/DeviceList.h b/include/DeviceList.h new file mode 100644 index 00000000..72843876 --- /dev/null +++ b/include/DeviceList.h @@ -0,0 +1,4 @@ +#pragma once +#include "Global.h" + +extern void addThisDeviceToList(); \ No newline at end of file diff --git a/include/Main.h b/include/Main.h index 56ff622b..5ad5f68f 100644 --- a/include/Main.h +++ b/include/Main.h @@ -9,3 +9,4 @@ #include "ESPConfiguration.h" #include "MqttClient.h" #include "WsServer.h" +#include "DeviceList.h" diff --git a/src/DeviceList.cpp b/src/DeviceList.cpp new file mode 100644 index 00000000..f49d892f --- /dev/null +++ b/src/DeviceList.cpp @@ -0,0 +1,11 @@ +#include "DeviceList.h" + +void addThisDeviceToList() { + jsonWriteStr_(devListJson, "devicelist", "devicelist"); + jsonWriteStr_(devListJson, "ip", jsonReadStr(settingsFlashJson, "ip")); + jsonWriteStr_(devListJson, "id", jsonReadStr(settingsFlashJson, "id")); + jsonWriteStr_(devListJson, "name", jsonReadStr(settingsFlashJson, "name")); + jsonWriteBool_(devListJson, "status", true); + devListJson = "[" + devListJson + "]"; + Serial.println(devListJson); +} \ No newline at end of file diff --git a/src/EspFileSystem.cpp b/src/EspFileSystem.cpp index f7664d36..a9fcee09 100644 --- a/src/EspFileSystem.cpp +++ b/src/EspFileSystem.cpp @@ -16,6 +16,7 @@ void globalVarsSync() { mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix")); mqttRootDevice = mqttPrefix + "/" + chipId; jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice); + jsonWriteStr_(settingsFlashJson, "id", chipId); saveSettingsFlashJson(); jsonWriteStr_(ssidListJson, "ssid", ""); } diff --git a/src/Global.cpp b/src/Global.cpp index b6b4ce5f..0c74b221 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -41,7 +41,7 @@ String eventBuf = ""; // wifi String ssidListJson = "{}"; -String devListJson = "{}"; +String devListJson; // Mqtt String mqttServer = ""; diff --git a/src/Main.cpp b/src/Main.cpp index 17633a03..4ff521f5 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -21,6 +21,9 @@ void setup() { //подключаемся к роутеру routerConnect(); + //синхронизация списка устройств + addThisDeviceToList(); + //запустим один раз асинхронное сканирование сетей wifi для веба RouterFind(jsonReadStr(settingsFlashJson, F("routerssid"))); @@ -49,6 +52,7 @@ void setup() { ts.add( MYTEST, 1000 * 30, [&](void*) { SerialPrint(F("i"), F("HEAP"), prettyBytes(ESP.getFreeHeap())); + standWebSocket.broadcastTXT(devListJson); }, nullptr, true); } diff --git a/src/WsServer.cpp b/src/WsServer.cpp index 318fcacc..0ce68062 100644 --- a/src/WsServer.cpp +++ b/src/WsServer.cpp @@ -62,8 +62,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) } // list =================================================================== if (headerStr == "/list") { - standWebSocket.sendTXT(num, devListJson); - sendFileToWs("/settings.json", num, 1024); + // standWebSocket.sendTXT(num, devListJson); + // sendFileToWs("/settings.json", num, 1024); } } break;