mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
поправлены баги списка устройств
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//Это версия прошивки
|
//Это версия прошивки
|
||||||
#define FIRMWARE_VERSION 401
|
#define FIRMWARE_VERSION 402
|
||||||
|
|
||||||
//Размер буфера json
|
//Размер буфера json
|
||||||
#define JSON_BUFFER_SIZE 1024
|
#define JSON_BUFFER_SIZE 1024
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
#include "ESPAsyncUDP.h"
|
#include "ESPAsyncUDP.h"
|
||||||
extern AsyncUDP asyncUdp;
|
extern AsyncUDP asyncUdp;
|
||||||
|
|
||||||
|
extern const String getThisDevice();
|
||||||
extern void addThisDeviceToList();
|
extern void addThisDeviceToList();
|
||||||
extern void asyncUdpInit();
|
extern void asyncUdpInit();
|
||||||
extern String uint8tToString(uint8_t* data, size_t len);
|
extern String uint8tToString(uint8_t* data, size_t len);
|
||||||
extern bool udpPacketValidation(String& data);
|
extern bool udpPacketValidation(String& data);
|
||||||
extern void udpPacketParse(String& data);
|
extern void udpPacketParse(String& data);
|
||||||
extern void jsonMergeArrays(String& arr1, String& arr2);
|
extern void jsonMergeArrays(String& arr1, String& arr2);
|
||||||
|
extern void jsonMergeArrays2(String& arr1, String& arr2);
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Utils/WiFiUtils.h"
|
#include "Utils/WiFiUtils.h"
|
||||||
|
#include "DeviceList.h"
|
||||||
|
|
||||||
#ifdef STANDARD_WEB_SOCKETS
|
#ifdef STANDARD_WEB_SOCKETS
|
||||||
extern void standWebSocketsInit();
|
extern void standWebSocketsInit();
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
#include "DeviceList.h"
|
#include "DeviceList.h"
|
||||||
|
|
||||||
|
const String getThisDevice() {
|
||||||
|
String thisDevice;
|
||||||
|
jsonWriteStr_(thisDevice, F("devicelist"), ""); //метка для парсинга
|
||||||
|
jsonWriteStr_(thisDevice, F("ip"), jsonReadStr(settingsFlashJson, F("ip")));
|
||||||
|
jsonWriteStr_(thisDevice, F("id"), jsonReadStr(settingsFlashJson, F("id")));
|
||||||
|
jsonWriteStr_(thisDevice, F("name"), jsonReadStr(settingsFlashJson, F("name")));
|
||||||
|
thisDevice = "[" + thisDevice + "]";
|
||||||
|
return thisDevice;
|
||||||
|
}
|
||||||
|
|
||||||
void addThisDeviceToList() {
|
void addThisDeviceToList() {
|
||||||
jsonWriteStr_(devListHeapJson, F("devicelist"), ""); //метка для парсинга
|
devListHeapJson = getThisDevice();
|
||||||
jsonWriteStr_(devListHeapJson, F("ip"), jsonReadStr(settingsFlashJson, F("ip")));
|
|
||||||
jsonWriteStr_(devListHeapJson, F("id"), jsonReadStr(settingsFlashJson, F("id")));
|
|
||||||
jsonWriteStr_(devListHeapJson, F("name"), jsonReadStr(settingsFlashJson, F("name")));
|
|
||||||
|
|
||||||
// для проверки
|
|
||||||
// devListHeapJson = devListHeapJson + ",";
|
|
||||||
// String test;
|
|
||||||
// jsonWriteStr_(test, "ip", "192.168.88.88");
|
|
||||||
// jsonWriteStr_(test, "id", "123456789");
|
|
||||||
// jsonWriteStr_(test, "name", "test");
|
|
||||||
// devListHeapJson = devListHeapJson + test;
|
|
||||||
|
|
||||||
devListHeapJson = "[" + devListHeapJson + "]";
|
|
||||||
Serial.println(devListHeapJson);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
#ifdef UDP_ENABLED
|
||||||
@@ -38,19 +34,16 @@ void asyncUdpInit() {
|
|||||||
// Serial.print(packet.length());
|
// Serial.print(packet.length());
|
||||||
// Serial.print(", Data: ");
|
// Serial.print(", Data: ");
|
||||||
// Serial.write(packet.data(), packet.length());
|
// Serial.write(packet.data(), packet.length());
|
||||||
|
|
||||||
String data = uint8tToString(packet.data(), packet.length());
|
String data = uint8tToString(packet.data(), packet.length());
|
||||||
SerialPrint("i", F("UDP"), "Udp packet received, IP: " + packet.remoteIP().toString() + ":" + String(packet.remotePort()));
|
// Serial.println(data);
|
||||||
Serial.println(data);
|
|
||||||
|
|
||||||
if (udpPacketValidation(data)) {
|
if (udpPacketValidation(data)) {
|
||||||
SerialPrint("i", F("UDP"), F("Device presentation received"));
|
SerialPrint("i", F("UDP"), "Udp packet received, IP: " + packet.remoteIP().toString() + ":" + String(packet.remotePort()));
|
||||||
jsonMergeArrays(devListHeapJson, data);
|
// Serial.println(data);
|
||||||
Serial.println(devListHeapJson);
|
jsonMergeArrays2(devListHeapJson, data);
|
||||||
|
// Serial.println(devListHeapJson);
|
||||||
} else {
|
} else {
|
||||||
SerialPrint("E", F("UDP"), F("Udp packet invalid"));
|
SerialPrint("E", F("UDP"), F("Udp packet invalid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// reply to the client
|
// reply to the client
|
||||||
// String ip = WiFi.localIP().toString();
|
// String ip = WiFi.localIP().toString();
|
||||||
// asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
// asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
||||||
@@ -62,7 +55,7 @@ void asyncUdpInit() {
|
|||||||
ts.add(
|
ts.add(
|
||||||
UDP, 10000, [&](void*) {
|
UDP, 10000, [&](void*) {
|
||||||
SerialPrint("i", F("UDP"), F("Broadcast device presentation"));
|
SerialPrint("i", F("UDP"), F("Broadcast device presentation"));
|
||||||
asyncUdp.broadcastTo(devListHeapJson.c_str(), 4210);
|
asyncUdp.broadcastTo(getThisDevice().c_str(), 4210);
|
||||||
// asyncUdp.broadcast("test");
|
// asyncUdp.broadcast("test");
|
||||||
// asyncUdp.print("Hello Server!");
|
// asyncUdp.print("Hello Server!");
|
||||||
},
|
},
|
||||||
@@ -90,11 +83,11 @@ void jsonMergeArrays(String& arr1, String& arr2) {
|
|||||||
arr2.replace("]", "");
|
arr2.replace("]", "");
|
||||||
String incIP = jsonReadStr(arr2, "ip");
|
String incIP = jsonReadStr(arr2, "ip");
|
||||||
|
|
||||||
Serial.println("incIP " + incIP);
|
// Serial.println("incIP " + incIP);
|
||||||
bool ipExistInList = false;
|
bool ipExistInList = false;
|
||||||
for (JsonVariant value : jarr) {
|
for (JsonVariant value : jarr) {
|
||||||
String locIP = value["ip"].as<String>();
|
String locIP = value["ip"].as<String>();
|
||||||
Serial.println("locIP " + locIP);
|
// Serial.println("locIP " + locIP);
|
||||||
if (locIP == incIP) {
|
if (locIP == incIP) {
|
||||||
ipExistInList = true;
|
ipExistInList = true;
|
||||||
break;
|
break;
|
||||||
@@ -108,6 +101,34 @@ void jsonMergeArrays(String& arr1, String& arr2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void jsonMergeArrays2(String& arr1, String& arr2) {
|
||||||
|
DynamicJsonDocument doc(1024);
|
||||||
|
DeserializationError error = deserializeJson(doc, arr1);
|
||||||
|
if (error) {
|
||||||
|
SerialPrint("E", F("UDP"), error.f_str());
|
||||||
|
}
|
||||||
|
JsonArray jarr = doc.as<JsonArray>();
|
||||||
|
arr2.replace("[", "");
|
||||||
|
arr2.replace("]", "");
|
||||||
|
String incIP = jsonReadStr(arr2, "ip");
|
||||||
|
String outArr = "[";
|
||||||
|
bool ipExistInList = false;
|
||||||
|
for (JsonVariant value : jarr) {
|
||||||
|
String locIP = value["ip"].as<String>();
|
||||||
|
if (locIP == incIP) {
|
||||||
|
outArr += "," + arr2;
|
||||||
|
ipExistInList = true;
|
||||||
|
} else {
|
||||||
|
outArr += value.as<String>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ipExistInList) {
|
||||||
|
outArr += "," + arr2;
|
||||||
|
}
|
||||||
|
outArr = outArr + "]";
|
||||||
|
arr1 = outArr;
|
||||||
|
}
|
||||||
|
|
||||||
// void udpPacketParse(String& data) {
|
// void udpPacketParse(String& data) {
|
||||||
// if (data.indexOf("scen:") != -1) {
|
// if (data.indexOf("scen:") != -1) {
|
||||||
// data = deleteBeforeDelimiter(data, ":");
|
// data = deleteBeforeDelimiter(data, ":");
|
||||||
|
|||||||
@@ -9,15 +9,19 @@ void standWebServerInit() {
|
|||||||
HTTP.serveStatic("/js/", FileFS, "/js/", "max-age=31536000"); // кеширование на 1 год
|
HTTP.serveStatic("/js/", FileFS, "/js/", "max-age=31536000"); // кеширование на 1 год
|
||||||
HTTP.serveStatic("/png/", FileFS, "/png/", "max-age=31536000"); // кеширование на 1 год
|
HTTP.serveStatic("/png/", FileFS, "/png/", "max-age=31536000"); // кеширование на 1 год
|
||||||
|
|
||||||
HTTP.on("/settingsh.json", HTTP_GET, []() {
|
HTTP.on("/devicelist.json", HTTP_GET, []() {
|
||||||
|
HTTP.send(200, "application/json", devListHeapJson);
|
||||||
|
});
|
||||||
|
|
||||||
|
HTTP.on("/settings.h.json", HTTP_GET, []() {
|
||||||
HTTP.send(200, "application/json", settingsFlashJson);
|
HTTP.send(200, "application/json", settingsFlashJson);
|
||||||
});
|
});
|
||||||
|
|
||||||
HTTP.on("/settingsf.json", HTTP_GET, []() {
|
HTTP.on("/settings.f.json", HTTP_GET, []() {
|
||||||
HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
||||||
});
|
});
|
||||||
|
|
||||||
HTTP.on("/paramsh.json", HTTP_GET, []() {
|
HTTP.on("/params.json", HTTP_GET, []() {
|
||||||
HTTP.send(200, "application/json", paramsHeapJson);
|
HTTP.send(200, "application/json", paramsHeapJson);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
||||||
writeUint8tToString(payload, length, headerLenth, settingsFlashJson);
|
writeUint8tToString(payload, length, headerLenth, settingsFlashJson);
|
||||||
standWebSocket.sendTXT(num, errorsHeapJson);
|
standWebSocket.sendTXT(num, errorsHeapJson);
|
||||||
|
addThisDeviceToList();
|
||||||
// settingsFlashJson = readFile(F("settings.json"), 4096);
|
// settingsFlashJson = readFile(F("settings.json"), 4096);
|
||||||
}
|
}
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
|
|||||||
Reference in New Issue
Block a user