fix: ignore MQTT messages for disabled components #203 (#204)

This commit is contained in:
helgeerbe 2023-04-28 19:26:58 +02:00 committed by GitHub
parent c621f2d3e3
commit 5d4c6866da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -73,6 +73,11 @@ void MqttHandleHuaweiClass::onMqttMessage(const espMqttClientTypes::MessagePrope
{ {
const CONFIG_T& config = Configuration.get(); const CONFIG_T& config = Configuration.get();
// ignore messages if Huawei is disabled
if (!config.Huawei_Enabled) {
return;
}
char token_topic[MQTT_MAX_TOPIC_STRLEN + 40]; // respect all subtopics char token_topic[MQTT_MAX_TOPIC_STRLEN + 40]; // respect all subtopics
strncpy(token_topic, topic, MQTT_MAX_TOPIC_STRLEN + 40); // convert const char* to char* strncpy(token_topic, topic, MQTT_MAX_TOPIC_STRLEN + 40); // convert const char* to char*

View File

@ -49,6 +49,11 @@ void MqttHandlePowerLimiterClass::loop()
void MqttHandlePowerLimiterClass::onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) void MqttHandlePowerLimiterClass::onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
{ {
const CONFIG_T& config = Configuration.get(); const CONFIG_T& config = Configuration.get();
// ignore messages if PowerLimiter is disabled
if (!config.PowerLimiter_Enabled) {
return;
}
char token_topic[MQTT_MAX_TOPIC_STRLEN + 40]; // respect all subtopics char token_topic[MQTT_MAX_TOPIC_STRLEN + 40]; // respect all subtopics
strncpy(token_topic, topic, MQTT_MAX_TOPIC_STRLEN + 40); // convert const char* to char* strncpy(token_topic, topic, MQTT_MAX_TOPIC_STRLEN + 40); // convert const char* to char*