mqtt publish state fix

This commit is contained in:
Yuri Trikoz
2020-06-22 18:09:39 +03:00
parent 8f395ccc8a
commit b50911ddcf
2 changed files with 8 additions and 4 deletions

View File

@@ -92,6 +92,8 @@ boolean connectMQTT() {
mqttRootDevice = mqttPrefix + "/" + chipId;
pm.info("broker " + addr + ":" + String(port, DEC));
pm.info("root " + mqttRootDevice);
setLedStatus(LED_FAST);
mqtt.setServer(addr.c_str(), port);
bool res = false;
@@ -200,7 +202,7 @@ boolean publishStatus(const String& topic, const String& data) {
String path = mqttRootDevice + "/" + topic + "/status";
String json = "{}";
jsonWriteStr(json, "status", data);
return mqtt.publish(topic.c_str(), json.c_str(), false);
return mqtt.publish(path.c_str(), json.c_str(), false);
}
//=====================================================ОТПРАВЛЯЕМ ВИДЖЕТЫ========================================================

View File

@@ -626,10 +626,12 @@ void bme280A() {
}
void bme280A_reading() {
float value = 0;
value = bme.readAltitude(1013.25);
jsonWriteStr(configLiveJson, bme280A_value_name, String(value));
float value = bme.readAltitude(1013.25);
jsonWriteStr(configLiveJson, bme280A_value_name, String(value, 2));
eventGen(bme280A_value_name, "");
publishStatus(bme280A_value_name, String(value));
Serial.println("[I] sensor '" + bme280A_value_name + "' data: " + String(value));
}