Browse Source

fix mqtt json

main
Hendrik Langer 6 years ago
parent
commit
b071245b05
  1. 13
      src/main.cpp

13
src/main.cpp

@ -71,7 +71,7 @@ uint32_t lastTransmit = 0;
//Variables for the mqtt packages and topics
String commandTopic;
String bme280Topic;
String weatherTopic;
String statusTopic;
void setup() {
@ -89,7 +89,7 @@ void setup() {
//Configure the MQTT topics
commandTopic = "esp32-node/cmd/" + iot.hostname + "/play";
bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280";
weatherTopic = "esp32-node/stat/" + iot.hostname + "/weather";
statusTopic = "esp32-node/stat/" + iot.hostname + "/status";
/*
@ -246,11 +246,10 @@ void transmitStatus() {
root["temperature"] = internal_temp;
}
char sensorBuf[root.measureLength()+1];
root.printTo(sensorBuf, sizeof(sensorBuf));
char weatherBuf[root.measureLength()+1];
root.printTo(weatherBuf, sizeof(weatherBuf));
uint16_t statusPacketIdSub;
statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 0, false, sensorBuf);
// statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 1, true, sensorBuf);
statusPacketIdSub = iot.mqtt.publish(weatherTopic.c_str(), 0, false, weatherBuf);
StaticJsonBuffer<200> jsonBuffer2;
JsonObject& root2 = jsonBuffer2.createObject();
@ -258,7 +257,7 @@ void transmitStatus() {
root2["rssi"] = WiFi.RSSI();
root2["heap"] = ESP.getFreeHeap();
char statusBuf[root2.measureLength()+1];
root2.printTo(sensorBuf, sizeof(sensorBuf));
root2.printTo(statusBuf, sizeof(statusBuf));
statusPacketIdSub = iot.mqtt.publish(statusTopic.c_str(), 0, false, statusBuf);
}

Loading…
Cancel
Save