Browse Source

send status(battery..) as json

main
Hendrik Langer 7 years ago
parent
commit
e8688b8820
  1. 17
      src/main.cpp

17
src/main.cpp

@ -72,7 +72,7 @@ uint32_t lastTransmit = 0;
//Variables for the mqtt packages and topics
String commandTopic;
String bme280Topic;
String batteryTopic;
String statusTopic;
void setup() {
// gpio configuration
@ -90,7 +90,7 @@ void setup() {
//Configure the MQTT topics
commandTopic = "esp32-node/cmd/" + iot.hostname + "/play";
bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280";
batteryTopic = "esp32-node/stat/" + iot.hostname + "/battery";
statusTopic = "esp32-node/stat/" + iot.hostname + "/status";
/*
//Use the web object to add elements to the interface
@ -251,10 +251,15 @@ void transmitStatus() {
uint16_t statusPacketIdSub;
statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 0, false, sensorBuf);
// statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 1, true, sensorBuf);
int voltage = rom_phy_get_vdd33();
char batteryBuf[9];
sprintf(batteryBuf, "%d", voltage);
statusPacketIdSub = iot.mqtt.publish(batteryTopic.c_str(), 0, false, batteryBuf);
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(sensorBuf, sizeof(sensorBuf));
statusPacketIdSub = iot.mqtt.publish(statusTopic.c_str(), 0, false, statusBuf);
}

Loading…
Cancel
Save