From 7f41967e7aaf69ee5aa226c623ab33853906dea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 12 Aug 2017 00:26:18 +0200 Subject: [PATCH] Moved domoticz code from relay.ino to domoticz.ino --- code/espurna/domoticz.ino | 63 ++++++++++++++++++++++++++++++++++ code/espurna/espurna.ino | 3 ++ code/espurna/relay.ino | 71 --------------------------------------- 3 files changed, 66 insertions(+), 71 deletions(-) diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 6534b91f..bd33db03 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -8,6 +8,8 @@ Copyright (C) 2016-2017 by Xose PĂ©rez #if ENABLE_DOMOTICZ +#include + template void domoticzSend(const char * key, T nvalue, const char * svalue) { unsigned int idx = getSetting(key).toInt(); if (idx > 0) { @@ -21,4 +23,65 @@ template void domoticzSend(const char * key, T nvalue) { domoticzSend(key, nvalue, ""); } +void relayDomoticzSend(unsigned int relayID) { + char buffer[15]; + sprintf(buffer, "dczRelayIdx%d", relayID); + domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); +} + +int relayFromIdx(unsigned int idx) { + for (int relayID=0; relayID= 0) { + unsigned long value = root["nvalue"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); + relayStatus(relayID, value == 1); + } + + } + + } + + }); +} + + #endif diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 3ff54f9d..e8edfd43 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -244,6 +244,9 @@ void setup() { #if ENABLE_EMON powerMonitorSetup(); #endif + #if ENABLE_DOMOTICZ + domoticzSetup(); + #endif // Prepare configuration for version 2.0 hwUpwardsCompatibility(); diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 950167c9..ae50ca20 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -306,74 +306,6 @@ void relayWS() { wsSend(output.c_str()); } -//------------------------------------------------------------------------------ -// Domoticz -//------------------------------------------------------------------------------ - -#if ENABLE_DOMOTICZ - -void relayDomoticzSend(unsigned int relayID) { - char buffer[15]; - sprintf(buffer, "dczRelayIdx%d", relayID); - domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); -} - -int relayFromIdx(unsigned int idx) { - for (int relayID=0; relayID= 0) { - unsigned long value = root["nvalue"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); - relayStatus(relayID, value == 1); - } - - } - - } - - }); -} - -#endif - //------------------------------------------------------------------------------ // MQTT //------------------------------------------------------------------------------ @@ -495,9 +427,6 @@ void relaySetup() { relaySetupAPI(); relaySetupMQTT(); - #if ENABLE_DOMOTICZ - relayDomoticzSetup(); - #endif DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size());