Browse Source

Subscribe to MQTT domoticz out topic only if domoticz is enabled (#344)

i18n
Xose Pérez 6 years ago
parent
commit
c0d63ff41c
1 changed files with 14 additions and 2 deletions
  1. +14
    -2
      code/espurna/domoticz.ino

+ 14
- 2
code/espurna/domoticz.ino View File

@ -35,8 +35,21 @@ bool _domoticzSkip(unsigned long idx) {
return false; return false;
} }
void _domoticzMqttSubscribe(bool value) {
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
if (value) {
mqttSubscribeRaw(dczTopicOut.c_str());
} else {
mqttUnsubscribeRaw(dczTopicOut.c_str());
}
}
void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) { void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) {
if (!_dcz_enabled) return;
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
if (type == MQTT_CONNECT_EVENT) { if (type == MQTT_CONNECT_EVENT) {
@ -45,8 +58,6 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
if (type == MQTT_MESSAGE_EVENT) { if (type == MQTT_MESSAGE_EVENT) {
if (!_dcz_enabled) return;
// Check topic // Check topic
if (dczTopicOut.equals(topic)) { if (dczTopicOut.equals(topic)) {
@ -107,6 +118,7 @@ void _domoticzWebSocketOnSend(JsonObject& root) {
void _domoticzConfigure() { void _domoticzConfigure() {
_dcz_enabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1; _dcz_enabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
_dcz_skip_time = 1000 * getSetting("dczSkip", DOMOTICZ_SKIP_TIME).toInt(); _dcz_skip_time = 1000 * getSetting("dczSkip", DOMOTICZ_SKIP_TIME).toInt();
_domoticzMqttSubscribe(_dcz_enabled);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


Loading…
Cancel
Save