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:
1 parent
bde80f408a
commit
c524f04d1f
1 file changed
+9
-3
+9
-3
@@ -288,9 +288,7 @@ void trc(float msg)
|
||||
|
||||
void trc(JsonObject &data)
|
||||
{
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
trc(JSONmessageBuffer);
|
||||
data.printTo(Serial);
|
||||
}
|
||||
|
||||
void pub(char *topicori, char *payload, bool retainFlag)
|
||||
@@ -314,7 +312,11 @@ void pub(char *topicori, JsonObject &data)
|
||||
#endif
|
||||
|
||||
#ifdef jsonPublishing
|
||||
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
|
||||
char JSONmessageBuffer[data.measureLength() + 1];
|
||||
#else
|
||||
char JSONmessageBuffer[JSON_MSG_BUFFER];
|
||||
#endif
|
||||
trc(F("Pub json into:"));
|
||||
trc(topic);
|
||||
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
@@ -389,7 +391,11 @@ void pub_custom_topic(char *topicori, JsonObject &data, boolean retain)
|
||||
{
|
||||
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];
|
||||
#endif
|
||||
trc(F("Pub json discovery into:"));
|
||||
trc(topicori);
|
||||
data.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
|
||||
|
||||
Reference in new issue
Block a user