From bb3fb7c4d6ff128bbc313e42ca8dd75ce8950a2f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Jun 2019 13:21:12 +0200 Subject: [PATCH 1/6] Fix Hue Emulation Fix Hue Emulation (#5849) --- sonoff/xdrv_20_hue.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sonoff/xdrv_20_hue.ino b/sonoff/xdrv_20_hue.ino index 6a4617ffc..7d7934106 100644 --- a/sonoff/xdrv_20_hue.ino +++ b/sonoff/xdrv_20_hue.ino @@ -344,7 +344,7 @@ void HueLightStatus2(uint8_t device, String *response) // generate a unique lightId mixing local IP address and device number // it is limited to 16 devices. -// last 16 bits of Mac address + 4 bits of local light +// last 24 bits of Mac address + 4 bits of local light uint32_t EncodeLightId(uint8_t idx) { uint8_t mac[6]; @@ -422,7 +422,7 @@ void HueLights(String *path) else if (path->endsWith("/state")) { // Got ID/state path->remove(0,8); // Remove /lights/ path->remove(path->indexOf("/state")); // Remove /state - device = atoi(path->c_str()); + device = DecodeLightId(atoi(path->c_str())); if ((device < 1) || (device > maxhue)) { device = 1; } @@ -434,7 +434,7 @@ void HueLights(String *path) if (hue_json.containsKey("on")) { response += FPSTR(HUE_LIGHT_RESPONSE_JSON); - response.replace("{id", String(device)); + response.replace("{id", String(EncodeLightId(device))); response.replace("{cm", "on"); on = hue_json["on"]; From ffd36e0b2d53aa673fdc902c324139487dabbd3d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Jun 2019 16:44:02 +0200 Subject: [PATCH 2/6] 6.5.0.14 Webserver HTML/Javascript changes 6.5.0.14 20190602 * Change webserver HTML input, button, textarea, and select name based on id * Fix webserver multiple Javascript window.onload functionality --- sonoff/_changelog.ino | 6 +++- sonoff/sonoff_version.h | 2 +- sonoff/xdrv_01_webserver.ino | 69 +++++++++++++++++++++++++----------- sonoff/xdrv_09_timers.ino | 6 ++-- sonoff/xdrv_11_knx.ino | 10 +++--- 5 files changed, 62 insertions(+), 31 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 6bed2c3b5..93cf1687f 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,8 @@ -/* 6.5.0.13 20190527 +/* 6.5.0.14 20190602 + * Change webserver HTML input, button, textarea, and select name based on id + * Fix webserver multiple Javascript window.onload functionality + * + * 6.5.0.13 20190527 * Add command SetOption38 6..255 to set IRReceive protocol detection sensitivity mimizing UNKNOWN protocols (#5853) * Fix missing white channel for WS2812 (#5869) * Add reset of Energy values when connection to sensor is lost for over 4 seconds (#5874, #5881) diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 8b7c27bfc..6c475febc 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,6 +20,6 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -const uint32_t VERSION = 0x0605000D; +const uint32_t VERSION = 0x0605000E; #endif // _SONOFF_VERSION_H_ diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index e71e4016d..6440d6370 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -58,13 +58,24 @@ const char HTTP_HEAD[] PROGMEM = "function eb(s){" "return document.getElementById(s);" // Save code space "}" - "function qs(s){" // Alias to save code space + "function qs(s){" // Alias to save code space "return document.querySelector(s);" "}" - "function idn(){" - "var t=0,i=document.querySelectorAll('input,button,textarea,select'); while(i.length>=t){ if(i[t]) {i[t]['name']=(i[t].hasAttribute('id')&&(!i[t].hasAttribute('name')))?i[t]['id']:i[t]['name'];}t++;}" - "}" - "window.onload=idn;idn();"; + + // https://www.htmlgoodies.com/beyond/javascript/article.php/3724571/Using-Multiple-JavaScript-Onload-Functions.htm + "function wl(f){" // Execute multiple window.onload + "var o=window.onload;" + "if(typeof window.onload!='function'){" + "window.onload=f;" + "}else{" + "window.onload=function(){" + "if(o){" + "o();" + "}" + "f();" + "}" + "}" + "}"; const char HTTP_SCRIPT_COUNTER[] PROGMEM = "var cn=180;" // seconds @@ -75,7 +86,7 @@ const char HTTP_SCRIPT_COUNTER[] PROGMEM = "setTimeout(u,1000);" "}" "}" - "window.onload=u;"; + "wl(u);"; const char HTTP_SCRIPT_ROOT[] PROGMEM = "function la(p){" @@ -102,7 +113,7 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM = "function lc(p){" "la('&t='+p);" // &t related to WebGetArg("t", tmp, sizeof(tmp)); "}" - "window.onload=la();"; + "wl(la);"; const char HTTP_SCRIPT_WIFI[] PROGMEM = "function c(l){" @@ -152,7 +163,7 @@ const char HTTP_SCRIPT_CONSOL[] PROGMEM = "lt=setTimeout(l,%d);" "return false;" "}" - "window.onload=l;"; + "wl(l);"; const char HTTP_MODULE_TEMPLATE_REPLACE[] PROGMEM = "}2%d'>%s (%d}3"; // }2 and }3 are used in below os.replace @@ -218,7 +229,10 @@ const char HTTP_SCRIPT_TEMPLATE[] PROGMEM = "sk(17,99);" // 17 = WEMOS "st(" STR(USER_MODULE) ");" "}" - "window.onload=ld('tp?m=1',x2);"; // ?m related to WebServer->hasArg("m") + "function sl(){" + "ld('tp?m=1',x2);" // ?m related to WebServer->hasArg("m") + "}" + "wl(sl);"; const char HTTP_SCRIPT_MODULE1[] PROGMEM = "function x1(a){" // Module Type @@ -240,7 +254,7 @@ const char HTTP_SCRIPT_MODULE2[] PROGMEM = "ld('md?a=1',x3);" // ?a related to WebServer->hasArg("a") "}" "}" - "window.onload=sl;"; + "wl(sl);"; const char HTTP_SCRIPT_INFO_BEGIN[] PROGMEM = "function i(){" @@ -250,11 +264,22 @@ const char HTTP_SCRIPT_INFO_END[] PROGMEM = "s=o.replace(/}1/g,\"