Browse Source

Removed anti-recursion check in Domoticz module

i18n
Xose Pérez 6 years ago
parent
commit
9062c70e63
5 changed files with 3087 additions and 3120 deletions
  1. +0
    -1
      code/espurna/config/general.h
  2. BIN
      code/espurna/data/index.html.gz
  3. +0
    -22
      code/espurna/domoticz.ino
  4. +3087
    -3089
      code/espurna/static/index.html.gz.h
  5. +0
    -8
      code/html/index.html

+ 0
- 1
code/espurna/config/general.h View File

@ -604,7 +604,6 @@ PROGMEM const char* const custom_reset_string[] = {
#define DOMOTICZ_ENABLED 0 // Disable domoticz by default
#define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
#define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic
#define DOMOTICZ_SKIP_TIME 2 // Avoid recursion skipping messages to same IDX within 2 seconds
// -----------------------------------------------------------------------------
// HOME ASSISTANT


BIN
code/espurna/data/index.html.gz View File


+ 0
- 22
code/espurna/domoticz.ino View File

@ -11,9 +11,6 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h>
bool _dcz_enabled = false;
unsigned long _dcz_skip_time = 0;
unsigned long _dcz_last_idx = 0;
unsigned long _dcz_last_time = 0;
//------------------------------------------------------------------------------
// Private methods
@ -28,13 +25,6 @@ int _domoticzRelay(unsigned int idx) {
return -1;
}
bool _domoticzSkip(unsigned long idx) {
if (idx == _dcz_last_idx && (millis() - _dcz_last_time < _dcz_skip_time)) return true;
_dcz_last_idx = idx;
_dcz_last_time = millis();
return false;
}
void _domoticzMqttSubscribe(bool value) {
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
@ -73,14 +63,9 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
unsigned long idx = root["idx"];
int relayID = _domoticzRelay(idx);
if (relayID >= 0) {
// Skip message if recursive
if (_domoticzSkip(idx)) return;
unsigned long value = root["nvalue"];
DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx);
relayStatus(relayID, value == 1);
}
}
@ -93,7 +78,6 @@ void _domoticzWebSocketOnSend(JsonObject& root) {
root["dczVisible"] = 1;
root["dczEnabled"] = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
root["dczSkip"] = getSetting("dczSkip", DOMOTICZ_SKIP_TIME);
root["dczTopicIn"] = getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC);
root["dczTopicOut"] = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
@ -117,7 +101,6 @@ void _domoticzWebSocketOnSend(JsonObject& root) {
void _domoticzConfigure() {
_dcz_enabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
_dcz_skip_time = 1000 * getSetting("dczSkip", DOMOTICZ_SKIP_TIME).toInt();
_domoticzMqttSubscribe(_dcz_enabled);
}
@ -129,14 +112,9 @@ template<typename T> void domoticzSend(const char * key, T nvalue, const char *
if (!_dcz_enabled) return;
unsigned int idx = getSetting(key).toInt();
if (idx > 0) {
// Skip message if recursive
if (_domoticzSkip(idx)) return;
char payload[128];
snprintf(payload, sizeof(payload), "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload);
}
}


+ 3087
- 3089
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 0
- 8
code/html/index.html View File

@ -718,14 +718,6 @@
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="dczEnabled" tabindex="30" /></div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Anti-recursion time</label>
<div class="pure-u-1 pure-u-lg-1-4"><input class="pure-u-23-24" name="dczSkip" type="number" min="0" max="10" tabindex="31" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-1-2 hint">Skip messages from the same IDX for these many seconds</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Domoticz IN Topic</label>
<input class="pure-u-1 pure-u-lg-3-4" name="dczTopicIn" type="text" tabindex="31" />


Loading…
Cancel
Save