Browse Source

Option to globally disable domoticz from web interface

fastled
Xose Pérez 7 years ago
parent
commit
36af250e10
6 changed files with 2816 additions and 2777 deletions
  1. +2
    -1
      code/espurna/config/general.h
  2. +45
    -26
      code/espurna/domoticz.ino
  3. +1
    -1
      code/espurna/relay.ino
  4. +2749
    -2748
      code/espurna/static/index.html.gz.h
  5. +14
    -1
      code/espurna/web.ino
  6. +5
    -0
      code/html/index.html

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

@ -359,8 +359,9 @@ PROGMEM const char* const custom_reset_string[] = {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef ENABLE_DOMOTICZ #ifndef ENABLE_DOMOTICZ
#define ENABLE_DOMOTICZ 1 // Enable Domoticz support by default
#define ENABLE_DOMOTICZ 1 // Build with domoticz support
#endif #endif
#define DOMOTICZ_ENABLED 1 // Enable domoticz by default
#define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic #define DOMOTICZ_IN_TOPIC "domoticz/in" // Default subscription topic
#define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic #define DOMOTICZ_OUT_TOPIC "domoticz/out" // Default publication topic


+ 45
- 26
code/espurna/domoticz.ino View File

@ -10,40 +10,21 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h> #include <ArduinoJson.h>
template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue) {
unsigned int idx = getSetting(key).toInt();
if (idx > 0) {
char payload[128];
snprintf(payload, 128, "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload);
}
}
template<typename T> void domoticzSend(const char * key, T nvalue) {
domoticzSend(key, nvalue, "");
}
bool _dczEnabled = false;
void relayDomoticzSend(unsigned int relayID) {
char buffer[15];
sprintf(buffer, "dczRelayIdx%d", relayID);
domoticzSend(buffer, relayStatus(relayID) ? "1" : "0");
}
//------------------------------------------------------------------------------
// Private methods
//------------------------------------------------------------------------------
int relayFromIdx(unsigned int idx) {
int _domoticzRelay(unsigned int idx) {
for (int relayID=0; relayID<relayCount(); relayID++) { for (int relayID=0; relayID<relayCount(); relayID++) {
if (relayToIdx(relayID) == idx) {
if (domoticzIdx(relayID) == idx) {
return relayID; return relayID;
} }
} }
return -1; return -1;
} }
int relayToIdx(unsigned int relayID) {
char buffer[15];
sprintf(buffer, "dczRelayIdx%d", relayID);
return getSetting(buffer).toInt();
}
void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) { void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) {
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
@ -54,6 +35,8 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
if (type == MQTT_MESSAGE_EVENT) { if (type == MQTT_MESSAGE_EVENT) {
if (!_dczEnabled) return;
// Check topic // Check topic
if (dczTopicOut.equals(topic)) { if (dczTopicOut.equals(topic)) {
@ -67,7 +50,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
// IDX // IDX
unsigned long idx = root["idx"]; unsigned long idx = root["idx"];
int relayID = relayFromIdx(idx);
int relayID = _domoticzRelay(idx);
if (relayID >= 0) { if (relayID >= 0) {
unsigned long value = root["nvalue"]; unsigned long value = root["nvalue"];
DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx);
@ -80,7 +63,43 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
}; };
//------------------------------------------------------------------------------
// Public API
//------------------------------------------------------------------------------
template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue) {
if (!_dczEnabled) return;
unsigned int idx = getSetting(key).toInt();
if (idx > 0) {
char payload[128];
snprintf(payload, 128, "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload);
}
}
template<typename T> void domoticzSend(const char * key, T nvalue) {
domoticzSend(key, nvalue, "");
}
void domoticzSendRelay(unsigned int relayID) {
if (!_dczEnabled) return;
char buffer[15];
sprintf(buffer, "dczRelayIdx%d", relayID);
domoticzSend(buffer, relayStatus(relayID) ? "1" : "0");
}
int domoticzIdx(unsigned int relayID) {
char buffer[15];
sprintf(buffer, "dczRelayIdx%d", relayID);
return getSetting(buffer).toInt();
}
void domoticzConfigure() {
_dczEnabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
}
void domoticzSetup() { void domoticzSetup() {
domoticzConfigure();
mqttRegister(_domoticzMqtt); mqttRegister(_domoticzMqtt);
} }


+ 1
- 1
code/espurna/relay.ino View File

@ -500,7 +500,7 @@ void relayLoop(void) {
} }
#if ENABLE_DOMOTICZ #if ENABLE_DOMOTICZ
relayDomoticzSend(id);
domoticzSendRelay(id);
#endif #endif
#if ENABLE_INFLUXDB #if ENABLE_INFLUXDB


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


+ 14
- 1
code/espurna/web.ino View File

@ -207,6 +207,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
#if ENABLE_FAUXMO #if ENABLE_FAUXMO
bool fauxmoEnabled = false; bool fauxmoEnabled = false;
#endif #endif
#if ENABLE_DOMOTICZ
bool dczEnabled = false;
#endif
unsigned int network = 0; unsigned int network = 0;
unsigned int dczRelayIdx = 0; unsigned int dczRelayIdx = 0;
String adminPass; String adminPass;
@ -298,6 +301,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
#if ENABLE_FAUXMO #if ENABLE_FAUXMO
if (key == "fauxmoEnabled") { fauxmoEnabled = true; continue; } if (key == "fauxmoEnabled") { fauxmoEnabled = true; continue; }
#endif #endif
#if ENABLE_DOMOTICZ
if (key == "dczEnabled") { dczEnabled = true; continue; }
#endif
if (key == "ssid") { if (key == "ssid") {
key = key + String(network); key = key + String(network);
@ -341,6 +347,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
#if ENABLE_FAUXMO #if ENABLE_FAUXMO
setBoolSetting("fauxmoEnabled", fauxmoEnabled, FAUXMO_ENABLED); setBoolSetting("fauxmoEnabled", fauxmoEnabled, FAUXMO_ENABLED);
#endif #endif
#if ENABLE_DOMOTICZ
setBoolSetting("dczEnabled", dczEnabled, DOMOTICZ_ENABLED);
#endif
// Clean wifi networks // Clean wifi networks
int i = 0; int i = 0;
@ -383,6 +392,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
#if ENABLE_INFLUXDB #if ENABLE_INFLUXDB
influxDBConfigure(); influxDBConfigure();
#endif #endif
#if ENABLE_DOMOTICZ
domoticzConfigure();
#endif
mqttConfigure(); mqttConfigure();
#if ENABLE_RF #if ENABLE_RF
@ -505,12 +517,13 @@ void _wsStart(uint32_t client_id) {
#if ENABLE_DOMOTICZ #if ENABLE_DOMOTICZ
root["dczVisible"] = 1; root["dczVisible"] = 1;
root["dczEnabled"] = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1;
root["dczTopicIn"] = getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC); root["dczTopicIn"] = getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC);
root["dczTopicOut"] = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); root["dczTopicOut"] = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC);
JsonArray& dczRelayIdx = root.createNestedArray("dczRelayIdx"); JsonArray& dczRelayIdx = root.createNestedArray("dczRelayIdx");
for (byte i=0; i<relayCount(); i++) { for (byte i=0; i<relayCount(); i++) {
dczRelayIdx.add(relayToIdx(i));
dczRelayIdx.add(domoticzIdx(i));
} }
#if ENABLE_DHT #if ENABLE_DHT


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

@ -597,6 +597,11 @@
<fieldset> <fieldset>
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-4"><label for="dczEnabled">Enable Domoticz</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="dczEnabled" tabindex="30" /></div>
</div>
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="dczTopicIn">Domoticz IN Topic</label> <label class="pure-u-1 pure-u-md-1-4" for="dczTopicIn">Domoticz IN Topic</label>
<input class="pure-u-1 pure-u-md-3-4" name="dczTopicIn" type="text" tabindex="31" /> <input class="pure-u-1 pure-u-md-3-4" name="dczTopicIn" type="text" tabindex="31" />


Loading…
Cancel
Save