mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
ignore mqtt echos if publish_single2command is set.
This commit is contained in:
10
src/mqtt.cpp
10
src/mqtt.cpp
@@ -55,6 +55,9 @@ uint8_t Mqtt::connectcount_ = 0;
|
|||||||
uint32_t Mqtt::mqtt_message_id_ = 0;
|
uint32_t Mqtt::mqtt_message_id_ = 0;
|
||||||
char will_topic_[Mqtt::MQTT_TOPIC_MAX_SIZE]; // because MQTT library keeps only char pointer
|
char will_topic_[Mqtt::MQTT_TOPIC_MAX_SIZE]; // because MQTT library keeps only char pointer
|
||||||
|
|
||||||
|
std::string Mqtt::lasttopic_ = "";
|
||||||
|
std::string Mqtt::lastpayload_ = "";
|
||||||
|
|
||||||
// Home Assistant specific
|
// Home Assistant specific
|
||||||
// icons from https://materialdesignicons.com used with the UOMs (unit of measurements)
|
// icons from https://materialdesignicons.com used with the UOMs (unit of measurements)
|
||||||
MAKE_PSTR_WORD(measurement)
|
MAKE_PSTR_WORD(measurement)
|
||||||
@@ -277,6 +280,11 @@ void Mqtt::on_message(const char * topic, const char * payload, size_t len) cons
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// for misconfigured mqtt servers and publish2command ignore echos
|
||||||
|
if (publish_single_ && publish_single2cmd_ && lasttopic_ == topic && lastpayload_ == message) {
|
||||||
|
LOG_DEBUG("Received echo message %s: %s", topic, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// check first against any of our subscribed topics
|
// check first against any of our subscribed topics
|
||||||
for (const auto & mf : mqtt_subfunctions_) {
|
for (const auto & mf : mqtt_subfunctions_) {
|
||||||
@@ -857,6 +865,8 @@ void Mqtt::process_queue() {
|
|||||||
|
|
||||||
// else try and publish it
|
// else try and publish it
|
||||||
uint16_t packet_id = mqttClient_->publish(topic, mqtt_qos_, message->retain, message->payload.c_str(), message->payload.size(), false, mqtt_message.id_);
|
uint16_t packet_id = mqttClient_->publish(topic, mqtt_qos_, message->retain, message->payload.c_str(), message->payload.size(), false, mqtt_message.id_);
|
||||||
|
lasttopic_ = topic;
|
||||||
|
lastpayload_ = message->payload;
|
||||||
LOG_DEBUG("Publishing topic %s (#%02d, retain=%d, retry=%d, size=%d, pid=%d)",
|
LOG_DEBUG("Publishing topic %s (#%02d, retain=%d, retry=%d, size=%d, pid=%d)",
|
||||||
topic,
|
topic,
|
||||||
mqtt_message.id_,
|
mqtt_message.id_,
|
||||||
|
|||||||
@@ -297,6 +297,9 @@ class Mqtt {
|
|||||||
static uint8_t connectcount_;
|
static uint8_t connectcount_;
|
||||||
static bool ha_climate_reset_;
|
static bool ha_climate_reset_;
|
||||||
|
|
||||||
|
static std::string lasttopic_;
|
||||||
|
static std::string lastpayload_;
|
||||||
|
|
||||||
// settings, copied over
|
// settings, copied over
|
||||||
static std::string mqtt_base_;
|
static std::string mqtt_base_;
|
||||||
static std::string mqtt_basename_;
|
static std::string mqtt_basename_;
|
||||||
|
|||||||
Reference in New Issue
Block a user