mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
minor improvements
This commit is contained in:
20
src/mqtt.cpp
20
src/mqtt.cpp
@@ -640,7 +640,7 @@ void Mqtt::process_queue() {
|
|||||||
LOG_DEBUG(F("Subscribing to topic: %s"), message->topic.c_str());
|
LOG_DEBUG(F("Subscribing to topic: %s"), message->topic.c_str());
|
||||||
uint16_t packet_id = mqttClient_->subscribe(message->topic.c_str(), mqtt_qos_);
|
uint16_t packet_id = mqttClient_->subscribe(message->topic.c_str(), mqtt_qos_);
|
||||||
if (!packet_id) {
|
if (!packet_id) {
|
||||||
LOG_DEBUG(F("Error subscribing to %s, error %d"), message->topic.c_str(), packet_id);
|
LOG_DEBUG(F("Error subscribing to %s"), message->topic.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
mqtt_messages_.pop_front(); // remove the message from the queue
|
mqtt_messages_.pop_front(); // remove the message from the queue
|
||||||
@@ -714,8 +714,8 @@ void Mqtt::register_mqtt_ha_binary_sensor(const __FlashStringHelper * name, cons
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JsonObject dev = doc.createNestedObject(F("dev"));
|
JsonObject dev = doc.createNestedObject("dev");
|
||||||
JsonArray ids = dev.createNestedArray(F("ids"));
|
JsonArray ids = dev.createNestedArray("ids");
|
||||||
char ha_device[40];
|
char ha_device[40];
|
||||||
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), EMSdevice::device_type_2_device_name(device_type).c_str());
|
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), EMSdevice::device_type_2_device_name(device_type).c_str());
|
||||||
ids.add(ha_device);
|
ids.add(ha_device);
|
||||||
@@ -795,8 +795,8 @@ void Mqtt::register_mqtt_ha_sensor(const char * prefix,
|
|||||||
if (icon != nullptr) {
|
if (icon != nullptr) {
|
||||||
doc["ic"] = icon;
|
doc["ic"] = icon;
|
||||||
}
|
}
|
||||||
JsonObject dev = doc.createNestedObject(F("dev"));
|
JsonObject dev = doc.createNestedObject("dev");
|
||||||
JsonArray ids = dev.createNestedArray(F("ids"));
|
JsonArray ids = dev.createNestedArray("ids");
|
||||||
ids.add(ha_device);
|
ids.add(ha_device);
|
||||||
|
|
||||||
// convert json to string and publish immediately with retain forced to true
|
// convert json to string and publish immediately with retain forced to true
|
||||||
@@ -804,17 +804,17 @@ void Mqtt::register_mqtt_ha_sensor(const char * prefix,
|
|||||||
std::string payload_text;
|
std::string payload_text;
|
||||||
serializeJson(doc, payload_text); // convert json to string
|
serializeJson(doc, payload_text); // convert json to string
|
||||||
uint16_t packet_id = mqttClient_->publish(topic, 0, true, payload_text.c_str(), payload_text.size());
|
uint16_t packet_id = mqttClient_->publish(topic, 0, true, payload_text.c_str(), payload_text.size());
|
||||||
#if defined(EMSESP_STANDALONE)
|
|
||||||
LOG_DEBUG(F("Publishing topic %s"), topic);
|
|
||||||
#else
|
|
||||||
if (packet_id == 0) {
|
if (packet_id == 0) {
|
||||||
LOG_ERROR(F("Failed to publish topic %s"), topic);
|
LOG_ERROR(F("Failed to publish topic %s"), topic);
|
||||||
} else {
|
} else {
|
||||||
|
#if defined(EMSESP_STANDALONE)
|
||||||
|
LOG_DEBUG(F("Publishing topic=%s, payload=%s"), topic, payload_text.c_str());
|
||||||
|
#else
|
||||||
LOG_DEBUG(F("Publishing topic %s"), topic);
|
LOG_DEBUG(F("Publishing topic %s"), topic);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
delay(MQTT_PUBLISH_WAIT);
|
delay(MQTT_PUBLISH_WAIT); // don't flood asynctcp
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
Reference in New Issue
Block a user