Replace fixed allocation of json buffer (#520)

* Replace fixed allocation of json buffer

by a dynamic one, and simplify trace function of json objects

* differentiate the change depending on board memory size

to make it works with UNO
This commit is contained in:
Florian authored and GitHub committed 2020-01-02 22:30:20 +01:00
1 parent bde80f408a
commit c524f04d1f
1 file changed
+9 -3
+9 -3
View File
@@ -288,9 +288,7 @@ void trc(float msg)
void trc(JsonObject &data) void trc(JsonObject &data)
{ {
char JSONmessageBuffer[JSON_MSG_BUFFER]; data.printTo(Serial);
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
trc(JSONmessageBuffer);
} }
void pub(char *topicori, char *payload, bool retainFlag) void pub(char *topicori, char *payload, bool retainFlag)
@@ -314,7 +312,11 @@ void pub(char *topicori, JsonObject &data)
#endif #endif
#ifdef jsonPublishing #ifdef jsonPublishing
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
char JSONmessageBuffer[data.measureLength() + 1];
#else
char JSONmessageBuffer[JSON_MSG_BUFFER]; char JSONmessageBuffer[JSON_MSG_BUFFER];
#endif
trc(F("Pub json into:")); trc(F("Pub json into:"));
trc(topic); trc(topic);
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer)); data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
@@ -389,7 +391,11 @@ void pub_custom_topic(char *topicori, JsonObject &data, boolean retain)
{ {
if (client.connected()) if (client.connected())
{ {
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
char JSONmessageBuffer[data.measureLength() + 1];
#else
char JSONmessageBuffer[JSON_MSG_BUFFER]; char JSONmessageBuffer[JSON_MSG_BUFFER];
#endif
trc(F("Pub json discovery into:")); trc(F("Pub json discovery into:"));
trc(topicori); trc(topicori);
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer)); data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));