mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
increase ws buffer sizes - https://github.com/proddy/EMS-ESP/issues/250
This commit is contained in:
@@ -1472,8 +1472,8 @@ void MyESP::_heartbeatCheck(bool force) {
|
|||||||
uint32_t free_memory = ESP.getFreeHeap();
|
uint32_t free_memory = ESP.getFreeHeap();
|
||||||
uint8_t mem_available = 100 * free_memory / total_memory; // as a %
|
uint8_t mem_available = 100 * free_memory / total_memory; // as a %
|
||||||
|
|
||||||
StaticJsonDocument<200> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
JsonObject rootHeartbeat = doc.to<JsonObject>();
|
JsonObject rootHeartbeat = doc.to<JsonObject>();
|
||||||
|
|
||||||
rootHeartbeat["version"] = _app_version;
|
rootHeartbeat["version"] = _app_version;
|
||||||
rootHeartbeat["IP"] = WiFi.localIP().toString();
|
rootHeartbeat["IP"] = WiFi.localIP().toString();
|
||||||
@@ -2312,11 +2312,13 @@ void MyESP::_onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, A
|
|||||||
// handle ws from browser
|
// handle ws from browser
|
||||||
void MyESP::_procMsg(AsyncWebSocketClient * client, size_t sz) {
|
void MyESP::_procMsg(AsyncWebSocketClient * client, size_t sz) {
|
||||||
// We should always get a JSON object from browser, so parse it
|
// We should always get a JSON object from browser, so parse it
|
||||||
StaticJsonDocument<500> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_MEDIUM> doc;
|
||||||
char json[sz + 1];
|
char json[sz + 1];
|
||||||
memcpy(json, (char *)(client->_tempObject), sz);
|
memcpy(json, (char *)(client->_tempObject), sz);
|
||||||
json[sz] = '\0';
|
json[sz] = '\0';
|
||||||
|
|
||||||
|
// Serial.printf("[%s]", json);
|
||||||
|
|
||||||
JsonObject root = doc.to<JsonObject>(); // create empty object
|
JsonObject root = doc.to<JsonObject>(); // create empty object
|
||||||
DeserializationError error = deserializeJson(doc, json); // Deserialize the JSON document
|
DeserializationError error = deserializeJson(doc, json); // Deserialize the JSON document
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -2410,8 +2412,7 @@ bool MyESP::_fs_sendConfig() {
|
|||||||
|
|
||||||
// send custom status via ws
|
// send custom status via ws
|
||||||
void MyESP::_sendCustomStatus() {
|
void MyESP::_sendCustomStatus() {
|
||||||
// StaticJsonDocument<300> doc;
|
DynamicJsonDocument doc(MYESP_JSON_MAXSIZE_LARGE);
|
||||||
DynamicJsonDocument doc(MYESP_JSON_MAXSIZE);
|
|
||||||
|
|
||||||
JsonObject root = doc.to<JsonObject>();
|
JsonObject root = doc.to<JsonObject>();
|
||||||
|
|
||||||
@@ -2427,7 +2428,7 @@ void MyESP::_sendCustomStatus() {
|
|||||||
(_web_callback_f)(root);
|
(_web_callback_f)(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[MYESP_JSON_MAXSIZE];
|
char buffer[MYESP_JSON_MAXSIZE_LARGE];
|
||||||
size_t len = serializeJson(root, buffer);
|
size_t len = serializeJson(root, buffer);
|
||||||
|
|
||||||
#ifdef MYESP_DEBUG
|
#ifdef MYESP_DEBUG
|
||||||
@@ -2536,9 +2537,9 @@ void MyESP::_printScanResult(int networksFound) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<400> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_MEDIUM> doc;
|
||||||
JsonObject root = doc.to<JsonObject>();
|
JsonObject root = doc.to<JsonObject>();
|
||||||
root["command"] = "ssidlist";
|
root["command"] = "ssidlist";
|
||||||
|
|
||||||
JsonArray list = doc.createNestedArray("list");
|
JsonArray list = doc.createNestedArray("list");
|
||||||
for (int i = 0; i <= 5 && i < networksFound; ++i) {
|
for (int i = 0; i <= 5 && i < networksFound; ++i) {
|
||||||
@@ -2548,7 +2549,7 @@ void MyESP::_printScanResult(int networksFound) {
|
|||||||
item["rssi"] = WiFi.RSSI(indices[i]);
|
item["rssi"] = WiFi.RSSI(indices[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[400];
|
char buffer[MYESP_JSON_MAXSIZE_MEDIUM];
|
||||||
size_t len = serializeJson(root, buffer);
|
size_t len = serializeJson(root, buffer);
|
||||||
_ws->textAll(buffer, len);
|
_ws->textAll(buffer, len);
|
||||||
}
|
}
|
||||||
@@ -2750,12 +2751,12 @@ void MyESP::_addMQTTLog(const char * topic, const char * payload, const MYESP_MQ
|
|||||||
|
|
||||||
// send UTC time via ws
|
// send UTC time via ws
|
||||||
void MyESP::_sendTime() {
|
void MyESP::_sendTime() {
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
JsonObject root = doc.to<JsonObject>();
|
JsonObject root = doc.to<JsonObject>();
|
||||||
root["command"] = "gettime";
|
root["command"] = "gettime";
|
||||||
root["epoch"] = now();
|
root["epoch"] = now();
|
||||||
|
|
||||||
char buffer[100];
|
char buffer[MYESP_JSON_MAXSIZE_SMALL];
|
||||||
size_t len = serializeJson(root, buffer);
|
size_t len = serializeJson(root, buffer);
|
||||||
_ws->textAll(buffer, len);
|
_ws->textAll(buffer, len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,9 +103,11 @@ extern struct rst_info resetInfo;
|
|||||||
#define MQTT_DISCONNECT_EVENT 1
|
#define MQTT_DISCONNECT_EVENT 1
|
||||||
#define MQTT_MESSAGE_EVENT 2
|
#define MQTT_MESSAGE_EVENT 2
|
||||||
|
|
||||||
#define MYESP_JSON_MAXSIZE 2000 // for large Dynamic json files
|
#define MYESP_JSON_MAXSIZE_LARGE 2000 // for large Dynamic json files
|
||||||
#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes
|
#define MYESP_JSON_MAXSIZE_MEDIUM 800 // for medium Dynamic json files
|
||||||
#define MYESP_JSON_LOG_MAXSIZE 300 // max size of an JSON log entry
|
#define MYESP_JSON_MAXSIZE_SMALL 200 // for smaller Static json documents
|
||||||
|
|
||||||
|
#define MYESP_MQTTLOG_MAX 60 // max number of log entries for MQTT publishes and subscribes
|
||||||
|
|
||||||
#define MYESP_MQTT_PAYLOAD_ON '1' // for MQTT switch on
|
#define MYESP_MQTT_PAYLOAD_ON '1' // for MQTT switch on
|
||||||
#define MYESP_MQTT_PAYLOAD_OFF '0' // for MQTT switch off
|
#define MYESP_MQTT_PAYLOAD_OFF '0' // for MQTT switch off
|
||||||
|
|||||||
@@ -515,8 +515,8 @@ void publishSensorValues(bool force) {
|
|||||||
return; // no sensors attached
|
return; // no sensors attached
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<200> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
JsonObject sensors = doc.to<JsonObject>();
|
JsonObject sensors = doc.to<JsonObject>();
|
||||||
|
|
||||||
bool hasdata = false;
|
bool hasdata = false;
|
||||||
char label[8] = {0};
|
char label[8] = {0};
|
||||||
@@ -539,7 +539,7 @@ void publishSensorValues(bool force) {
|
|||||||
CRC32 crc;
|
CRC32 crc;
|
||||||
uint32_t fchecksum;
|
uint32_t fchecksum;
|
||||||
|
|
||||||
char data[200] = {0};
|
char data[MYESP_JSON_MAXSIZE_SMALL] = {0};
|
||||||
serializeJson(doc, data, sizeof(data));
|
serializeJson(doc, data, sizeof(data));
|
||||||
|
|
||||||
size_t jsonSize = measureJson(doc);
|
size_t jsonSize = measureJson(doc);
|
||||||
@@ -1038,10 +1038,10 @@ bool LoadSaveCallback(MYESP_FSACTION_t action, JsonObject settings) {
|
|||||||
|
|
||||||
// Publish shower data
|
// Publish shower data
|
||||||
bool do_publishShowerData() {
|
bool do_publishShowerData() {
|
||||||
StaticJsonDocument<200> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
JsonObject rootShower = doc.to<JsonObject>();
|
JsonObject rootShower = doc.to<JsonObject>();
|
||||||
rootShower[TOPIC_SHOWER_TIMER] = EMSESP_Settings.shower_timer ? "1" : "0";
|
rootShower[TOPIC_SHOWER_TIMER] = EMSESP_Settings.shower_timer ? "1" : "0";
|
||||||
rootShower[TOPIC_SHOWER_ALERT] = EMSESP_Settings.shower_alert ? "1" : "0";
|
rootShower[TOPIC_SHOWER_ALERT] = EMSESP_Settings.shower_alert ? "1" : "0";
|
||||||
|
|
||||||
// only publish shower duration if there is a value
|
// only publish shower duration if there is a value
|
||||||
char s[50] = {0};
|
char s[50] = {0};
|
||||||
@@ -1486,8 +1486,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
|
|||||||
// check first for generic commands
|
// check first for generic commands
|
||||||
if (strcmp(topic, TOPIC_GENERIC_CMD) == 0) {
|
if (strcmp(topic, TOPIC_GENERIC_CMD) == 0) {
|
||||||
// convert JSON and get the command
|
// convert JSON and get the command
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
||||||
if (error) {
|
if (error) {
|
||||||
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1505,8 +1505,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
|
|||||||
|
|
||||||
// check for shower commands
|
// check for shower commands
|
||||||
if (strcmp(topic, TOPIC_SHOWER_DATA) == 0) {
|
if (strcmp(topic, TOPIC_SHOWER_DATA) == 0) {
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
||||||
if (error) {
|
if (error) {
|
||||||
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1532,8 +1532,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
|
|||||||
// check for boiler commands
|
// check for boiler commands
|
||||||
if (strcmp(topic, TOPIC_BOILER_CMD) == 0) {
|
if (strcmp(topic, TOPIC_BOILER_CMD) == 0) {
|
||||||
// convert JSON and get the command
|
// convert JSON and get the command
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
||||||
if (error) {
|
if (error) {
|
||||||
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
||||||
return;
|
return;
|
||||||
@@ -1619,8 +1619,8 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
|
|||||||
// check for generic thermostat commands
|
// check for generic thermostat commands
|
||||||
if (strcmp(topic, TOPIC_THERMOSTAT_CMD) == 0) {
|
if (strcmp(topic, TOPIC_THERMOSTAT_CMD) == 0) {
|
||||||
// convert JSON and get the command
|
// convert JSON and get the command
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
DeserializationError error = deserializeJson(doc, message); // Deserialize the JSON document
|
||||||
if (error) {
|
if (error) {
|
||||||
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
myDebug_P(PSTR("[MQTT] Invalid command from topic %s, payload %s, error %s"), topic, message, error.c_str());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define APP_VERSION "1.9.4b21"
|
#define APP_VERSION "1.9.4b22"
|
||||||
|
|||||||
Reference in New Issue
Block a user