diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index a0f01a763..6070d8ac8 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -76,7 +76,7 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM = "a=p;" "clearTimeout(lt);" "}" - "if(x!=null){x.abort();}" // Abort if no response within 2 seconds (happens on restart 1) + "if(x!=null){x.abort();}" // Abort if no response within Settings.web_refresh milliseconds (happens on restart 1) "x=new XMLHttpRequest();" "x.onreadystatechange=function(){" "if(x.readyState==4&&x.status==200){" @@ -84,15 +84,15 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM = "eb('l1').innerHTML=s;" "}" "};" - "x.open('GET','ay'+a,true);" + "x.open('GET','?m=1'+a,true);" // ?m related to WebServer->hasArg("m") "x.send();" "lt=setTimeout(la,{a});" // Settings.web_refresh "}" "function lb(p){" - "la('?d='+p);" // ?d related to WebGetArg("d", tmp, sizeof(tmp)); + "la('&d='+p);" // &d related to WebGetArg("d", tmp, sizeof(tmp)); "}" "function lc(p){" - "la('?t='+p);" // ?t related to WebGetArg("t", tmp, sizeof(tmp)); + "la('&t='+p);" // &t related to WebGetArg("t", tmp, sizeof(tmp)); "}" "window.onload=la();"; @@ -140,7 +140,7 @@ const char HTTP_SCRIPT_CONSOL[] PROGMEM = "sn=t.scrollTop;" "}" "};" - "x.open('GET','ax?c2='+id+o,true);" + "x.open('GET','cs?c2='+id+o,true);" // Related to WebServer->hasArg("c2") and WebGetArg("c2", stmp, sizeof(stmp)) "x.send();" "}" "lt=setTimeout(l,{a});" @@ -431,7 +431,7 @@ const char HTTP_END[] PROGMEM = "" ""; -const char HTTP_DEVICE_CONTROL[] PROGMEM = ""; // ?o is related to WebGetArg("o", tmp, sizeof(tmp)); +const char HTTP_DEVICE_CONTROL[] PROGMEM = ""; // ?o is related to WebGetArg("o", tmp, sizeof(tmp)); const char HTTP_DEVICE_STATE[] PROGMEM = "%s%s"; // {c} = %'>
"); - if (devices_present) { - if (light_type) { - if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MSG_SLIDER1, LightGetColorTemp()); - page += mqtt_data; - } - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MSG_SLIDER2, Settings.light_dimmer); + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_MAIN_MENU); + + char stemp[5]; + + String page = FPSTR(HTTP_HEAD); + page.replace(F("{v}"), FPSTR(S_MAIN_MENU)); + page += FPSTR(HTTP_SCRIPT_ROOT); + page += FPSTR(HTTP_HEAD_STYLE); + + page += F("
"); + if (devices_present) { + if (light_type) { + if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MSG_SLIDER1, LightGetColorTemp()); page += mqtt_data; } - page += FPSTR(HTTP_TABLE100); - page += F(""); - if (SONOFF_IFAN02 == my_module_type) { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, ""); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_MSG_SLIDER2, Settings.light_dimmer); + page += mqtt_data; + } + page += FPSTR(HTTP_TABLE100); + page += F(""); + if (SONOFF_IFAN02 == my_module_type) { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, ""); + page += mqtt_data; + for (uint8_t i = 0; i < MAX_FAN_SPEED; i++) { + snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, 16, i +2, stemp, ""); page += mqtt_data; - for (uint8_t i = 0; i < MAX_FAN_SPEED; i++) { - snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i); - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, 16, i +2, stemp, ""); - page += mqtt_data; - } - } else { - for (uint8_t idx = 1; idx <= devices_present; idx++) { - snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx); - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, - 100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : ""); - page += mqtt_data; - } } - page += F(""); - } - if (SONOFF_BRIDGE == my_module_type) { - page += FPSTR(HTTP_TABLE100); - page += F(""); - uint8_t idx = 0; - for (uint8_t i = 0; i < 4; i++) { - if (idx > 0) { page += F(""); } - for (uint8_t j = 0; j < 4; j++) { - idx++; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(""), idx, idx); // ?k is related to WebGetArg("k", tmp, sizeof(tmp)); - page += mqtt_data; - } + } else { + for (uint8_t idx = 1; idx <= devices_present; idx++) { + snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_DEVICE_CONTROL, + 100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : ""); + page += mqtt_data; } - page += F(""); } + page += F(""); + } + if (SONOFF_BRIDGE == my_module_type) { + page += FPSTR(HTTP_TABLE100); + page += F(""); + uint8_t idx = 0; + for (uint8_t i = 0; i < 4; i++) { + if (idx > 0) { page += F(""); } + for (uint8_t j = 0; j < 4; j++) { + idx++; + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(""), idx, idx); // ?k is related to WebGetArg("k", tmp, sizeof(tmp)); + page += mqtt_data; + } + } + page += F(""); + } #ifndef FIRMWARE_MINIMAL - mqtt_data[0] = '\0'; - XdrvCall(FUNC_WEB_ADD_MAIN_BUTTON); - XsnsCall(FUNC_WEB_ADD_MAIN_BUTTON); - page += String(mqtt_data); + mqtt_data[0] = '\0'; + XdrvCall(FUNC_WEB_ADD_MAIN_BUTTON); + XsnsCall(FUNC_WEB_ADD_MAIN_BUTTON); + page += String(mqtt_data); #endif // Not FIRMWARE_MINIMAL - if (HTTP_ADMIN == webserver_state) { - page += FPSTR(HTTP_BTN_MENU1); - page += FPSTR(HTTP_BTN_RSTRT); - } - ShowPage(page); + if (HTTP_ADMIN == webserver_state) { + page += FPSTR(HTTP_BTN_MENU1); + page += FPSTR(HTTP_BTN_RSTRT); } + ShowPage(page); } -void HandleAjaxStatusRefresh(void) +bool HandleRootStatusRefresh(void) { - if (!WebAuthenticate()) { return WebServer->requestAuthentication(); } + if (!WebAuthenticate()) { + WebServer->requestAuthentication(); + return true; + } + + if (!WebServer->hasArg("m")) { // Status refresh requested + return false; + } char tmp[8]; // WebGetArg numbers only char svalue[32]; // Command and number parameter @@ -864,6 +873,7 @@ void HandleAjaxStatusRefresh(void) snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s"), mqtt_data); } WSSend(200, CT_HTML, mqtt_data); + return true; } bool HttpCheckPriviledgedAccess(bool autorequestauth = true) @@ -2016,6 +2026,11 @@ void HandleConsole(void) { if (!HttpCheckPriviledgedAccess()) { return; } + if (WebServer->hasArg("c2")) { // Console refresh requested + HandleConsoleRefresh(); + return; + } + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONSOLE); String page = FPSTR(HTTP_HEAD); @@ -2027,10 +2042,8 @@ void HandleConsole(void) ShowPage(page); } -void HandleAjaxConsoleRefresh(void) +void HandleConsoleRefresh(void) { - if (!HttpCheckPriviledgedAccess()) { return; } - bool cflg = true; uint8_t counter = 0; // Initial start, should never be 0 again