From fa179ee296e1106dc7a5469023a05aedd5e63824 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 27 Aug 2020 18:54:53 +0200 Subject: [PATCH 1/2] Add ``SetOption109 1`` to force gen1 Alexa mode, for Echo Dot 2nd gen devices only --- tasmota/CHANGELOG.md | 1 + tasmota/settings.h | 4 ++-- tasmota/xdrv_01_webserver.ino | 6 ------ tasmota/xdrv_20_hue.ino | 23 ++++------------------- tasmota/xdrv_21_wemo.ino | 12 ++++++++---- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 96ae2be02..7289ce970 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -4,6 +4,7 @@ - Add command ``PowerDelta1`` to ``PowerDelta3`` to trigger on up to three phases (#9134) - Add Zigbee web ui widget for Lights +- Add ``SetOption109 1`` to force gen1 Alexa mode, for Echo Dot 2nd gen devices only ### 8.4.0.2 20200813 diff --git a/tasmota/settings.h b/tasmota/settings.h index 590d0af3e..d7a526d41 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -127,8 +127,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t white_blend_mode : 1; // bit 23 (v8.4.0.1) - SetOption105 - White Blend Mode - used to be `RGBWWTable` last value `0`, now deprecated in favor of this option uint32_t virtual_ct : 1; // bit 24 (v8.4.0.1) - SetOption106 - Virtual CT - Creates a virtual White ColorTemp for RGBW lights uint32_t virtual_ct_cw : 1; // bit 25 (v8.4.0.1) - SetOption107 - Virtual CT Channel - signals whether the hardware white is cold CW (true) or warm WW (false) - uint32_t teleinfo_rawdata : 1; // bit 21 (v8.4.0.2) - SetOption108 - enable Teleinfo + Tasmota Energy device (0) or Teleinfo raw data only (1) - uint32_t spare27 : 1; + uint32_t teleinfo_rawdata : 1; // bit 26 (v8.4.0.2) - SetOption108 - enable Teleinfo + Tasmota Energy device (0) or Teleinfo raw data only (1) + uint32_t alexa_gen_1 : 1; // bit 27 (v8.4.0.3) - SetOption109 - Alexa gen1 mode - if you only have Echo Dot 2nd gen devices uint32_t spare28 : 1; // bit 28 uint32_t spare29 : 1; // bit 29 uint32_t spare30 : 1; // bit 30 diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 96e1e5a54..615317337 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -46,8 +46,6 @@ uint8_t *efm8bb1_update = nullptr; enum UploadTypes { UPL_TASMOTA, UPL_SETTINGS, UPL_EFM8BB1, UPL_TASMOTACLIENT, UPL_EFR32 }; -static const char * HEADER_KEYS[] = { "User-Agent", }; - #ifdef USE_UNISHOX_COMPRESSION #ifdef USE_JAVASCRIPT_ES6 // insert D_HTML_LANGUAGE later @@ -891,10 +889,6 @@ void StartWebserver(int type, IPAddress ipweb) } Web.reset_web_log_flag = false; - // Collect User-Agent for Alexa Hue Emulation - // This is used in xdrv_20_hue.ino in function findEchoGeneration() - Webserver->collectHeaders(HEADER_KEYS, sizeof(HEADER_KEYS)/sizeof(char*)); - Webserver->begin(); // Web server start } if (Web.state != type) { diff --git a/tasmota/xdrv_20_hue.ino b/tasmota/xdrv_20_hue.ino index 17a0886db..354a527e7 100644 --- a/tasmota/xdrv_20_hue.ino +++ b/tasmota/xdrv_20_hue.ino @@ -510,24 +510,9 @@ static const char * FIRST_GEN_UA[] = { // list of User-Agents signature }; // Check if the Echo device is of 1st generation, which triggers different results -uint32_t findEchoGeneration(void) { - // result is 1 for 1st gen, 2 for 2nd gen and further - String user_agent = Webserver->header("User-Agent"); - uint32_t gen = 2; - - for (uint32_t i = 0; i < sizeof(FIRST_GEN_UA)/sizeof(char*); i++) { - if (user_agent.indexOf(FIRST_GEN_UA[i]) >= 0) { // found - gen = 1; - break; - } - } - if (0 == user_agent.length()) { - gen = 1; // if no user-agent, also revert to gen v1 - } - - AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " User-Agent: %s, gen=%d"), user_agent.c_str(), gen); // Header collection is set in xdrv_01_webserver.ino, in StartWebserver() - - return gen; +inline uint32_t findEchoGeneration(void) { + // don't try to guess from User-Agent anymore but use SetOption109 + return Settings.flag4.alexa_gen_1 ? 1 : 2; } void HueGlobalConfig(String *path) { @@ -893,7 +878,7 @@ void HandleHueApi(String *path) path->remove(0, 4); // remove /api uint16_t apilen = path->length(); - AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE_API " (%s)"), path->c_str()); // HTP: Hue API (//lights/1/state + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE_API " (%s) from %s"), path->c_str(), Webserver->client().remoteIP().toString().c_str()); // HTP: Hue API (//lights/1/state) from 192.168.1.20 for (args = 0; args < Webserver->args(); args++) { String json = Webserver->arg(args); AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE_POST_ARGS " (%s)"), json.c_str()); // HTP: Hue POST args ({"on":false}) diff --git a/tasmota/xdrv_21_wemo.ino b/tasmota/xdrv_21_wemo.ino index 5376d4248..30f9e7749 100644 --- a/tasmota/xdrv_21_wemo.ino +++ b/tasmota/xdrv_21_wemo.ino @@ -267,9 +267,13 @@ const char WEMO_SETUP_XML[] PROGMEM = /********************************************************************************************/ +void LogUpnpWithClient(const char *msg) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP "%s from %s"), msg, Webserver->client().remoteIP().toString().c_str()); +} + void HandleUpnpEvent(void) { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT)); + LogUpnpWithClient(PSTR(D_WEMO_BASIC_EVENT)); char event[500]; strlcpy(event, Webserver->arg(0).c_str(), sizeof(event)); @@ -303,7 +307,7 @@ void HandleUpnpEvent(void) void HandleUpnpService(void) { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_EVENT_SERVICE)); + LogUpnpWithClient(PSTR(D_WEMO_EVENT_SERVICE)); #ifdef USE_UNISHOX_COMPRESSION WSSend(200, CT_PLAIN, Decompress(WEMO_EVENTSERVICE_XML, WEMO_EVENTSERVICE_XML_SIZE)); @@ -314,7 +318,7 @@ void HandleUpnpService(void) void HandleUpnpMetaService(void) { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_META_SERVICE)); + LogUpnpWithClient(PSTR(D_WEMO_META_SERVICE)); #ifdef USE_UNISHOX_COMPRESSION WSSend(200, CT_PLAIN, Decompress(WEMO_METASERVICE_XML, WEMO_METASERVICE_XML_SIZE)); @@ -325,7 +329,7 @@ void HandleUpnpMetaService(void) void HandleUpnpSetupWemo(void) { - AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_SETUP)); + LogUpnpWithClient(PSTR(D_WEMO_SETUP)); #ifdef USE_UNISHOX_COMPRESSION String setup_xml = Decompress(WEMO_SETUP_XML, WEMO_SETUP_XML_SIZE); From 9d400ac00a69100116f3ba5de487e2e6d7c8bdf6 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 27 Aug 2020 19:02:17 +0200 Subject: [PATCH 2/2] Remove unused array. --- tasmota/xdrv_20_hue.ino | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tasmota/xdrv_20_hue.ino b/tasmota/xdrv_20_hue.ino index 354a527e7..974ebbb78 100644 --- a/tasmota/xdrv_20_hue.ino +++ b/tasmota/xdrv_20_hue.ino @@ -505,10 +505,6 @@ uint32_t DecodeLightId(uint32_t hue_id, uint16_t * shortaddr = nullptr) return relay_id; } -static const char * FIRST_GEN_UA[] = { // list of User-Agents signature - "AEOBC", // Echo Dot 2ng Generation -}; - // Check if the Echo device is of 1st generation, which triggers different results inline uint32_t findEchoGeneration(void) { // don't try to guess from User-Agent anymore but use SetOption109