mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
список устройств
This commit is contained in:
4
include/DeviceList.h
Normal file
4
include/DeviceList.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
|
||||
extern void addThisDeviceToList();
|
||||
@@ -9,3 +9,4 @@
|
||||
#include "ESPConfiguration.h"
|
||||
#include "MqttClient.h"
|
||||
#include "WsServer.h"
|
||||
#include "DeviceList.h"
|
||||
|
||||
11
src/DeviceList.cpp
Normal file
11
src/DeviceList.cpp
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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", "");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ String eventBuf = "";
|
||||
// wifi
|
||||
String ssidListJson = "{}";
|
||||
|
||||
String devListJson = "{}";
|
||||
String devListJson;
|
||||
|
||||
// Mqtt
|
||||
String mqttServer = "";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user