mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
always register subscriptions (#79)
This commit is contained in:
25
src/mqtt.cpp
25
src/mqtt.cpp
@@ -57,9 +57,6 @@ uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON};
|
|||||||
// subscribe to an MQTT topic, and store the associated callback function
|
// subscribe to an MQTT topic, and store the associated callback function
|
||||||
// only if it already hasn't been added
|
// only if it already hasn't been added
|
||||||
void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_subfunction_p cb) {
|
void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_subfunction_p cb) {
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if we already have the topic subscribed, if so don't add it again
|
// check if we already have the topic subscribed, if so don't add it again
|
||||||
if (!mqtt_subfunctions_.empty()) {
|
if (!mqtt_subfunctions_.empty()) {
|
||||||
@@ -74,18 +71,18 @@ void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(F("Subscribing MQTT topic %s for device type %s"), topic.c_str(), EMSdevice::device_type_2_device_name(device_type).c_str());
|
|
||||||
|
|
||||||
// add to MQTT queue as a subscribe operation
|
|
||||||
auto message = queue_subscribe_message(topic);
|
|
||||||
|
|
||||||
if (message == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// register in our libary with the callback function.
|
// register in our libary with the callback function.
|
||||||
// We store the original topic without base
|
// We store the original topic without base
|
||||||
mqtt_subfunctions_.emplace_back(device_type, std::move(topic), std::move(cb));
|
mqtt_subfunctions_.emplace_back(device_type, std::move(topic), std::move(cb));
|
||||||
|
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG(F("Subscribing MQTT topic %s for device type %s"), topic.c_str(), EMSdevice::device_type_2_device_name(device_type).c_str());
|
||||||
|
|
||||||
|
// add to MQTT queue as a subscribe operation
|
||||||
|
queue_subscribe_message(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
// subscribe to the command topic if it doesn't exist yet
|
// subscribe to the command topic if it doesn't exist yet
|
||||||
@@ -107,6 +104,10 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper
|
|||||||
LOG_DEBUG(F("Registering MQTT cmd %s with topic %s"), uuid::read_flash_string(cmd).c_str(), EMSdevice::device_type_2_device_name(device_type).c_str());
|
LOG_DEBUG(F("Registering MQTT cmd %s with topic %s"), uuid::read_flash_string(cmd).c_str(), EMSdevice::device_type_2_device_name(device_type).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// register the individual commands too (e.g. ems-esp/boiler/wwonetime)
|
// register the individual commands too (e.g. ems-esp/boiler/wwonetime)
|
||||||
// https://github.com/emsesp/EMS-ESP32/issues/31
|
// https://github.com/emsesp/EMS-ESP32/issues/31
|
||||||
std::string topic(MQTT_TOPIC_MAX_SIZE, '\0');
|
std::string topic(MQTT_TOPIC_MAX_SIZE, '\0');
|
||||||
|
|||||||
Reference in New Issue
Block a user