diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index f2fe6dbe0..79da30741 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -25,10 +25,10 @@ * Based on source by AlexT (https://github.com/tzapu) \*********************************************************************************************/ -#ifdef USE_KNX -#include // Include KNX IP library +#ifdef USE_KNX +#include // Include KNX IP library #endif // USE_KNX - + #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -43,16 +43,19 @@ const char HTTP_HEAD[] PROGMEM = "var cn,x,lt;" "cn=180;" "x=null;" // Allow for abortion + "function eb(s){" + "return document.getElementById(s);" // Save code space + "}" "function u(){" "if(cn>=0){" - "document.getElementById('t').innerHTML='" D_RESTART_IN " '+cn+' " D_SECONDS "';" + "eb('t').innerHTML='" D_RESTART_IN " '+cn+' " D_SECONDS "';" "cn--;" "setTimeout(u,1000);" "}" "}" "function c(l){" - "document.getElementById('s1').value=l.innerText||l.textContent;" - "document.getElementById('p1').focus();" + "eb('s1').value=l.innerText||l.textContent;" + "eb('p1').focus();" "}" "function la(p){" "var a='';" @@ -65,7 +68,7 @@ const char HTTP_HEAD[] PROGMEM = "x.onreadystatechange=function(){" "if(x.readyState==4&&x.status==200){" "var s=x.responseText.replace(/{t}/g,\"\").replace(/{s}/g,\"\").replace(/{c}/g,\"%'>
\").replace(/{m}/g,\"\").replace(/{e}/g,\"
\").replace(/}2/g,\"\");" - "document.getElementById('i').innerHTML=s;" + "eb('i').innerHTML=s;" "}" ""; const char HTTP_MSG_SLIDER1[] PROGMEM = @@ -184,6 +187,11 @@ const char HTTP_BTN_RSTRT[] PROGMEM = "
"; const char HTTP_BTN_MENU2[] PROGMEM = "
" +#ifdef USE_TIMERS +#ifdef USE_TIMERS_WEB + "
" +#endif // USE_TIMERS_WEB +#endif // USE_TIMERS "
"; const char HTTP_BTN_MENU3[] PROGMEM = "
" @@ -192,9 +200,9 @@ const char HTTP_BTN_MENU3[] PROGMEM = #endif // USE_DOMOTICZ ""; const char HTTP_BTN_MENU4[] PROGMEM = -#ifdef USE_KNX - "
" -#endif // USE_KNX +#ifdef USE_KNX + "
" +#endif // USE_KNX "
" "
" "
" @@ -213,7 +221,7 @@ const char HTTP_BTN_CONF[] PROGMEM = "

"; const char HTTP_FORM_MODULE[] PROGMEM = "
 " D_MODULE_PARAMETERS " 
" - "" + "" "
" D_MODULE_TYPE " ({mt)

"; const char HTTP_LNK_ITEM[] PROGMEM = "
{v} {i} {r}%
"; @@ -221,7 +229,7 @@ const char HTTP_LNK_SCAN[] PROGMEM = "
"; const char HTTP_FORM_WIFI[] PROGMEM = "
 " D_WIFI_PARAMETERS " " - "" + "" "
" D_AP1_SSID " (" STA_SSID1 ")

" "
" D_AP1_PASSWORD "

" "
" D_AP2_SSID " (" STA_SSID2 ")

" @@ -229,7 +237,7 @@ const char HTTP_FORM_WIFI[] PROGMEM = "
" D_HOSTNAME " (" WIFI_HOSTNAME ")

"; const char HTTP_FORM_MQTT[] PROGMEM = "
 " D_MQTT_PARAMETERS " " - "" + "" "
" D_HOST " (" MQTT_HOST ")

" "
" D_PORT " (" STR(MQTT_PORT) ")

" "
" D_CLIENT " ({m0)

" @@ -239,7 +247,7 @@ const char HTTP_FORM_MQTT[] PROGMEM = "
" D_FULL_TOPIC " (" MQTT_FULLTOPIC ")

"; const char HTTP_FORM_LOG1[] PROGMEM = "
 " D_LOGGING_PARAMETERS " " - ""; + ""; const char HTTP_FORM_LOG2[] PROGMEM = "
{b0 ({b1)

"; const char HTTP_FORM_OTHER[] PROGMEM = "
 " D_OTHER_PARAMETERS " " - "" + "" "
" D_WEB_ADMIN_PASSWORD "

" "
" D_MQTT_ENABLE "
"; const char HTTP_FORM_OTHER2[] PROGMEM = @@ -281,7 +289,7 @@ const char HTTP_FORM_UPG[] PROGMEM = const char HTTP_FORM_RST_UPG[] PROGMEM = "" "

" - "
" + "
" "
" "" ""; @@ -337,6 +345,11 @@ void StartWebserver(int type, IPAddress ipweb) WebServer->on("/", HandleRoot); WebServer->on("/cn", HandleConfiguration); WebServer->on("/md", HandleModuleConfiguration); +#ifdef USE_TIMERS +#ifdef USE_TIMERS_WEB + WebServer->on("/tm", HandleTimerConfiguration); +#endif // USE_TIMERS_WEB +#endif // USE_TIMERS WebServer->on("/w1", HandleWifiConfigurationWithScan); WebServer->on("/w0", HandleWifiConfiguration); if (Settings.flag.mqtt_enabled) { @@ -374,9 +387,9 @@ void StartWebserver(int type, IPAddress ipweb) } #endif // USE_EMULATION WebServer->onNotFound(HandleNotFound); -#ifdef USE_KNX - knx.start(WebServer); // Start knx. The /knx link is automatically set inside the KNX library -#endif // USE_KNX +#ifdef USE_KNX + knx.start(WebServer); // Start knx. The /knx link is automatically set inside the KNX library +#endif // USE_KNX } reset_web_log_flag = 0; WebServer->begin(); // Web server start @@ -1011,17 +1024,16 @@ void HandleSaveSettings() char stemp[TOPSZ]; char stemp2[TOPSZ]; - byte what = 0; - byte restart; String result = ""; AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_SAVE_CONFIGURATION); char tmp[100]; - WebGetArg("w", tmp, sizeof(tmp)); - if (strlen(tmp)) { - what = atoi(tmp); - } + WebGetArg("w", tmp, sizeof(tmp)); // Returns "5,1" where 5 is config type and 1 is restart flag + char *p = tmp; + uint8_t what = strtol(p, &p, 10); + p++; // Skip comma + uint8_t restart = strtol(p, &p, 10); switch (what) { case 1: WebGetArg("h", tmp, sizeof(tmp)); @@ -1095,6 +1107,13 @@ void HandleSaveSettings() Settings.seriallog_level, Settings.weblog_level, Settings.syslog_level, Settings.syslog_host, Settings.syslog_port, Settings.tele_period); AddLog(LOG_LEVEL_INFO); break; +#ifdef USE_TIMERS +#ifdef USE_TIMERS_WEB + case 7: + TimerSaveSettings(); + break; +#endif // USE_TIMERS_WEB +#endif // USE_TIMERS #ifdef USE_DOMOTICZ case 4: DomoticzSaveSettings(); @@ -1146,8 +1165,6 @@ void HandleSaveSettings() break; } - WebGetArg("r", tmp, sizeof(tmp)); - restart = (!strlen(tmp)) ? 1 : atoi(tmp); if (restart) { String page = FPSTR(HTTP_HEAD); page.replace(F("{v}"), FPSTR(S_SAVE_CONFIGURATION));