diff --git a/code/espurna/config/all.h b/code/espurna/config/all.h index d734e0ba..2494890c 100644 --- a/code/espurna/config/all.h +++ b/code/espurna/config/all.h @@ -28,6 +28,7 @@ #include "arduino.h" #include "hardware.h" #include "defaults.h" +#include "deprecated.h" #include "general.h" #include "dependencies.h" #include "debug.h" diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index 2838182c..6d9c30f9 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -41,6 +41,7 @@ //#define ELECTRODRAGON_WIFI_IOT //#define WORKCHOICE_ECOPLUG //#define AITHINKER_AI_LIGHT +//#define LYASI_LIGHT //#define MAGICHOME_LED_CONTROLLER //#define MAGICHOME_LED_CONTROLLER_20 //#define HUACANXING_H801 diff --git a/code/espurna/config/deprecated.h b/code/espurna/config/deprecated.h new file mode 100644 index 00000000..a8a99508 --- /dev/null +++ b/code/espurna/config/deprecated.h @@ -0,0 +1,9 @@ +#pragma once + +// 1.13.3 added TELNET_PASSWORD build-only flag +// 1.13.4 replaces it with TELNET_AUTHENTICATION runtime setting default +// TODO warning should be removed eventually +#ifdef TELNET_PASSWORD +#warning TELNET_PASSWORD is deprecated! Please replace it with TELNET_AUTHENTICATION +#define TELNET_AUTHENTICATION TELNET_PASSWORD +#endif diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 5c4baef1..9c1ef409 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -235,8 +235,8 @@ #define HEARTBEAT_REPORT_HOSTNAME 1 #endif -#ifndef HEARTBEAT_REPORT_DESCRITION -#define HEARTBEAT_REPORT_DESCRITION 1 +#ifndef HEARTBEAT_REPORT_DESCRIPTION +#define HEARTBEAT_REPORT_DESCRIPTION 1 #endif #ifndef HEARTBEAT_REPORT_APP diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index b30c09cd..85695ea9 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -1151,6 +1151,28 @@ #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_MAPPING 0, 1, 2, 3 +// ----------------------------------------------------------------------------- +// Lyasi LED +// ----------------------------------------------------------------------------- + +#elif defined(LYASI_LIGHT) + + // Info + #define MANUFACTURER "LYASI" + #define DEVICE "RGB-LED" + #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT + #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX + #define DUMMY_RELAY_COUNT 1 + + // Light + #define LIGHT_CHANNELS 4 + #define MY92XX_MODEL MY92XX_MODEL_MY9291 + #define MY92XX_CHIPS 1 + #define MY92XX_DI_PIN 4 + #define MY92XX_DCKI_PIN 5 + #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT + #define MY92XX_MAPPING 0, 1, 2, 3 + // ----------------------------------------------------------------------------- // LED Controller // ----------------------------------------------------------------------------- diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index eb923ace..223b1ab6 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -11,6 +11,7 @@ Copyright (C) 2016-2018 by Xose PĂ©rez #include bool _dcz_enabled = false; +std::vector _dcz_relay_state; //------------------------------------------------------------------------------ // Private methods @@ -36,6 +37,15 @@ void _domoticzMqttSubscribe(bool value) { } +bool _domoticzStatus(unsigned char id) { + return _dcz_relay_state[id]; +} + +void _domoticzStatus(unsigned char id, bool status) { + _dcz_relay_state[id] = status; + relayStatus(id, status); +} + void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) { if (!_dcz_enabled) return; @@ -128,7 +138,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) if (relayID >= 0) { unsigned char value = root["nvalue"]; DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); - relayStatus(relayID, value > 0); + _domoticzStatus(relayID, value > 0); } } #else @@ -139,7 +149,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) if (relayID >= 0) { unsigned char value = root["nvalue"]; DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %u for IDX %u\n"), value, idx); - relayStatus(relayID, value == 1); + _domoticzStatus(relayID, value == 1); } } @@ -199,6 +209,12 @@ void _domoticzWebSocketOnSend(JsonObject& root) { void _domoticzConfigure() { bool enabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1; if (enabled != _dcz_enabled) _domoticzMqttSubscribe(enabled); + + _dcz_relay_state.reserve(relayCount()); + for (size_t n = 0; n < relayCount(); ++n) { + _dcz_relay_state[n] = relayStatus(n); + } + _dcz_enabled = enabled; } @@ -222,6 +238,8 @@ template void domoticzSend(const char * key, T nvalue) { void domoticzSendRelay(unsigned char relayID, bool status) { if (!_dcz_enabled) return; + if (_domoticzStatus(relayID) == status) return; + _dcz_relay_state[relayID] = status; char buffer[15]; snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%u"), relayID); domoticzSend(buffer, status ? "1" : "0"); diff --git a/code/espurna/migrate.ino b/code/espurna/migrate.ino index c12ed228..f1e7eafe 100644 --- a/code/espurna/migrate.ino +++ b/code/espurna/migrate.ino @@ -257,6 +257,17 @@ void migrate() { setSetting("myDCKIGPIO", 15); setSetting("relays", 1); + #elif defined(LYASI_LIGHT) + + setSetting("board", 20); + setSetting("relayProvider", RELAY_PROVIDER_LIGHT); + setSetting("lightProvider", LIGHT_PROVIDER_MY92XX); + setSetting("myModel", MY92XX_MODEL_MY9291); + setSetting("myChips", 1); + setSetting("myDIGPIO", 4); + setSetting("myDCKIGPIO", 5); + setSetting("relays", 1); + #elif defined(MAGICHOME_LED_CONTROLLER) setSetting("board", 21); diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 27b2d4dd..791ba99c 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -86,6 +86,12 @@ void _systemSetupHeartbeat() { _heartbeat_interval = getSetting("hbInterval", HEARTBEAT_INTERVAL).toInt(); } +#if WEB_SUPPORT + bool _systemWebSocketOnReceive(const char * key, JsonVariant& value) { + return (strncmp(key, "hb", 2) == 0); + } +#endif + void systemLoop() { // ------------------------------------------------------------------------- @@ -182,6 +188,10 @@ void systemSetup() { systemCheck(false); #endif + #if WEB_SUPPORT + wsOnReceiveRegister(_systemWebSocketOnReceive); + #endif + // Init device-specific hardware _systemSetupSpecificHardware(); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index d7c2c491..23c6ea03 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -181,7 +181,7 @@ namespace Heartbeat { (Relay * (HEARTBEAT_REPORT_RELAY)) | \ (Light * (HEARTBEAT_REPORT_LIGHT)) | \ (Hostname * (HEARTBEAT_REPORT_HOSTNAME)) | \ - (Description * (HEARTBEAT_REPORT_DESCRITION)) | \ + (Description * (HEARTBEAT_REPORT_DESCRIPTION)) | \ (App * (HEARTBEAT_REPORT_APP)) | \ (Version * (HEARTBEAT_REPORT_VERSION)) | \ (Board * (HEARTBEAT_REPORT_BOARD)) | \ diff --git a/code/platformio.ini b/code/platformio.ini index 22e6f27e..cf2bb3f3 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -1229,6 +1229,31 @@ upload_flags = ${common.upload_flags} monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} +[env:lyasi-rgb-light] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board_1m} +board_build.flash_mode = ${common.flash_mode} +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m0m} -DLYASI_LIGHT +monitor_speed = ${common.monitor_speed} +extra_scripts = ${common.extra_scripts} + +[env:lyasi-rgb-light-ota] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board_1m} +board_build.flash_mode = ${common.flash_mode} +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m0m} -DLYASI_LIGHT +upload_speed = ${common.upload_speed} +upload_port = ${common.upload_port} +upload_flags = ${common.upload_flags} +monitor_speed = ${common.monitor_speed} +extra_scripts = ${common.extra_scripts} + [env:magichome-led-controller] platform = ${common.platform} framework = ${common.framework}