From 62d05b77ffc333ff0560b62d2ce9122403aa2f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 26 Jun 2018 21:59:01 +0200 Subject: [PATCH] Key renaming, first round --- README.md | 6 +- code/espurna/alexa.ino | 18 +++-- code/espurna/api.ino | 8 +- code/espurna/broker.ino | 2 + code/espurna/button.ino | 2 + code/espurna/debug.ino | 2 + code/espurna/domoticz.ino | 2 + code/espurna/eeprom.ino | 4 + code/espurna/espurna.ino | 4 +- code/espurna/gpio.ino | 2 + code/espurna/homeassistant.ino | 2 + code/espurna/i2c.ino | 13 ++++ code/espurna/influxdb.ino | 26 +++++-- code/espurna/ir.ino | 2 + code/espurna/led.ino | 2 + code/espurna/light.ino | 77 +++++++++++-------- code/espurna/mdns.ino | 2 +- code/espurna/migrate.ino | 6 +- code/espurna/mqtt.ino | 14 +++- code/espurna/nofuss.ino | 25 ++++-- code/espurna/ntp.ino | 8 ++ code/espurna/ota.ino | 18 ++++- code/espurna/relay.ino | 38 ++++++---- code/espurna/rf.ino | 2 + code/espurna/rfbridge.ino | 4 +- code/espurna/scheduler.ino | 2 + code/espurna/sensor.ino | 135 +++++++++++++++++++-------------- code/espurna/settings.ino | 19 +++++ code/espurna/ssdp.ino | 2 + code/espurna/system.ino | 2 + code/espurna/telnet.ino | 17 ++++- code/espurna/thinkspeak.ino | 2 + code/espurna/uartmqtt.ino | 2 + code/espurna/utils.ino | 2 + code/espurna/web.ino | 2 + code/espurna/wifi.ino | 2 + code/html/custom.js | 28 +++---- code/html/index.html | 98 ++++++++++++------------ 38 files changed, 399 insertions(+), 203 deletions(-) diff --git a/README.md b/README.md index 2db727b5..fcba64be 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.13.1a-brightgreen.svg)](CHANGELOG.md) -[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/) -[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) -[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) +[![branch](https://img.shields.io/badge/branch-softcfg-orange.svg)](https://github.com/xoseperez/espurna/tree/softcfg/) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=softcfg)](https://travis-ci.org/xoseperez/espurna) +[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/softcfg.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest) diff --git a/code/espurna/alexa.ino b/code/espurna/alexa.ino index 81815d8b..9942df3b 100644 --- a/code/espurna/alexa.ino +++ b/code/espurna/alexa.ino @@ -4,6 +4,8 @@ ALEXA MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: alx + */ #if ALEXA_SUPPORT @@ -24,24 +26,28 @@ static std::queue _alexa_dev_changes; // ----------------------------------------------------------------------------- bool _alexaWebSocketOnReceive(const char * key, JsonVariant& value) { - return (strncmp(key, "alexa", 5) == 0); + return (strncmp(key, "alx", 3) == 0); } void _alexaWebSocketOnSend(JsonObject& root) { - root["alexaVisible"] = 1; - root["alexaEnabled"] = getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1; + root["alxVisible"] = 1; + root["alxEnabled"] = getSetting("alxEnabled", ALEXA_ENABLED).toInt() == 1; } void _alexaConfigure() { - alexa.enable(getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1); + alexa.enable(getSetting("alxEnabled", ALEXA_ENABLED).toInt() == 1); } +void _alexaBackwards() { + moveSetting("fauxmoEnabled", "alxEnabled"); // 1.9.0 - 2017-08-25 + moveSetting("alexaEnabled", "alxEnabled"); // 1.13.1 - 2018-06-27 +} // ----------------------------------------------------------------------------- void alexaSetup() { - // Backwards compatibility - moveSetting("fauxmoEnabled", "alexaEnabled"); + // Check backwards compatibility + _alexaBackwards(); // Load & cache settings _alexaConfigure(); diff --git a/code/espurna/api.ino b/code/espurna/api.ino index c1c33281..545bc381 100644 --- a/code/espurna/api.ino +++ b/code/espurna/api.ino @@ -4,6 +4,8 @@ API MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: api + */ #if WEB_SUPPORT @@ -29,7 +31,7 @@ bool _apiWebSocketOnReceive(const char * key, JsonVariant& value) { void _apiWebSocketOnSend(JsonObject& root) { root["apiEnabled"] = getSetting("apiEnabled", API_ENABLED).toInt() == 1; root["apiKey"] = getSetting("apiKey"); - root["apiRealTime"] = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1; + root["apiRealTime"] = apiRealTime(); } // ----------------------------------------------------------------------------- @@ -199,4 +201,8 @@ void apiSetup() { wsOnReceiveRegister(_apiWebSocketOnReceive); } +bool apiRealTime() { + return getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1; +} + #endif // WEB_SUPPORT diff --git a/code/espurna/broker.ino b/code/espurna/broker.ino index 6db86e20..0779ec36 100644 --- a/code/espurna/broker.ino +++ b/code/espurna/broker.ino @@ -4,6 +4,8 @@ BROKER MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: bkr + */ #if BROKER_SUPPORT diff --git a/code/espurna/button.ino b/code/espurna/button.ino index ea550e1f..a2335bca 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -4,6 +4,8 @@ BUTTON MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: btn + */ // ----------------------------------------------------------------------------- diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 7eea7ccb..112a3ab7 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -4,6 +4,8 @@ DEBUG MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: dbg + */ #if DEBUG_SUPPORT diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index d2622eca..931cd776 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -4,6 +4,8 @@ DOMOTICZ MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: dcz + */ #if DOMOTICZ_SUPPORT diff --git a/code/espurna/eeprom.ino b/code/espurna/eeprom.ino index 2e79fcbb..d0a7fca6 100644 --- a/code/espurna/eeprom.ino +++ b/code/espurna/eeprom.ino @@ -2,6 +2,10 @@ EEPROM MODULE +Copyright (C) 2018 by Xose Pérez + +Module key prefix: eep + */ #include diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index def70f6b..d5f2f3e6 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -17,6 +17,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . +Module key prefix: esp (shared with others) + */ #include "config/all.h" @@ -49,7 +51,7 @@ void setup() { // Init EEPROM eepromSetup(); - + // Init Serial, SPIFFS and system check systemSetup(); diff --git a/code/espurna/gpio.ino b/code/espurna/gpio.ino index c69f437a..4e53cf3f 100644 --- a/code/espurna/gpio.ino +++ b/code/espurna/gpio.ino @@ -4,6 +4,8 @@ GPIO MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: io + */ unsigned int _gpio_locked = 0; diff --git a/code/espurna/homeassistant.ino b/code/espurna/homeassistant.ino index 9b8c8934..b0820c24 100644 --- a/code/espurna/homeassistant.ino +++ b/code/espurna/homeassistant.ino @@ -4,6 +4,8 @@ HOME ASSISTANT MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: ha + */ #if HOMEASSISTANT_SUPPORT diff --git a/code/espurna/i2c.ino b/code/espurna/i2c.ino index 8300929a..95f7dbfc 100644 --- a/code/espurna/i2c.ino +++ b/code/espurna/i2c.ino @@ -4,6 +4,8 @@ I2C MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: i2c + */ #if I2C_SUPPORT @@ -104,6 +106,13 @@ int _i2cClearbus(int sda, int scl) { } +#if WEB_SUPPORT + +bool _i2cWebSocketOnReceive(const char * key, JsonVariant& value) { + return (strncmp(key, "i2c", 3) == 0); +} + +#endif // WEB_SUPPORT // --------------------------------------------------------------------- // I2C API // --------------------------------------------------------------------- @@ -364,6 +373,10 @@ void i2cSetup() { Wire.begin(sda, scl); #endif + #if WEB_SUPPORT + wsOnReceiveRegister(_i2cWebSocketOnReceive); + #endif + DEBUG_MSG_P(PSTR("[I2C] Using GPIO%u for SDA and GPIO%u for SCL\n"), sda, scl); #if I2C_CLEAR_BUS diff --git a/code/espurna/influxdb.ino b/code/espurna/influxdb.ino index 041ce6c6..d20755e7 100644 --- a/code/espurna/influxdb.ino +++ b/code/espurna/influxdb.ino @@ -4,6 +4,8 @@ INFLUXDB MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: idb + */ #if INFLUXDB_SUPPORT @@ -16,6 +18,8 @@ SyncClient _idb_client; // ----------------------------------------------------------------------------- +#if WEB_SUPPORT + bool _idbWebSocketOnReceive(const char * key, JsonVariant& value) { return (strncmp(key, "idb", 3) == 0); } @@ -25,9 +29,9 @@ void _idbWebSocketOnSend(JsonObject& root) { root["idbEnabled"] = getSetting("idbEnabled", INFLUXDB_ENABLED).toInt() == 1; root["idbHost"] = getSetting("idbHost", INFLUXDB_HOST); root["idbPort"] = getSetting("idbPort", INFLUXDB_PORT).toInt(); - root["idbDatabase"] = getSetting("idbDatabase", INFLUXDB_DATABASE); - root["idbUsername"] = getSetting("idbUsername", INFLUXDB_USERNAME); - root["idbPassword"] = getSetting("idbPassword", INFLUXDB_PASSWORD); + root["idbDB"] = getSetting("idbDB", INFLUXDB_DATABASE); + root["idbUser"] = getSetting("idbUser", INFLUXDB_USERNAME); + root["idbPass"] = getSetting("idbPass", INFLUXDB_PASSWORD); } void _idbConfigure() { @@ -38,6 +42,14 @@ void _idbConfigure() { } } +#endif // WEB_SUPPORT + +void _idbBackwards() { + moveSetting("idbDatabase", "idbDB"); // 1.13.1 - 2018-06-26 + moveSetting("idbUserName", "idbUser"); // 1.13.1 - 2018-06-26 + moveSetting("idbPassword", "idbPass"); // 1.13.1 - 2018-06-26 +} + // ----------------------------------------------------------------------------- bool idbSend(const char * topic, const char * payload) { @@ -64,8 +76,8 @@ bool idbSend(const char * topic, const char * payload) { char request[256]; snprintf(request, sizeof(request), "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\nHost: %s:%u\r\nContent-Length: %d\r\n\r\n%s", - getSetting("idbDatabase", INFLUXDB_DATABASE).c_str(), - getSetting("idbUsername", INFLUXDB_USERNAME).c_str(), getSetting("idbPassword", INFLUXDB_PASSWORD).c_str(), + getSetting("idbDB", INFLUXDB_DATABASE).c_str(), + getSetting("idbUser", INFLUXDB_USERNAME).c_str(), getSetting("idbPass", INFLUXDB_PASSWORD).c_str(), host, port, strlen(data), data); if (_idb_client.printf(request) > 0) { @@ -100,12 +112,16 @@ bool idbEnabled() { } void idbSetup() { + + _idbBackwards(); _idbConfigure(); + #if WEB_SUPPORT wsOnSendRegister(_idbWebSocketOnSend); wsOnAfterParseRegister(_idbConfigure); wsOnReceiveRegister(_idbWebSocketOnReceive); #endif + } #endif diff --git a/code/espurna/ir.ino b/code/espurna/ir.ino index 7dd0a34c..148eeb9c 100644 --- a/code/espurna/ir.ino +++ b/code/espurna/ir.ino @@ -5,6 +5,8 @@ IR MODULE Copyright (C) 2016-2018 by Xose Pérez Copyright (C) 2017-2018 by François Déchery +Module key prefix: ir + */ #if IR_SUPPORT diff --git a/code/espurna/led.ino b/code/espurna/led.ino index 06fac792..92084685 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -4,6 +4,8 @@ LED MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: led + */ // ----------------------------------------------------------------------------- diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 5ecd79cd..5e2ef162 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -4,6 +4,8 @@ LIGHT MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: lit + */ #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE @@ -462,19 +464,19 @@ void _lightProviderUpdate() { void _lightColorSave() { for (unsigned int i=0; i < _light_channel.size(); i++) { - setSetting("ch", i, _light_channel[i].inputValue); + setSetting("litCH", i, _light_channel[i].inputValue); } - setSetting("brightness", _light_brightness); - setSetting("mireds", _light_mireds); + setSetting("litBright", _light_brightness); + setSetting("litMireds", _light_mireds); saveSettings(); } void _lightColorRestore() { for (unsigned int i=0; i < _light_channel.size(); i++) { - _light_channel[i].inputValue = getSetting("ch", i, i==0 ? 255 : 0).toInt(); + _light_channel[i].inputValue = getSetting("litCH", i, i==0 ? 255 : 0).toInt(); } - _light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt(); - _light_mireds = getSetting("mireds", _light_mireds).toInt(); + _light_brightness = getSetting("litBright", LIGHT_MAX_BRIGHTNESS).toInt(); + _light_mireds = getSetting("litMireds", _light_mireds).toInt(); lightUpdate(false, false); } @@ -574,7 +576,7 @@ void lightMQTT() { if (_light_has_color) { // Color - if (getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1) { + if (getSetting("litCSS", LIGHT_USE_CSS).toInt() == 1) { _toRGB(buffer, sizeof(buffer)); } else { _toLong(buffer, sizeof(buffer)); @@ -760,25 +762,24 @@ void lightBrightnessStep(int steps) { #if WEB_SUPPORT bool _lightWebSocketOnReceive(const char * key, JsonVariant& value) { - if (strncmp(key, "light", 5) == 0) return true; - if (strncmp(key, "use", 3) == 0) return true; + if (strncmp(key, "lit", 3) == 0) return true; return false; } void _lightWebSocketOnSend(JsonObject& root) { - root["colorVisible"] = 1; + root["litVisible"] = 1; root["mqttGroupColor"] = getSetting("mqttGroupColor"); - root["useColor"] = _light_has_color; - root["useWhite"] = _light_use_white; - root["useGamma"] = _light_use_gamma; - root["useTransitions"] = _light_use_transitions; - root["lightTime"] = _light_transition_time; - root["useCSS"] = getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1; - bool useRGB = getSetting("useRGB", LIGHT_USE_RGB).toInt() == 1; - root["useRGB"] = useRGB; + root["litColor"] = _light_has_color; + root["litWhite"] = _light_use_white; + root["litGamma"] = _light_use_gamma; + root["litTrans"] = _light_use_transitions; + root["litTime"] = _light_transition_time; + root["litCSS"] = getSetting("litCSS", LIGHT_USE_CSS).toInt() == 1; + bool useRGB = getSetting("litRGB", LIGHT_USE_RGB).toInt() == 1; + root["litRGB"] = useRGB; if (_light_has_color) { if (_light_use_cct) { - root["useCCT"] = _light_use_cct; + root["litCCT"] = _light_use_cct; root["mireds"] = _light_mireds; } if (useRGB) { @@ -831,7 +832,7 @@ void _lightAPISetup() { if (_light_has_color) { apiRegister(MQTT_TOPIC_COLOR_RGB, [](char * buffer, size_t len) { - if (getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1) { + if (getSetting("litCSS", LIGHT_USE_CSS).toInt() == 1) { _toRGB(buffer, len); } else { _toLong(buffer, len); @@ -902,7 +903,7 @@ void _lightAPISetup() { void _lightInitCommands() { - settingsRegisterCommand(F("BRIGHTNESS"), [](Embedis* e) { + settingsRegisterCommand(F("brightness"), [](Embedis* e) { if (e->argc > 1) { lightBrightness(String(e->argv[1]).toInt()); lightUpdate(true, true); @@ -985,32 +986,48 @@ unsigned long getIOFunc(unsigned long gpio) { void _lightConfigure() { - _light_has_color = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1; + _light_has_color = getSetting("litColor", LIGHT_USE_COLOR).toInt() == 1; if (_light_has_color && (_light_channel.size() < 3)) { _light_has_color = false; - setSetting("useColor", _light_has_color); + setSetting("litColor", _light_has_color); } - _light_use_white = getSetting("useWhite", LIGHT_USE_WHITE).toInt() == 1; + _light_use_white = getSetting("litWhite", LIGHT_USE_WHITE).toInt() == 1; if (_light_use_white && (_light_channel.size() < 4)) { _light_use_white = false; - setSetting("useWhite", _light_use_white); + setSetting("litWhite", _light_use_white); } - _light_use_cct = getSetting("useCCT", LIGHT_USE_CCT).toInt() == 1; + _light_use_cct = getSetting("litCCT", LIGHT_USE_CCT).toInt() == 1; if (_light_use_cct && ((_light_channel.size() < 5) || !_light_use_white)) { _light_use_cct = false; - setSetting("useCCT", _light_use_cct); + setSetting("litCCT", _light_use_cct); } - _light_use_gamma = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1; - _light_use_transitions = getSetting("useTransitions", LIGHT_USE_TRANSITIONS).toInt() == 1; - _light_transition_time = getSetting("lightTime", LIGHT_TRANSITION_TIME).toInt(); + _light_use_gamma = getSetting("litGamma", LIGHT_USE_GAMMA).toInt() == 1; + _light_use_transitions = getSetting("litTrans", LIGHT_USE_TRANSITIONS).toInt() == 1; + _light_transition_time = getSetting("litTime", LIGHT_TRANSITION_TIME).toInt(); + +} +void _lightBackwards() { + moveSettings("ch", "litCH"); // 1.13.1 - 2018-06-26 + moveSetting("useCSS", "litCSS"); // 1.13.1 - 2018-06-26 + moveSetting("useRGB", "litRGB"); // 1.13.1 - 2018-06-26 + moveSetting("useColor", "litColor"); // 1.13.1 - 2018-06-26 + moveSetting("useWhite", "litWhite"); // 1.13.1 - 2018-06-26 + moveSetting("useCCT", "litCCT"); // 1.13.1 - 2018-06-26 + moveSetting("useGamma", "litGamma"); // 1.13.1 - 2018-06-26 + moveSetting("useTransitions", "litTrans"); // 1.13.1 - 2018-06-26 + moveSetting("lightTime", "litTime"); // 1.13.1 - 2018-06-26 + moveSetting("brightness", "litBright"); // 1.13.1 - 2018-06-26 + moveSetting("mireds", "litMireds"); // 1.13.1 - 2018-06-26 } void lightSetup() { + _lightBackwards(); + #ifdef LIGHT_ENABLE_PIN pinMode(LIGHT_ENABLE_PIN, OUTPUT); digitalWrite(LIGHT_ENABLE_PIN, HIGH); diff --git a/code/espurna/mdns.ino b/code/espurna/mdns.ino index 45610dac..3be38444 100644 --- a/code/espurna/mdns.ino +++ b/code/espurna/mdns.ino @@ -40,7 +40,7 @@ void _mdnsServerStart() { void mdnsServerSetup() { #if WEB_SUPPORT - MDNS.addService("http", "tcp", getSetting("webPort", WEB_PORT).toInt()); + MDNS.addService("http", "tcp", webPort()); #endif #if TELNET_SUPPORT diff --git a/code/espurna/migrate.ino b/code/espurna/migrate.ino index 806f2de9..d1a34751 100644 --- a/code/espurna/migrate.ino +++ b/code/espurna/migrate.ino @@ -1032,9 +1032,9 @@ void migrate() { setSetting("selGPIO", 12); setSetting("cf1GPIO", 14); setSetting("cfGPIO", 5); - setSetting("pwrRatioC", 25740); - setSetting("pwrRatioV", 313400); - setSetting("pwrRatioP", 3414290); + setSetting("curRatio", 25740); + setSetting("volRatio", 313400); + setSetting("pwrRatio", 3414290); setSetting("hlwSelC", LOW); setSetting("hlwIntM", FALLING); diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index fa02afde..0681d528 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -4,6 +4,8 @@ MQTT MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: mqtt + */ #if MQTT_SUPPORT @@ -99,7 +101,7 @@ void _mqttConnect() { if (_mqtt_clientid) free(_mqtt_clientid); _mqtt_user = strdup(getSetting("mqttUser", MQTT_USER).c_str()); - _mqtt_pass = strdup(getSetting("mqttPassword", MQTT_PASS).c_str()); + _mqtt_pass = strdup(getSetting("mqttPass", MQTT_PASS).c_str()); _mqtt_will = strdup(mqttTopic(MQTT_TOPIC_STATUS, false).c_str()); _mqtt_clientid = strdup(getSetting("mqttClientID", getIdentifier()).c_str()); @@ -250,11 +252,16 @@ void _mqttConfigure() { } void _mqttBackwards() { + + // 1.13.0 - 2018-05-30 String mqttTopic = getSetting("mqttTopic", MQTT_TOPIC); if (mqttTopic.indexOf("{identifier}") > 0) { mqttTopic.replace("{identifier}", "{hostname}"); setSetting("mqttTopic", mqttTopic); } + + moveSetting("mqttPassword", "mqttPass"); // 1.13.1 - 2018-06-26 + } unsigned long _mqttNextMessageId() { @@ -317,7 +324,7 @@ void _mqttWebSocketOnSend(JsonObject& root) { root["mqttPort"] = getSetting("mqttPort", MQTT_PORT); root["mqttUser"] = getSetting("mqttUser", MQTT_USER); root["mqttClientID"] = getSetting("mqttClientID"); - root["mqttPassword"] = getSetting("mqttPassword", MQTT_PASS); + root["mqttPass"] = getSetting("mqttPass", MQTT_PASS); root["mqttKeep"] = _mqtt_keepalive; root["mqttRetain"] = _mqtt_retain; root["mqttQoS"] = _mqtt_qos; @@ -750,8 +757,9 @@ void mqttReset() { void mqttSetup() { + // Check backwards compatibility _mqttBackwards(); - + DEBUG_MSG_P(PSTR("[MQTT] Async %s, SSL %s, Autoconnect %s\n"), MQTT_USE_ASYNC ? "ENABLED" : "DISABLED", ASYNC_TCP_SSL_ENABLED ? "ENABLED" : "DISABLED", diff --git a/code/espurna/nofuss.ino b/code/espurna/nofuss.ino index c9247986..1439f2e6 100644 --- a/code/espurna/nofuss.ino +++ b/code/espurna/nofuss.ino @@ -4,6 +4,8 @@ NOFUSS MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: nof + */ #if NOFUSS_SUPPORT @@ -21,31 +23,31 @@ bool _nofussEnabled = false; #if WEB_SUPPORT bool _nofussWebSocketOnReceive(const char * key, JsonVariant& value) { - return (strncmp(key, "nofuss", 6) == 0); + return (strncmp(key, "nof", 6) == 0); } void _nofussWebSocketOnSend(JsonObject& root) { - root["nofussVisible"] = 1; - root["nofussEnabled"] = getSetting("nofussEnabled", NOFUSS_ENABLED).toInt() == 1; - root["nofussServer"] = getSetting("nofussServer", NOFUSS_SERVER); + root["nofVisible"] = 1; + root["nofEnabled"] = getSetting("nofEnabled", NOFUSS_ENABLED).toInt() == 1; + root["nofServer"] = getSetting("nofServer", NOFUSS_SERVER); } #endif void _nofussConfigure() { - String nofussServer = getSetting("nofussServer", NOFUSS_SERVER); + String nofussServer = getSetting("nofServer", NOFUSS_SERVER); #if MDNS_CLIENT_SUPPORT nofussServer = mdnsResolve(nofussServer); #endif if (nofussServer.length() == 0) { - setSetting("nofussEnabled", 0); + setSetting("nofEnabled", 0); _nofussEnabled = false; } else { - _nofussEnabled = getSetting("nofussEnabled", NOFUSS_ENABLED).toInt() == 1; + _nofussEnabled = getSetting("nofEnabled", NOFUSS_ENABLED).toInt() == 1; } - _nofussInterval = getSetting("nofussInterval", NOFUSS_INTERVAL).toInt(); + _nofussInterval = getSetting("nofInterval", NOFUSS_INTERVAL).toInt(); _nofussLastCheck = 0; if (!_nofussEnabled) { @@ -70,6 +72,12 @@ void _nofussConfigure() { } +void _nofussBackwards() { + moveSettings("nofussServer", "nofServer"); // 1.13.1 2018-06-26 + moveSettings("nofussEnabled", "nofEnabled"); // 1.13.1 2018-06-26 + moveSettings("nofussInterval", "nofInterval"); // 1.13.1 2018-06-26 +} + #if TERMINAL_SUPPORT void _nofussInitCommands() { @@ -92,6 +100,7 @@ void nofussRun() { void nofussSetup() { + _nofussBackwards(); _nofussConfigure(); NoFUSSClient.onMessage([](nofuss_t code) { diff --git a/code/espurna/ntp.ino b/code/espurna/ntp.ino index 2a8134a6..1f99f52e 100644 --- a/code/espurna/ntp.ino +++ b/code/espurna/ntp.ino @@ -4,6 +4,8 @@ NTP MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: ntp + */ #if NTP_SUPPORT @@ -115,14 +117,19 @@ void _ntpLoop() { } void _ntpBackwards() { + + // 1.12.0 - 2018-01-21 moveSetting("ntpServer1", "ntpServer"); delSetting("ntpServer2"); delSetting("ntpServer3"); + + // 1.12.0 - 2018-01-20 int offset = getSetting("ntpOffset", NTP_TIME_OFFSET).toInt(); if (-30 < offset && offset < 30) { offset *= 60; setSetting("ntpOffset", offset); } + } // ----------------------------------------------------------------------------- @@ -155,6 +162,7 @@ time_t ntpLocal2UTC(time_t local) { void ntpSetup() { + // Check backwards compatibility _ntpBackwards(); NTP.onNTPSyncEvent([](NTPSyncEvent_t error) { diff --git a/code/espurna/ota.ino b/code/espurna/ota.ino index 4443431a..f8dddebc 100644 --- a/code/espurna/ota.ino +++ b/code/espurna/ota.ino @@ -4,6 +4,8 @@ OTA MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: ota + */ #include "ArduinoOTA.h" @@ -126,7 +128,7 @@ void _otaFrom(const char * host, unsigned int port, const char * url) { #if ASYNC_TCP_SSL_ENABLED if (443 == _ota_port) { uint8_t fp[20] = {0}; - sslFingerPrintArray(getSetting("otafp", OTA_GITHUB_FP).c_str(), fp); + sslFingerPrintArray(getSetting("otaFP", OTA_GITHUB_FP).c_str(), fp); SSL * ssl = _ota_client->getSSL(); if (ssl_match_fingerprint(ssl, fp) != SSL_OK) { DEBUG_MSG_P(PSTR("[OTA] Warning: certificate doesn't match\n")); @@ -197,14 +199,28 @@ void _otaInitCommands() { #endif // TERMINAL_SUPPORT +#if WEB_SUPPORT + +bool _otaWebSocketOnReceive(const char * key, JsonVariant& value) { + return (strncmp(key, "ota", 3) == 0); +} + +#endif // WEB_SUPPORT + +void _otaBackwards() { + moveSetting("otafs", "otaFS"); +} + // ----------------------------------------------------------------------------- void otaSetup() { + _otaBackwards(); _otaConfigure(); #if WEB_SUPPORT wsOnAfterParseRegister(_otaConfigure); + wsOnReceiveRegister(_otaWebSocketOnReceive); #endif #if TERMINAL_SUPPORT diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 1c361a60..27f1549d 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -4,6 +4,8 @@ RELAY MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: rly + */ #include @@ -223,8 +225,8 @@ void relayPulse(unsigned char id) { DEBUG_MSG_P(PSTR("[RELAY] Scheduling relay #%d back in %lums (pulse)\n"), id, ms); _relays[id].pulseTicker.once_ms(ms, relayToggle, id); // Reconfigure after dynamic pulse - _relays[id].pulse = getSetting("relayPulse", id, RELAY_PULSE_MODE).toInt(); - _relays[id].pulse_ms = 1000 * getSetting("relayTime", id, RELAY_PULSE_MODE).toFloat(); + _relays[id].pulse = getSetting("rlyPulse", id, RELAY_PULSE_MODE).toInt(); + _relays[id].pulse_ms = 1000 * getSetting("rlyTime", id, RELAY_PULSE_MODE).toFloat(); } } @@ -323,7 +325,7 @@ void relaySync(unsigned char id) { // Flag sync mode _relayRecursive = true; - byte relaySync = getSetting("relaySync", RELAY_SYNC).toInt(); + byte relaySync = getSetting("rlySync", RELAY_SYNC).toInt(); bool status = _relays[id].target_status; // If RELAY_SYNC_SAME all relays should have the same state @@ -415,21 +417,27 @@ unsigned char relayParsePayload(const char * payload) { // BACKWARDS COMPATIBILITY void _relayBackwards() { + // 1.11.0 - 2017-12-26 byte relayMode = getSetting("relayMode", RELAY_BOOT_MODE).toInt(); byte relayPulseMode = getSetting("relayPulseMode", RELAY_PULSE_MODE).toInt(); float relayPulseTime = getSetting("relayPulseTime", RELAY_PULSE_TIME).toFloat(); if (relayPulseMode == RELAY_PULSE_NONE) relayPulseTime = 0; - for (unsigned int i=0; i<_relays.size(); i++) { - if (!hasSetting("relayBoot", i)) setSetting("relayBoot", i, relayMode); - if (!hasSetting("relayPulse", i)) setSetting("relayPulse", i, relayPulseMode); - if (!hasSetting("relayTime", i)) setSetting("relayTime", i, relayPulseTime); + if (!hasSetting("relayBoot", i)) setSetting("rlyBoot", i, relayMode); + if (!hasSetting("relayPulse", i)) setSetting("rlyPulse", i, relayPulseMode); + if (!hasSetting("relayTime", i)) setSetting("rlyTime", i, relayPulseTime); } - delSetting("relayMode"); delSetting("relayPulseMode"); delSetting("relayPulseTime"); + // 1.13.1 - 2018-06-26 + moveSettings("relayBoot", "rlyBoot"); + moveSettings("relayPulse", "rlyPulse"); + moveSettings("relayTime", "rlyTime"); + moveSetting("relayOnDisc", "rlyOnDisc"); + moveSetting("relaySync", "rlySync"); + } void _relayBoot() { @@ -491,8 +499,8 @@ void _relayConfigure() { if (_relays[i].type == RELAY_TYPE_LATCHED || _relays[i].type == RELAY_TYPE_LATCHED_INVERSE) { pinMode(_relays[i].reset_pin, OUTPUT); } - _relays[i].pulse = getSetting("relayPulse", i, RELAY_PULSE_MODE).toInt(); - _relays[i].pulse_ms = 1000 * getSetting("relayTime", i, RELAY_PULSE_MODE).toFloat(); + _relays[i].pulse = getSetting("rlyPulse", i, RELAY_PULSE_MODE).toInt(); + _relays[i].pulse_ms = 1000 * getSetting("rlyTime", i, RELAY_PULSE_MODE).toFloat(); } } @@ -533,16 +541,16 @@ void _relayWebSocketOnStart(JsonObject& root) { #if MQTT_SUPPORT line["group"] = getSetting("mqttGroup", i, ""); line["group_inv"] = getSetting("mqttGroupInv", i, 0).toInt(); - line["on_disc"] = getSetting("relayOnDisc", i, 0).toInt(); + line["on_disc"] = getSetting("rlyOnDisc", i, 0).toInt(); #endif } if (relayCount() > 1) { - root["multirelayVisible"] = 1; - root["relaySync"] = getSetting("relaySync", RELAY_SYNC); + root["mrlyVisible"] = 1; + root["rlySync"] = getSetting("rlySync", RELAY_SYNC); } - root["relayVisible"] = 1; + root["rlyVisible"] = 1; } @@ -812,7 +820,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo if (type == MQTT_DISCONNECT_EVENT) { for (unsigned int i=0; i < _relays.size(); i++){ - int reaction = getSetting("relayOnDisc", i, 0).toInt(); + int reaction = getSetting("rlyOnDisc", i, 0).toInt(); if (1 == reaction) { // switch relay OFF DEBUG_MSG_P(PSTR("[RELAY] Reset relay (%d) due to MQTT disconnection\n"), i); relayStatusWrap(i, false, false); diff --git a/code/espurna/rf.ino b/code/espurna/rf.ino index 68756b6d..825703fb 100644 --- a/code/espurna/rf.ino +++ b/code/espurna/rf.ino @@ -4,6 +4,8 @@ RF MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: rfb (shared with RFBridge) + */ #if RF_SUPPORT diff --git a/code/espurna/rfbridge.ino b/code/espurna/rfbridge.ino index c19a7a74..5c1be3e3 100644 --- a/code/espurna/rfbridge.ino +++ b/code/espurna/rfbridge.ino @@ -4,6 +4,8 @@ ITEAD RF BRIDGE MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: rfb (shared with RFBridge) + */ #ifdef ITEAD_SONOFF_RFBRIDGE @@ -306,7 +308,7 @@ void _rfbDecode() { _rfbToChar(&_uartbuf[1], buffer); /* Look for the code, possibly replacing the code with the exact learned one on match - * we want to do this on learn too to be sure that the learned code is the same if it + * we want to do this on learn too to be sure that the learned code is the same if it * is equivalent */ DEBUG_MSG_P(PSTR("[RFBRIDGE] Received message '%s'\n"), buffer); diff --git a/code/espurna/scheduler.ino b/code/espurna/scheduler.ino index 003a6f69..ae3f5804 100644 --- a/code/espurna/scheduler.ino +++ b/code/espurna/scheduler.ino @@ -5,6 +5,8 @@ SCHEDULER MODULE Copyright (C) 2017 by faina09 Adapted by Xose Pérez +Module key prefix: sch + */ #if SCHEDULER_SUPPORT diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index e20e89b4..853e759d 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -4,6 +4,8 @@ SENSOR MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: sns pwr ene cur vol tmp hum + */ #if SENSOR_SUPPORT @@ -96,11 +98,13 @@ double _magnitudeProcess(unsigned char type, double value) { #if WEB_SUPPORT bool _sensorWebSocketOnReceive(const char * key, JsonVariant& value) { - if (strncmp(key, "pwr", 3) == 0) return true; if (strncmp(key, "sns", 3) == 0) return true; + if (strncmp(key, "pwr", 3) == 0) return true; + if (strncmp(key, "ene", 3) == 0) return true; + if (strncmp(key, "cur", 3) == 0) return true; + if (strncmp(key, "vol", 3) == 0) return true; if (strncmp(key, "tmp", 3) == 0) return true; if (strncmp(key, "hum", 3) == 0) return true; - if (strncmp(key, "energy", 6) == 0) return true; return false; } @@ -136,8 +140,8 @@ void _sensorWebSocketSendData(JsonObject& root) { } - if (hasTemperature) root["temperatureVisible"] = 1; - if (hasHumidity) root["humidityVisible"] = 1; + if (hasTemperature) root["tmpVisible"] = 1; + if (hasHumidity) root["humVisible"] = 1; } @@ -151,7 +155,7 @@ void _sensorWebSocketStart(JsonObject& root) { if (sensor->getID() == SENSOR_EMON_ANALOG_ID) { root["emonVisible"] = 1; root["pwrVisible"] = 1; - root["pwrVoltage"] = ((EmonAnalogSensor *) sensor)->getVoltage(); + root["volNominal"] = ((EmonAnalogSensor *) sensor)->getVoltage(); } #endif @@ -191,13 +195,12 @@ void _sensorWebSocketStart(JsonObject& root) { } if (_magnitudes.size() > 0) { - root["sensorsVisible"] = 1; - //root["apiRealTime"] = _sensor_realtime; + root["snsVisible"] = 1; root["pwrUnits"] = _sensor_power_units; - root["energyUnits"] = _sensor_energy_units; + root["eneUnits"] = _sensor_energy_units; root["tmpUnits"] = _sensor_temperature_units; - root["tmpCorrection"] = _sensor_temperature_correction; - root["humCorrection"] = _sensor_humidity_correction; + root["tmpOffset"] = _sensor_temperature_correction; + root["humOffset"] = _sensor_humidity_correction; root["snsRead"] = _sensor_read_interval / 1000; root["snsReport"] = _sensor_report_every; } @@ -630,8 +633,8 @@ void _sensorInit() { if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) { EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; - sensor->setCurrentRatio(0, getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat()); - sensor->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt()); + sensor->setCurrentRatio(0, getSetting("curRatio", EMON_CURRENT_RATIO).toFloat()); + sensor->setVoltage(getSetting("volNominal", EMON_MAINS_VOLTAGE).toInt()); } #endif // EMON_ANALOG_SUPPORT @@ -644,13 +647,13 @@ void _sensorInit() { double value; - value = getSetting("pwrRatioC", HLW8012_CURRENT_RATIO).toFloat(); + value = getSetting("curRatio", HLW8012_CURRENT_RATIO).toFloat(); if (value > 0) sensor->setCurrentRatio(value); - value = getSetting("pwrRatioV", HLW8012_VOLTAGE_RATIO).toFloat(); + value = getSetting("volRatio", HLW8012_VOLTAGE_RATIO).toFloat(); if (value > 0) sensor->setVoltageRatio(value); - value = getSetting("pwrRatioP", HLW8012_POWER_RATIO).toFloat(); + value = getSetting("pwrRatio", HLW8012_POWER_RATIO).toFloat(); if (value > 0) sensor->setPowerRatio(value); } @@ -665,13 +668,13 @@ void _sensorInit() { double value; - value = getSetting("pwrRatioC", 0).toFloat(); + value = getSetting("curRatio", 0).toFloat(); if (value > 0) sensor->setCurrentRatio(value); - value = getSetting("pwrRatioV", 0).toFloat(); + value = getSetting("volRatio", 0).toFloat(); if (value > 0) sensor->setVoltageRatio(value); - value = getSetting("pwrRatioP", 0).toFloat(); + value = getSetting("pwrRatio", 0).toFloat(); if (value > 0) sensor->setPowerRatio(value); } @@ -687,12 +690,12 @@ void _sensorConfigure() { // General sensor settings _sensor_read_interval = 1000 * constrain(getSetting("snsRead", SENSOR_READ_INTERVAL).toInt(), SENSOR_READ_MIN_INTERVAL, SENSOR_READ_MAX_INTERVAL); _sensor_report_every = constrain(getSetting("snsReport", SENSOR_REPORT_EVERY).toInt(), SENSOR_REPORT_MIN_EVERY, SENSOR_REPORT_MAX_EVERY); - _sensor_realtime = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1; + _sensor_realtime = apiRealTime(); _sensor_power_units = getSetting("pwrUnits", SENSOR_POWER_UNITS).toInt(); - _sensor_energy_units = getSetting("energyUnits", SENSOR_ENERGY_UNITS).toInt(); + _sensor_energy_units = getSetting("eneUnits", SENSOR_ENERGY_UNITS).toInt(); _sensor_temperature_units = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt(); - _sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat(); - _sensor_humidity_correction = getSetting("humCorrection", SENSOR_HUMIDITY_CORRECTION).toFloat(); + _sensor_temperature_correction = getSetting("tmpOffset", SENSOR_TEMPERATURE_CORRECTION).toFloat(); + _sensor_humidity_correction = getSetting("humOffset", SENSOR_HUMIDITY_CORRECTION).toFloat(); // Specific sensor settings for (unsigned char i=0; i<_sensors.size(); i++) { @@ -704,22 +707,22 @@ void _sensorConfigure() { double value; EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; - if (value = getSetting("pwrExpectedP", 0).toInt()) { + if (value = getSetting("pwrExpected", 0).toInt()) { sensor->expectedPower(0, value); - setSetting("pwrRatioC", sensor->getCurrentRatio(0)); + setSetting("curRatio", sensor->getCurrentRatio(0)); } - if (getSetting("pwrResetCalibration", 0).toInt() == 1) { + if (getSetting("snsResetCalibrarion", 0).toInt() == 1) { sensor->setCurrentRatio(0, EMON_CURRENT_RATIO); - delSetting("pwrRatioC"); + delSetting("curRatio"); } - if (getSetting("pwrResetE", 0).toInt() == 1) { + if (getSetting("eneReset", 0).toInt() == 1) { sensor->resetEnergy(); _sensorReset(); } - sensor->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt()); + sensor->setVoltage(getSetting("volNominal", EMON_MAINS_VOLTAGE).toInt()); } @@ -728,7 +731,7 @@ void _sensorConfigure() { #if EMON_ADC121_SUPPORT if (_sensors[i]->getID() == SENSOR_EMON_ADC121_ID) { EmonADC121Sensor * sensor = (EmonADC121Sensor *) _sensors[i]; - if (getSetting("pwrResetE", 0).toInt() == 1) { + if (getSetting("eneReset", 0).toInt() == 1) { sensor->resetEnergy(); _sensorReset(); } @@ -738,7 +741,7 @@ void _sensorConfigure() { #if EMON_ADS1X15_SUPPORT if (_sensors[i]->getID() == SENSOR_EMON_ADS1X15_ID) { EmonADS1X15Sensor * sensor = (EmonADS1X15Sensor *) _sensors[i]; - if (getSetting("pwrResetE", 0).toInt() == 1) { + if (getSetting("eneReset", 0).toInt() == 1) { sensor->resetEnergy(); _sensorReset(); } @@ -753,31 +756,31 @@ void _sensorConfigure() { double value; HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i]; - if (value = getSetting("pwrExpectedC", 0).toFloat()) { + if (value = getSetting("curExpected", 0).toFloat()) { sensor->expectedCurrent(value); - setSetting("pwrRatioC", sensor->getCurrentRatio()); + setSetting("curRatio", sensor->getCurrentRatio()); } - if (value = getSetting("pwrExpectedV", 0).toInt()) { + if (value = getSetting("volExpected", 0).toInt()) { sensor->expectedVoltage(value); - setSetting("pwrRatioV", sensor->getVoltageRatio()); + setSetting("volRatio", sensor->getVoltageRatio()); } - if (value = getSetting("pwrExpectedP", 0).toInt()) { + if (value = getSetting("pwrExpected", 0).toInt()) { sensor->expectedPower(value); - setSetting("pwrRatioP", sensor->getPowerRatio()); + setSetting("pwrRatio", sensor->getPowerRatio()); } - if (getSetting("pwrResetE", 0).toInt() == 1) { + if (getSetting("eneReset", 0).toInt() == 1) { sensor->resetEnergy(); _sensorReset(); } - if (getSetting("pwrResetCalibration", 0).toInt() == 1) { + if (getSetting("snsResetCalibrarion", 0).toInt() == 1) { sensor->resetRatios(); - delSetting("pwrRatioC"); - delSetting("pwrRatioV"); - delSetting("pwrRatioP"); + delSetting("curRatio"); + delSetting("volRatio"); + delSetting("pwrRatio"); } } @@ -791,31 +794,31 @@ void _sensorConfigure() { double value; CSE7766Sensor * sensor = (CSE7766Sensor *) _sensors[i]; - if (value = getSetting("pwrExpectedC", 0).toFloat()) { + if (value = getSetting("curExpected", 0).toFloat()) { sensor->expectedCurrent(value); - setSetting("pwrRatioC", sensor->getCurrentRatio()); + setSetting("curRatio", sensor->getCurrentRatio()); } - if (value = getSetting("pwrExpectedV", 0).toInt()) { + if (value = getSetting("volExpected", 0).toInt()) { sensor->expectedVoltage(value); - setSetting("pwrRatioV", sensor->getVoltageRatio()); + setSetting("volRatio", sensor->getVoltageRatio()); } - if (value = getSetting("pwrExpectedP", 0).toInt()) { + if (value = getSetting("pwrExpected", 0).toInt()) { sensor->expectedPower(value); - setSetting("pwrRatioP", sensor->getPowerRatio()); + setSetting("pwrRatio", sensor->getPowerRatio()); } - if (getSetting("pwrResetE", 0).toInt() == 1) { + if (getSetting("eneReset", 0).toInt() == 1) { sensor->resetEnergy(); _sensorReset(); } - if (getSetting("pwrResetCalibration", 0).toInt() == 1) { + if (getSetting("snsResetCalibrarion", 0).toInt() == 1) { sensor->resetRatios(); - delSetting("pwrRatioC"); - delSetting("pwrRatioV"); - delSetting("pwrRatioP"); + delSetting("curRatio"); + delSetting("volRatio"); + delSetting("pwrRatio"); } } @@ -830,15 +833,31 @@ void _sensorConfigure() { } // Save settings - delSetting("pwrExpectedP"); - delSetting("pwrExpectedC"); - delSetting("pwrExpectedV"); - delSetting("pwrResetCalibration"); - delSetting("pwrResetE"); + delSetting("pwrExpected"); + delSetting("curExpected"); + delSetting("volExpected"); + delSetting("snsResetCalibrarion"); + delSetting("eneReset"); saveSettings(); } +void _sensorBackwards() { + moveSetting("powerUnits", "pwrUnits"); // 1.12.5 - 2018-04-03 + moveSetting("tmpCorrection", "tmpOffset"); // 1.13.1 - 2018-06-26 + moveSetting("humCorrection", "humOffset"); // 1.13.1 - 2018-06-26 + moveSetting("energyUnits", "eneUnits"); // 1.13.1 - 2018-06-26 + moveSetting("pwrRatioC", "curRatio"); // 1.13.1 - 2018-06-26 + moveSetting("pwrRatioP", "pwrRatio"); // 1.13.1 - 2018-06-26 + moveSetting("pwrRatioV", "volRatio"); // 1.13.1 - 2018-06-26 + moveSetting("pwrVoltage", "volNominal"); // 1.13.1 - 2018-06-26 + moveSetting("pwrExpectedP", "pwrExpected"); // 1.13.1 - 2018-06-26 + moveSetting("pwrExpectedC", "curExpected"); // 1.13.1 - 2018-06-26 + moveSetting("pwrExpectedV", "volExpected"); // 1.13.1 - 2018-06-26 + moveSetting("pwrResetCalibration", "snsResetCalibration"); // 1.13.1 - 2018-06-26 + moveSetting("pwrResetE", "eneReset"); // 1.13.1 - 2018-06-26 +} + // ----------------------------------------------------------------------------- // Public // ----------------------------------------------------------------------------- @@ -918,7 +937,7 @@ String magnitudeUnits(unsigned char type) { void sensorSetup() { // Backwards compatibility - moveSetting("powerUnits", "pwrUnits"); + _sensorBackwards(); // Load sensors _sensorLoad(); diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index 19013663..027b69f3 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -4,6 +4,8 @@ SETTINGS MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: cfg + */ #include @@ -306,6 +308,23 @@ void moveSetting(const char * from, const char * to) { delSetting(from); } +void moveSetting(const char * from, const char * to, unsigned int index) { + String value = getSetting(from, index, ""); + if (value.length() > 0) setSetting(to, index, value); + delSetting(from, index); +} + +void moveSettings(const char * from, const char * to) { + unsigned int index = 0; + while (index < 100) { + String value = getSetting(from, index, ""); + if (value.length() == 0) break; + setSetting(to, index, value); + delSetting(from, index); + index++; + } +} + template String getSetting(const String& key, T defaultValue) { String value; if (!Embedis::get(key, value)) value = String(defaultValue); diff --git a/code/espurna/ssdp.ino b/code/espurna/ssdp.ino index 6ecf0f58..ca3a9e94 100644 --- a/code/espurna/ssdp.ino +++ b/code/espurna/ssdp.ino @@ -6,6 +6,8 @@ Copyright (C) 2017-2018 by Xose Pérez Uses SSDP library by PawelDino (https://github.com/PawelDino) https://github.com/esp8266/Arduino/issues/2283#issuecomment-299635604 +Module key prefix: ssdp + */ #if SSDP_SUPPORT diff --git a/code/espurna/system.ino b/code/espurna/system.ino index e437bccc..a71ae1ec 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -4,6 +4,8 @@ SYSTEM MODULE Copyright (C) 2018 by Xose Pérez +Module key prefix: esp (shared with others) + */ #include diff --git a/code/espurna/telnet.ino b/code/espurna/telnet.ino index 4f858ab4..d3e63d3a 100644 --- a/code/espurna/telnet.ino +++ b/code/espurna/telnet.ino @@ -6,6 +6,8 @@ Copyright (C) 2017-2018 by Xose Pérez Parts of the code have been borrowed from Thomas Sarlandie's NetServer (https://github.com/sarfata/kbox-firmware/tree/master/src/esp) +Module key prefix: tel + */ #if TELNET_SUPPORT @@ -23,12 +25,12 @@ bool _telnetFirst = true; #if WEB_SUPPORT bool _telnetWebSocketOnReceive(const char * key, JsonVariant& value) { - return (strncmp(key, "telnet", 6) == 0); + return (strncmp(key, "telt", 3) == 0); } void _telnetWebSocketOnSend(JsonObject& root) { - root["telnetVisible"] = 1; - root["telnetSTA"] = getSetting("telnetSTA", TELNET_STA).toInt() == 1; + root["telVisible"] = 1; + root["telSTA"] = getSetting("telSTA", TELNET_STA).toInt() == 1; } #endif @@ -93,7 +95,7 @@ void _telnetNewClient(AsyncClient *client) { #ifdef ESPURNA_CORE bool telnetSTA = true; #else - bool telnetSTA = getSetting("telnetSTA", TELNET_STA).toInt() == 1; + bool telnetSTA = getSetting("telSTA", TELNET_STA).toInt() == 1; #endif if (!telnetSTA) { @@ -160,6 +162,10 @@ void _telnetNewClient(AsyncClient *client) { } +void _telnetBackwards() { + moveSetting("telnetSTA", "telSTA"); // 1.13.1 -- 2018-06-26 +} + // ----------------------------------------------------------------------------- // Public API // ----------------------------------------------------------------------------- @@ -178,6 +184,9 @@ unsigned char telnetWrite(unsigned char ch) { void telnetSetup() { + // Backwards compatibility + _telnetBackwards(); + _telnetServer = new AsyncServer(TELNET_PORT); _telnetServer->onClient([](void *s, AsyncClient* c) { _telnetNewClient(c); diff --git a/code/espurna/thinkspeak.ino b/code/espurna/thinkspeak.ino index 04b0c85c..93369bf9 100644 --- a/code/espurna/thinkspeak.ino +++ b/code/espurna/thinkspeak.ino @@ -4,6 +4,8 @@ THINGSPEAK MODULE Copyright (C) 2018 by Xose Pérez +Module key prefix: tspk + */ #if THINGSPEAK_SUPPORT diff --git a/code/espurna/uartmqtt.ino b/code/espurna/uartmqtt.ino index ed3132e6..f3f31302 100644 --- a/code/espurna/uartmqtt.ino +++ b/code/espurna/uartmqtt.ino @@ -5,6 +5,8 @@ UART_MQTT MODULE Copyright (C) 2018 by Albert Weterings Adapted by Xose Pérez +Module key prefix: u2m + */ #if UART_MQTT_SUPPORT diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 9a229c4a..99c1d422 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -4,6 +4,8 @@ UTILS MODULE Copyright (C) 2017-2018 by Xose Pérez +Module key prefix: esp (shared with others) + */ #include diff --git a/code/espurna/web.ino b/code/espurna/web.ino index c0083575..978f8b35 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -4,6 +4,8 @@ WEBSERVER MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: web + */ #if WEB_SUPPORT diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index 37f55464..a7d76c23 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -4,6 +4,8 @@ WIFI MODULE Copyright (C) 2016-2018 by Xose Pérez +Module key prefix: wifi + */ #include "JustWifi.h" diff --git a/code/html/custom.js b/code/html/custom.js index e300980a..b031a49f 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -12,8 +12,8 @@ var numReboot = 0; var numReconnect = 0; var numReload = 0; -var useWhite = false; -var useCCT = false; +var litWhite = false; +var litCCT = false; var now = 0; var ago = 0; @@ -201,8 +201,8 @@ function addValue(data, name, value) { var is_group = [ "ssid", "pass", "gw", "mask", "ip", "dns", "schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC", - "relayBoot", "relayPulse", "relayTime", - "mqttGroup", "mqttGroupInv", "relayOnDisc", + "rlyBoot", "rlyPulse", "rlyTime", + "mqttGroup", "mqttGroupInv", "rlyOnDisc", "dczRelayIdx", "dczMagnitude", "tspkRelay", "tspkMagnitude", "ledMode", @@ -802,12 +802,12 @@ function initRelayConfig(data) { var line = $(template).clone(); $("span.gpio", line).html(relay.gpio); $("span.id", line).html(i); - $("select[name='relayBoot']", line).val(relay.boot); - $("select[name='relayPulse']", line).val(relay.pulse); - $("input[name='relayTime']", line).val(relay.pulse_ms); + $("select[name='rlyBoot']", line).val(relay.boot); + $("select[name='rlyPulse']", line).val(relay.pulse); + $("input[name='rlyTime']", line).val(relay.pulse_ms); $("input[name='mqttGroup']", line).val(relay.group); $("select[name='mqttGroupInv']", line).val(relay.group_inv); - $("select[name='relayOnDisc']", line).val(relay.on_disc); + $("select[name='rlyOnDisc']", line).val(relay.on_disc); line.appendTo("#relayConfig"); } @@ -924,9 +924,9 @@ function initChannels(num) { var max = num; if (colors) { max = num % 3; - if ((max > 0) & useWhite) { + if ((max > 0) & litWhite) { max--; - if (useCCT) { + if (litCCT) { max--; } } @@ -1125,13 +1125,13 @@ function processData(data) { return; } - if ("useWhite" === key) { - useWhite = value; + if ("litWhite" === key) { + litWhite = value; } - if ("useCCT" === key) { + if ("litCCT" === key) { initCCT(); - useCCT = value; + litCCT = value; } diff --git a/code/html/index.html b/code/html/index.html index a123764d..0acdb065 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -100,7 +100,7 @@ -
  • +
  • LIGHTS
  • @@ -124,12 +124,12 @@ -
  • +
  • SENSORS
  • -
  • +
  • SWITCHES
  • @@ -350,9 +350,9 @@ -
    +
    -
    +
    @@ -370,11 +370,11 @@
    - General + General -
    +
    - @@ -405,7 +405,7 @@
    -
    +
    Use the first three channels as RGB channels. This will also enable the color picker in the web UI. Will only work if the device has at least 3 dimmable channels.
    Reload the page to update the web interface.
    @@ -413,7 +413,7 @@
    -
    +
    Use RGB color picker if enabled (plus brightness), otherwise use HSV (hue-saturation-value) style
    @@ -421,7 +421,7 @@
    -
    +
    Use forth dimmable channel as (cold) white light calculated out of the RGB values.
    Will only work if the device has at least 4 dimmable channels.
    Enabling this will render useless the "Channel 4" slider in the status page.
    Reload the page to update the web interface.
    @@ -429,7 +429,7 @@
    -
    +
    Use fifth dimmable channel as warm white light and the forth dimmable channel as cold white.
    Will only work if the device has at least 5 dimmable channels and "white channel" above is also ON.
    Enabling this will render useless the "Channel 5" slider in the status page.
    Reload the page to update the web interface.
    @@ -437,7 +437,7 @@
    -
    +
    Use gamma correction for RGB channels.
    Will only work if "use colorpicker" above is also ON.
    @@ -445,7 +445,7 @@
    -
    +
    Use CSS style to report colors to MQTT and REST API.
    Red will be reported as "#FF0000" if ON, otherwise "255,0,0"
    @@ -453,7 +453,7 @@
    -
    +
    If enabled color changes will be smoothed.
    @@ -461,7 +461,7 @@
    -
    +
    Time in millisecons to transition from one color to another.
    @@ -555,23 +555,23 @@
    -
    +
    -
    +
    Turn ON to be able to telnet to your device while connected to your home router.
    TELNET is always enabled in AP mode.
    -
    +
    -
    +
    -
    +
    - +
    This name address of the NoFUSS server for automatic remote updates (see https://bitbucket.org/xoseperez/nofuss).
    @@ -648,9 +648,9 @@
    - + - +
    @@ -692,7 +692,7 @@
    - +
    @@ -749,11 +749,11 @@ This is the root topic for this device. The {hostname} and {mac} placeholders will be replaced by the device hostname and MAC address.
    - <root>/relay/#/set Send a 0 or a 1 as a payload to this topic to switch it on or off. You can also send a 2 to toggle its current state. Replace # with the switch ID (starting from 0). If the board has only one switch it will be 0.
    - - <root>/rgb/set Set the color using this topic, your can either send an "#RRGGBB" value or "RRR,GGG,BBB" (0-255 each).
    - - <root>/hsv/set Set the color using hue (0-360), saturation (0-100) and value (0-100) values, comma separated.
    - - <root>/brightness/set Set the brighness (0-255).
    - - <root>/channel/#/set Set the value for a single color channel (0-255). Replace # with the channel ID (starting from 0 and up to 4 for RGBWC lights).
    - - <root>/mired/set Set the temperature color in mired.
    + - <root>/rgb/set Set the color using this topic, your can either send an "#RRGGBB" value or "RRR,GGG,BBB" (0-255 each).
    + - <root>/hsv/set Set the color using hue (0-360), saturation (0-100) and value (0-100) values, comma separated.
    + - <root>/brightness/set Set the brighness (0-255).
    + - <root>/channel/#/set Set the value for a single color channel (0-255). Replace # with the channel ID (starting from 0 and up to 4 for RGBWC lights).
    + - <root>/mired/set Set the temperature color in mired.
    - <root>/status The device will report a 1 to this topic every few minutes. Upon MQTT disconnecting this will be set to 0.
    - Other values reported (depending on the build) are: firmware and version, hostname, IP, MAC, signal strenth (RSSI), uptime (in seconds), free heap and power supply. @@ -994,17 +994,17 @@
    - +
    - +
    - +
    @@ -1097,13 +1097,13 @@
    -
    -
    +
    -
    +
    - +
    @@ -1121,9 +1121,9 @@
    -
    +
    - +
    @@ -1135,35 +1135,35 @@
    - +
    Mains voltage in your system (in V).
    - +
    In Amperes (A). If you are using a pure resistive load like a bulb, this will be the ratio between the two previous values, i.e. power / voltage. You can also use a current clamp around one of the power wires to get this value.
    - +
    In Volts (V). Enter your the nominal AC voltage for your household or facility, or use multimeter to get this value.
    - +
    In Watts (W). Calibrate your sensor connecting a pure resistive load (like a bulb) and enter here the its nominal power or use a multimeter.
    -
    +
    Move this switch to ON and press "Save" to revert to factory calibration values.
    @@ -1171,7 +1171,7 @@
    -
    +
    Move this switch to ON and press "Save" to set energy count to 0.
    @@ -1346,7 +1346,7 @@ Switch # (GPIO)
    - @@ -1355,7 +1355,7 @@
    - @@ -1363,7 +1363,7 @@
    -
    +
    @@ -1378,7 +1378,7 @@
    -