Merge branch 'IoTManagerProject:ver4dev' into ver4dev

This commit is contained in:
2023-10-03 22:27:12 +03:00
committed by GitHub
5 changed files with 37 additions and 27 deletions

View File

@@ -21,3 +21,4 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
void sendStringToWs(const String& header, String& payload, int client_id); void sendStringToWs(const String& header, String& payload, int client_id);
void sendDeviceList(uint8_t num); void sendDeviceList(uint8_t num);
int getNumWSClients();

View File

@@ -2,9 +2,8 @@
#include "Global.h" #include "Global.h"
#include "MqttClient.h" #include "MqttClient.h"
#include <vector> boolean isNetworkActive();
// boolean isNetworkActive(); uint8_t getNumAPClients();
inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;};
void routerConnect(); void routerConnect();
bool startAPMode(); bool startAPMode();
boolean RouterFind(std::vector<String> jArray); boolean RouterFind(std::vector<String> jArray);

View File

@@ -450,25 +450,27 @@ void sendFileToWsByFrames(const String& filename, const String& header,
} }
void sendStringToWs(const String& header, String& payload, int client_id) { void sendStringToWs(const String& header, String& payload, int client_id) {
if (!(WiFi.softAPgetStationNum() || isNetworkActive())) { if ((!getNumAPClients() && !isNetworkActive()) || !getNumWSClients()) {
return; // standWebSocket.disconnect(); // это и ниже надо сделать при -
} // standWebSocket.close(); // - отключении AP И WiFi(STA), надо менять ядро WiFi. Сейчас не закрывается сессия клиента при пропаже AP И WiFi(STA)
return;
}
if (header.length() != 6) { if (header.length() != 6) {
SerialPrint("E", "FS", F("wrong header size")); SerialPrint("E", "FS", F("wrong header size"));
return; return;
} }
String msg = header + "|0012|" + payload; String msg = header + "|0012|" + payload;
size_t totalSize = msg.length(); size_t totalSize = msg.length();
char dataArray[totalSize]; char dataArray[totalSize];
msg.toCharArray(dataArray, totalSize + 1); msg.toCharArray(dataArray, totalSize + 1);
if (client_id == -1) { if (client_id == -1) {
standWebSocket.broadcastBIN((uint8_t*)dataArray, totalSize); standWebSocket.broadcastBIN((uint8_t*)dataArray, totalSize);
} else { } else {
standWebSocket.sendBIN(client_id, (uint8_t*)dataArray, totalSize); standWebSocket.sendBIN(client_id, (uint8_t*)dataArray, totalSize);
} }
} }
void sendDeviceList(uint8_t num) { void sendDeviceList(uint8_t num) {
@@ -483,3 +485,7 @@ void sendDeviceList(uint8_t num) {
SerialPrint("i", "FS", "flash list"); SerialPrint("i", "FS", "flash list");
} }
} }
int getNumWSClients() {
return standWebSocket.connectedClients(false);
}

View File

@@ -11,11 +11,11 @@ void SerialPrint(const String& errorLevel, const String& module, const String& m
tosend += msg; tosend += msg;
Serial.println(tosend); Serial.println(tosend);
if (isNetworkActive()) { // if (isNetworkActive()) { // все проверки происходят в sendStringToWs()
if (jsonReadInt(settingsFlashJson, F("log")) != 0) { if (jsonReadInt(settingsFlashJson, F("log")) != 0) {
sendStringToWs(F("corelg"), tosend, -1); sendStringToWs(F("corelg"), tosend, -1);
}
} }
// }
if (errorLevel == "E") { if (errorLevel == "E") {
cleanString(tosend); cleanString(tosend);

View File

@@ -171,9 +171,13 @@ boolean RouterFind(std::vector<String> jArray)
return res; return res;
} }
// boolean isNetworkActive() { boolean isNetworkActive() {
// return WiFi.status() == WL_CONNECTED; return WiFi.status() == WL_CONNECTED;
// } }
uint8_t getNumAPClients() {
return WiFi.softAPgetStationNum();
}
uint8_t RSSIquality() { uint8_t RSSIquality() {
uint8_t res = 0; uint8_t res = 0;