Browse Source

Update code to ArduinoJSON 6

ci-update
Hendrik Langer 5 years ago
parent
commit
14ae8b8591
  1. 28
      src/main.cpp

28
src/main.cpp

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

Loading…
Cancel
Save