From b3039de1b6b844ff5987e23ebf27ad5a06b6763c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 10 Oct 2018 22:21:44 +0200 Subject: [PATCH] 6.2.1.14 Rewrite Webserver 6.2.1.14 20181010 * Rewrite Webserver page handler for easier extension (thx to Adrian Scillato) --- sonoff/_changelog.ino | 5 +- sonoff/i18n.h | 1 - sonoff/sonoff.h | 2 +- sonoff/sonoff_version.h | 2 +- sonoff/xdrv_01_webserver.ino | 2003 ++++++++++++++++++++++++++++++++++ sonoff/xdrv_02_mqtt.ino | 903 +++++++++++++++ sonoff/xdrv_07_domoticz.ino | 49 +- sonoff/xdrv_09_timers.ino | 33 +- sonoff/xdrv_11_knx.ino | 18 +- sonoff/xplg_wemohue.ino | 14 + 10 files changed, 3002 insertions(+), 28 deletions(-) create mode 100644 sonoff/xdrv_01_webserver.ino create mode 100644 sonoff/xdrv_02_mqtt.ino diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index b2210c830..def41834a 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.2.1.13 20181008 +/* 6.2.1.14 20181010 + * Rewrite Webserver page handler for easier extension (thx to Adrian Scillato) + * + * 6.2.1.13 20181008 * Change default Mqtt client library from PubSubClient to non-blocking ArduinoMqtt by Joel Gaehwiler * Add command WebRefresh 1000..10000 to control web page refresh in milliseconds. Default is 2345 * diff --git a/sonoff/i18n.h b/sonoff/i18n.h index ab1f0a1d2..62226f91f 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -539,7 +539,6 @@ const char S_CONFIGURATION[] PROGMEM = D_CONFIGURATION; const char S_CONFIGURE_MODULE[] PROGMEM = D_CONFIGURE_MODULE; const char S_CONFIGURE_WIFI[] PROGMEM = D_CONFIGURE_WIFI; const char S_NO_NETWORKS_FOUND[] PROGMEM = D_NO_NETWORKS_FOUND; -const char S_CONFIGURE_MQTT[] PROGMEM = D_CONFIGURE_MQTT; const char S_CONFIGURE_LOGGING[] PROGMEM = D_CONFIGURE_LOGGING; const char S_CONFIGURE_OTHER[] PROGMEM = D_CONFIGURE_OTHER; const char S_SAVE_CONFIGURATION[] PROGMEM = D_SAVE_CONFIGURATION; diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 5d41aa18d..5bc744157 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -214,7 +214,7 @@ enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MA enum XsnsFunctions {FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR, - FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM}; + FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_HANDLER}; const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 }; diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index eba7ddc21..080c76fa4 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0602010D +#define VERSION 0x0602010E #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino new file mode 100644 index 000000000..50345145f --- /dev/null +++ b/sonoff/xdrv_01_webserver.ino @@ -0,0 +1,2003 @@ +/* + xdrv_01_webserver.ino - webserver for Sonoff-Tasmota + + Copyright (C) 2018 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_WEBSERVER +/*********************************************************************************************\ + * Web server and WiFi Manager + * + * Enables configuration and reconfiguration of WiFi credentials using a Captive Portal + * Based on source by AlexT (https://github.com/tzapu) +\*********************************************************************************************/ + +#define HTTP_REFRESH_TIME 2345 // milliseconds + +#ifdef USE_RF_FLASH +uint8_t *efm8bb1_update = NULL; +#endif // USE_RF_FLASH + +enum UploadTypes { UPL_TASMOTA, UPL_SETTINGS, UPL_EFM8BB1 }; + +const char HTTP_HEAD[] PROGMEM = + "" + "" + "" + "" + "{h} - {v}" + + "" + + "" + + "" + "" + "
" +#ifdef BE_MINIMAL + "

" D_MINIMAL_FIRMWARE_PLEASE_UPGRADE "

" +#endif + "
" +#ifdef LANGUAGE_MODULE_NAME + "

" D_MODULE " {ha

" +#else + "

{ha " D_MODULE "

" +#endif + "

{h}

"; +const char HTTP_SCRIPT_CONSOL[] PROGMEM = + "var sn=0;" // Scroll position + "var id=0;" // Get most of weblog initially + "function l(p){" // Console log and command service + "var c,o,t;" + "clearTimeout(lt);" + "o='';" + "t=eb('t1');" + "if(p==1){" + "c=eb('c1');" + "o='&c1='+encodeURIComponent(c.value);" + "c.value='';" + "t.scrollTop=sn;" + "}" + "if(t.scrollTop>=sn){" // User scrolled back so no updates + "if(x!=null){x.abort();}" // Abort if no response within 2 seconds (happens on restart 1) + "x=new XMLHttpRequest();" + "x.onreadystatechange=function(){" + "if(x.readyState==4&&x.status==200){" + "var z,d;" + "d=x.responseXML;" + "id=d.getElementsByTagName('i')[0].childNodes[0].nodeValue;" + "if(d.getElementsByTagName('j')[0].childNodes[0].nodeValue==0){t.value='';}" + "z=d.getElementsByTagName('l')[0].childNodes;" + "if(z.length>0){t.value+=decodeURIComponent(z[0].nodeValue);}" + "t.scrollTop=99999;" + "sn=t.scrollTop;" + "}" + "};" + "x.open('GET','ax?c2='+id+o,true);" + "x.send();" + "}" + "lt=setTimeout(l,{a});" + "return false;" + "}" + ""; +const char HTTP_SCRIPT_MODULE1[] PROGMEM = + "var os;" + "function sk(s,g){" + "var o=os.replace(\"value='\"+s+\"'\",\"selected value='\"+s+\"'\");" + "eb('g'+g).innerHTML=o;" + "}" + "function sl(){" + "var o0=\""; +const char HTTP_SCRIPT_MODULE2[] PROGMEM = + "}1'%d'>%02d %s}2"; // "}1" and "}2" means do not use "}x" in Module name and Sensor name +const char HTTP_SCRIPT_MODULE3[] PROGMEM = + "\";" + "os=o0.replace(/}1/g,\"