From e6191915e36bb47f0a994af3acef0f88aa7bfa79 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Tue, 19 Mar 2019 21:47:29 +0100 Subject: [PATCH] correct json buffer size optimizations --- OpenMQTTGateway.ino | 3 +-- Zgateway2G.ino | 3 +-- ZgatewayIR.ino | 3 +-- ZgatewayLORA.ino | 3 +-- ZgatewayRF2.ino | 2 +- ZgatewayRFM69.ino | 3 +-- ZgatewaySRFB.ino | 3 +-- ZmqttDiscovery.ino | 2 +- ZsensorTSL2561.ino | 2 +- 9 files changed, 9 insertions(+), 15 deletions(-) diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index 5a73412..dd6dbb9 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -702,8 +702,7 @@ void stateMeasures(){ unsigned long now = millis(); if (now > (timer_sys_measures + TimeBetweenReadingSYS)) {//retriving value of memory ram every TimeBetweenReadingSYS timer_sys_measures = millis(); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4); - StaticJsonBuffer jsonBuffer; + StaticJsonBuffer jsonBuffer; JsonObject& SYSdata = jsonBuffer.createObject(); trc(F("Uptime (s)")); unsigned long uptime = millis()/1000; diff --git a/Zgateway2G.ino b/Zgateway2G.ino index 77935e1..68298a8 100644 --- a/Zgateway2G.ino +++ b/Zgateway2G.ino @@ -82,8 +82,7 @@ boolean _2GtoMQTT(){ // Get the memory locations of unread SMS messages. unreadSMSNum = A6l.getUnreadSMSLocs(unreadSMSLocs, 512); trc(F("Creating SMS buffer")); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3); - StaticJsonBuffer jsonBuffer; + StaticJsonBuffer jsonBuffer; JsonObject& SMSdata = jsonBuffer.createObject(); for (int i = 0; i < unreadSMSNum; i++) { trc(F("New message at index: ")); diff --git a/ZgatewayIR.ino b/ZgatewayIR.ino index ff88c5f..d8a7806 100644 --- a/ZgatewayIR.ino +++ b/ZgatewayIR.ino @@ -94,8 +94,7 @@ void IRtoMQTT(){ if (irrecv.decode(&results)){ trc(F("Creating IR buffer")); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4); - StaticJsonBuffer jsonBuffer; + StaticJsonBuffer jsonBuffer; JsonObject& IRdata = jsonBuffer.createObject(); trc(F("Rcv. IR")); diff --git a/ZgatewayLORA.ino b/ZgatewayLORA.ino index e376dad..70c8d9e 100644 --- a/ZgatewayLORA.ino +++ b/ZgatewayLORA.ino @@ -59,8 +59,7 @@ void setupLORA() { void LORAtoMQTT(){ int packetSize = LoRa.parsePacket(); if (packetSize) { - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5); - StaticJsonBuffer jsonBuffer; + StaticJsonBuffer jsonBuffer; JsonObject& LORAdata = jsonBuffer.createObject(); trc(F("Rcv. LORA")); #ifdef ESP32 diff --git a/ZgatewayRF2.ino b/ZgatewayRF2.ino index 80bee38..129d1a7 100644 --- a/ZgatewayRF2.ino +++ b/ZgatewayRF2.ino @@ -68,7 +68,7 @@ void RF2toMQTT(){ if(rf2rd.hasNewData){ trc(F("Creating RF2 buffer")); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4); + const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5); StaticJsonBuffer jsonBuffer; JsonObject& RF2data = jsonBuffer.createObject(); diff --git a/ZgatewayRFM69.ino b/ZgatewayRFM69.ino index af9df6e..1d6cd07 100644 --- a/ZgatewayRFM69.ino +++ b/ZgatewayRFM69.ino @@ -143,8 +143,7 @@ boolean RFM69toMQTT(void) { if (radio.receiveDone()) { trc(F("Creating RFM69 buffer")); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3); - StaticJsonBuffer jsonBuffer; + StaticJsonBuffer jsonBuffer; JsonObject& RFM69data = jsonBuffer.createObject(); uint8_t data[RF69_MAX_DATA_LEN+1]; // For the null character uint8_t SENDERID = radio.SENDERID; diff --git a/ZgatewaySRFB.ino b/ZgatewaySRFB.ino index ff863db..1fd3019 100644 --- a/ZgatewaySRFB.ino +++ b/ZgatewaySRFB.ino @@ -103,8 +103,7 @@ void _rfbDecode() { _rfbToChar(&_uartbuf[1], buffer); trc(F("Creating SRFB buffer")); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4); - StaticJsonBuffer jsonBuffer; + StaticJsonBuffer jsonBuffer; JsonObject& SRFBdata = jsonBuffer.createObject(); SRFBdata.set("raw", (char *)buffer); diff --git a/ZmqttDiscovery.ino b/ZmqttDiscovery.ino index 4349617..63506ef 100644 --- a/ZmqttDiscovery.ino +++ b/ZmqttDiscovery.ino @@ -358,7 +358,7 @@ void createDiscovery(char * sensor_type, int off_delay, char * payload_available, char * payload_not_avalaible, boolean child_device , char * command_topic) { - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(14) + JSON_OBJECT_SIZE(4); + const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(14) + JSON_OBJECT_SIZE(5)+ JSON_ARRAY_SIZE(1); StaticJsonBuffer jsonBuffer; JsonObject &sensor = jsonBuffer.createObject(); sensor.set("stat_t", state_topic); //state_topic diff --git a/ZsensorTSL2561.ino b/ZsensorTSL2561.ino index 6cdfece..6a41a95 100644 --- a/ZsensorTSL2561.ino +++ b/ZsensorTSL2561.ino @@ -92,7 +92,7 @@ void MeasureLightIntensityTSL2561() timetsl2561 = millis(); trc(F("Creating TSL2561 buffer")); - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4); + const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3); StaticJsonBuffer jsonBuffer; JsonObject& TSL2561data = jsonBuffer.createObject();