Skip to content

Commit 9c86aa1

Browse files
committed
Fix JSON serialization in “node-wifi-mqtt” again, there was an off-by-one-error. Thanks, Giuseppe!
1 parent 34c6ffa commit 9c86aa1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ in-progress
1717
- Improve firmwares :ref:`node-wifi-mqtt-homie` and :ref:`node-wifi-mqtt-homie-battery`
1818
- :ref:`node-wifi-mqtt`: Fix JSON serialization: Transmit sensor readings as float values. Thanks, Matthias!
1919
- :ref:`node-wifi-mqtt`: Improve configuration and documentation
20+
- :ref:`node-wifi-mqtt`: Fix JSON serialization again, there was an off-by-one-error. Thanks, Giuseppe!
2021

2122

2223
2017-03-17 0.13.0

node-wifi-mqtt/node-wifi-mqtt.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,8 @@ void loop() {
365365
getHumidityTemperature();
366366

367367

368-
// Prepare data, build JSON object
369-
370-
StaticJsonBuffer<256> jsonBuffer;
368+
// Build JSON object containing sensor readings
369+
StaticJsonBuffer<512> jsonBuffer;
371370

372371
JsonObject& root = jsonBuffer.createObject();
373372
root["weight"] = String(weightChar).toFloat();
@@ -384,7 +383,8 @@ void loop() {
384383

385384

386385
// Serialize data
387-
char payload[256];
386+
int json_length = root.measureLength();
387+
char payload[json_length+1];
388388
root.printTo(payload, sizeof(payload));
389389

390390

0 commit comments

Comments
 (0)