diff --git a/src/main.cpp b/src/main.cpp index 4e09081..f9ed390 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -264,28 +264,26 @@ void transmitStatus() { pres = bme280.readPressure(); } - StaticJsonBuffer<200> jsonBuffer; - JsonObject& root = jsonBuffer.createObject(); + StaticJsonDocument<200> jsonDocument; if (bme280.valid) { - root["temperature"] = temp; - root["humidity"] = humi; - root["pressure"] = pres; + jsonDocument["temperature"] = temp; + jsonDocument["humidity"] = humi; + jsonDocument["pressure"] = pres; } else { - //root["temperature"] = internal_temp; + //jsonDocument["temperature"] = internal_temp; } - char weatherBuf[root.measureLength()+1]; - root.printTo(weatherBuf, sizeof(weatherBuf)); + char weatherBuf[measureJson(jsonDocument)+1]; + serialize(jsonDocument, weatherBuf, sizeof(weatherBuf)); uint16_t statusPacketIdSub; statusPacketIdSub = iot.mqtt.publish(weatherTopic.c_str(), 0, false, weatherBuf); - StaticJsonBuffer<200> jsonBuffer2; - JsonObject& root2 = jsonBuffer2.createObject(); - root2["voltage"] = rom_phy_get_vdd33(); - root2["rssi"] = WiFi.RSSI(); - root2["heap"] = ESP.getFreeHeap(); - char statusBuf[root2.measureLength()+1]; - root2.printTo(statusBuf, sizeof(statusBuf)); + StaticJsonDocument<200> jsonDocument2; + jsonDocument2["voltage"] = rom_phy_get_vdd33(); + jsonDocument2["rssi"] = WiFi.RSSI(); + jsonDocument2["heap"] = ESP.getFreeHeap(); + char statusBuf[measureJson(jsonDocument2)+1]; + serialize(jsonDocument2, statusBuf, sizeof(statusBuf)); statusPacketIdSub = iot.mqtt.publish(statusTopic.c_str(), 0, false, statusBuf); }