diff --git a/lib/WebSockets/src/WebSocketsServer.cpp b/lib/WebSockets/src/WebSocketsServer.cpp index e864bfe2..39d8d3e2 100644 --- a/lib/WebSockets/src/WebSocketsServer.cpp +++ b/lib/WebSockets/src/WebSocketsServer.cpp @@ -257,8 +257,10 @@ bool WebSocketsServerCore::broadcastBIN(uint8_t * payload, size_t length, bool f for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) { client = &_clients[i]; if(clientIsConnected(client)) { - if(!sendFrame(client, WSop_binary, payload, length, fin, headerToPayload)) { - ret = false; + if(continuation) { + ret = sendFrame(client, WSop_continuation, payload, length, fin, headerToPayload); + } else { + ret = sendFrame(client, WSop_binary, payload, length, fin, headerToPayload); } } WEBSOCKETS_YIELD(); diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 89a2ba7e..7fa2c7ef 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -325,14 +325,15 @@ void handleMqttStatus(bool send) { String stateStr = getStateStr(mqtt.state()); // Serial.println(stateStr); jsonWriteStr_(errorsHeapJson, F("mqtt"), stateStr); - if (!send) standWebSocket.broadcastTXT(errorsHeapJson); + + if (!send) sendStringToWs("errors", errorsHeapJson, -1); } void handleMqttStatus(bool send, int state) { String stateStr = getStateStr(state); // Serial.println(stateStr); jsonWriteStr_(errorsHeapJson, F("mqtt"), stateStr); - if (!send) standWebSocket.broadcastTXT(errorsHeapJson); + if (!send) sendStringToWs("errors", errorsHeapJson, -1); } // log-20384820.txt diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp index ec953ba7..48c55fdf 100644 --- a/src/UpgradeFirm.cpp +++ b/src/UpgradeFirm.cpp @@ -132,5 +132,5 @@ void saveUserDataToFlash() { void handleUpdateStatus(bool send, int state) { jsonWriteInt_(errorsHeapJson, F("upd"), state); - if (!send) standWebSocket.broadcastTXT(errorsHeapJson); + if (!send) sendStringToWs("errors", errorsHeapJson, -1); } \ No newline at end of file diff --git a/src/WsServer.cpp b/src/WsServer.cpp index dbcdc553..9014f600 100644 --- a/src/WsServer.cpp +++ b/src/WsServer.cpp @@ -217,10 +217,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) } if (headerStr == "/test|") { - sendFileToWsByFrames("/items.json", "itemsj", "", num, WEB_SOCKETS_FRAME_SIZE); - sendFileToWsByFrames("/widgets.json", "widget", "", num, WEB_SOCKETS_FRAME_SIZE); - sendFileToWsByFrames("/config.json", "config", "", num, WEB_SOCKETS_FRAME_SIZE); - sendFileToWsByFrames("/scenario.txt", "scenar", "", num, WEB_SOCKETS_FRAME_SIZE); } } break; @@ -313,38 +309,38 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) { //посылка данных из файла в бинарном виде void sendFileToWs(String filename, int num, size_t frameSize) { - String st = "/st" + String(filename); - if (num == -1) { - standWebSocket.broadcastTXT(st); - } else { - standWebSocket.sendTXT(num, st); - } - - String path = filepath(filename); - auto file = FileFS.open(path, "r"); - if (!file) { - SerialPrint(F("E"), F("FS"), F("reed file error")); - return; - } - size_t fileSize = file.size(); - SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize)); - uint8_t payload[frameSize]; - int countRead = file.read(payload, sizeof(payload)); - while (countRead > 0) { - if (num == -1) { - standWebSocket.broadcastBIN(payload, countRead); - } else { - standWebSocket.sendBIN(num, payload, countRead); - } - countRead = file.read(payload, sizeof(payload)); - } - file.close(); - String end = "/end" + String(filename); - if (num == -1) { - standWebSocket.broadcastTXT(end); - } else { - standWebSocket.sendTXT(num, end); - } + // String st = "/st" + String(filename); + // if (num == -1) { + // standWebSocket.broadcastTXT(st); + // } else { + // standWebSocket.sendTXT(num, st); + // } + // + // String path = filepath(filename); + // auto file = FileFS.open(path, "r"); + // if (!file) { + // SerialPrint(F("E"), F("FS"), F("reed file error")); + // return; + //} + // size_t fileSize = file.size(); + // SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize)); + // uint8_t payload[frameSize]; + // int countRead = file.read(payload, sizeof(payload)); + // while (countRead > 0) { + // if (num == -1) { + // standWebSocket.broadcastBIN(payload, countRead); + // } else { + // standWebSocket.sendBIN(num, payload, countRead); + // } + // countRead = file.read(payload, sizeof(payload)); + //} + // file.close(); + // String end = "/end" + String(filename); + // if (num == -1) { + // standWebSocket.broadcastTXT(end); + //} else { + // standWebSocket.sendTXT(num, end); + //} } //посылка данных из string @@ -361,41 +357,41 @@ void sendFileToWs(String filename, int num, size_t frameSize) { //особая функция отправки графиков в веб void publishChartToWs(String filename, int num, size_t frameSize, int maxCount, String id) { - String json; - jsonWriteStr(json, "topic", mqttRootDevice + "/" + id); - jsonWriteInt(json, "maxCount", maxCount); - - String st = "/st/chart.json|" + json; - if (num == -1) { - standWebSocket.broadcastTXT(st); - } else { - standWebSocket.sendTXT(num, st); - } - String path = filepath(filename); - auto file = FileFS.open(path, "r"); - if (!file) { - SerialPrint(F("E"), F("FS"), F("reed file error")); - return; - } - size_t fileSize = file.size(); - SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize)); - uint8_t payload[frameSize]; - int countRead = file.read(payload, sizeof(payload)); - while (countRead > 0) { - if (num == -1) { - standWebSocket.broadcastBIN(payload, countRead); - } else { - standWebSocket.sendBIN(num, payload, countRead); - } - countRead = file.read(payload, sizeof(payload)); - } - file.close(); - String end = "/end/chart.json|" + json; - if (num == -1) { - standWebSocket.broadcastTXT(end); - } else { - standWebSocket.sendTXT(num, end); - } + // String json; + // jsonWriteStr(json, "topic", mqttRootDevice + "/" + id); + // jsonWriteInt(json, "maxCount", maxCount); + // + // String st = "/st/chart.json|" + json; + // if (num == -1) { + // standWebSocket.broadcastTXT(st); + //} else { + // standWebSocket.sendTXT(num, st); + //} + // String path = filepath(filename); + // auto file = FileFS.open(path, "r"); + // if (!file) { + // SerialPrint(F("E"), F("FS"), F("reed file error")); + // return; + //} + // size_t fileSize = file.size(); + // SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize)); + // uint8_t payload[frameSize]; + // int countRead = file.read(payload, sizeof(payload)); + // while (countRead > 0) { + // if (num == -1) { + // standWebSocket.broadcastBIN(payload, countRead); + // } else { + // standWebSocket.sendBIN(num, payload, countRead); + // } + // countRead = file.read(payload, sizeof(payload)); + //} + // file.close(); + // String end = "/end/chart.json|" + json; + // if (num == -1) { + // standWebSocket.broadcastTXT(end); + //} else { + // standWebSocket.sendTXT(num, end); + //} } void sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize) { @@ -412,7 +408,7 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St } size_t totalSize = file.size(); - SerialPrint("I", "FS", "Send file '" + String(filename) + "', file size: " + String(totalSize)); + // Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize)); char buf[32]; sprintf(buf, "%04d", json.length() + 12); @@ -452,7 +448,7 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St continuation = true; } - SerialPrint("I", "FS", String(i) + ") fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation)); + // Serial.println(String(i) + ") fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation)); standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation); } i++; @@ -470,7 +466,7 @@ void sendStringToWs(const String& header, String& payload, int client_id) { String msg = header + "|0012|" + payload; size_t totalSize = msg.length(); - SerialPrint("I", "FS", "Send string '" + header + "', str size: " + String(totalSize)); + // Serial.println("Send string '" + header + "', str size: " + String(totalSize)); char dataArray[totalSize]; msg.toCharArray(dataArray, totalSize + 1); diff --git a/src/modules/virtual/Loging/Loging.cpp b/src/modules/virtual/Loging/Loging.cpp index d7649e1f..72048ec6 100644 --- a/src/modules/virtual/Loging/Loging.cpp +++ b/src/modules/virtual/Loging/Loging.cpp @@ -228,14 +228,14 @@ class Loging : public IoTItem { String topic = mqttRootDevice + "/" + id; String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}"; String pk = "/string/chart.json|" + json; - standWebSocket.broadcastTXT(pk); + //standWebSocket.broadcastTXT(pk); } void publishChartToWsSinglePoint(String value) { String topic = mqttRootDevice + "/" + id; String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}"; String pk = "/string/chart.json|" + json; - standWebSocket.broadcastTXT(pk); + //standWebSocket.broadcastTXT(pk); } void setPublishDestination(int publishType, int wsNum = -1) { diff --git a/src/modules/virtual/LogingDaily/LogingDaily.cpp b/src/modules/virtual/LogingDaily/LogingDaily.cpp index fa4d5f59..529ca3ef 100644 --- a/src/modules/virtual/LogingDaily/LogingDaily.cpp +++ b/src/modules/virtual/LogingDaily/LogingDaily.cpp @@ -192,7 +192,7 @@ class LogingDaily : public IoTItem { String topic = mqttRootDevice + "/" + id; String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}"; String pk = "/string/chart.json|" + json; - standWebSocket.broadcastTXT(pk); + //standWebSocket.broadcastTXT(pk); } void setPublishDestination(int publishType, int wsNum = -1) { diff --git a/src/utils/SerialPrint.cpp b/src/utils/SerialPrint.cpp index ce713c12..6287029c 100644 --- a/src/utils/SerialPrint.cpp +++ b/src/utils/SerialPrint.cpp @@ -6,15 +6,14 @@ void SerialPrint(String errorLevel, String module, String msg) { tosend = prettyMillis(millis()); - // if (module == "Loging") { tosend = tosend + " [" + errorLevel + "] [" + module + "] " + msg; Serial.println(tosend); if (isNetworkActive()) { if (jsonReadInt(settingsFlashJson, F("log")) != 0) { - String pl = "/log|" + tosend; - standWebSocket.broadcastTXT(pl); + // String pl = "/log|" + tosend; + // standWebSocket.broadcastTXT(pl); + sendStringToWs("corelg", tosend, -1); } } - //} } \ No newline at end of file