\").replace(/}2/g,\" | \");"
"eb('i').innerHTML=s;"
"}"
From 483eb4dd44b3a75ed15acc0432e4a742f666c0c7 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Mon, 18 Feb 2019 13:10:10 +0100
Subject: [PATCH 44/68] Change Flags to Options
Change Flags to Options and enforce Activate for already active template (#5256)
---
sonoff/language/cs-CZ.h | 2 +-
sonoff/language/de-DE.h | 2 +-
sonoff/language/el-GR.h | 2 +-
sonoff/language/en-GB.h | 2 +-
sonoff/language/es-AR.h | 2 +-
sonoff/language/fr-FR.h | 2 +-
sonoff/language/he-HE.h | 2 +-
sonoff/language/hu-HU.h | 2 +-
sonoff/language/it-IT.h | 2 +-
sonoff/language/nl-NL.h | 2 +-
sonoff/language/pl-PL.h | 2 +-
sonoff/language/pt-BR.h | 2 +-
sonoff/language/pt-PT.h | 2 +-
sonoff/language/ru-RU.h | 2 +-
sonoff/language/sk-SK.h | 2 +-
sonoff/language/sv-SE.h | 2 +-
sonoff/language/tr-TR.h | 2 +-
sonoff/language/uk-UK.h | 2 +-
sonoff/language/zh-CN.h | 2 +-
sonoff/language/zh-TW.h | 2 +-
sonoff/xdrv_01_webserver.ino | 3 ++-
21 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h
index 769acfd0d..e9d17bb8e 100644
--- a/sonoff/language/cs-CZ.h
+++ b/sonoff/language/cs-CZ.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h
index 1bc7b2ea7..ed3202919 100644
--- a/sonoff/language/de-DE.h
+++ b/sonoff/language/de-DE.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Vorlage Parameter"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "basiert auf"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "Nutzer pull-up Auswahl"
diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h
index 3d96d4744..8e4cf7077 100644
--- a/sonoff/language/el-GR.h
+++ b/sonoff/language/el-GR.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h
index 7d8f32e6b..794af57fa 100644
--- a/sonoff/language/en-GB.h
+++ b/sonoff/language/en-GB.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h
index 1bc0f064c..9dc72cf7c 100644
--- a/sonoff/language/es-AR.h
+++ b/sonoff/language/es-AR.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h
index 562d85e60..06ada0874 100644
--- a/sonoff/language/fr-FR.h
+++ b/sonoff/language/fr-FR.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Paramètres du modèle"
#define D_TEMPLATE_NAME "Nom"
#define D_BASE_TYPE "Basé sur"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "Entrée ADC0"
#define D_ALLOW_PULLUP "Choix de pull-up utilisateur"
diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h
index deca89d18..8437e1a05 100644
--- a/sonoff/language/he-HE.h
+++ b/sonoff/language/he-HE.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h
index e9eed8025..393d250e7 100644
--- a/sonoff/language/hu-HU.h
+++ b/sonoff/language/hu-HU.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h
index 8269441ae..0f35e92b2 100644
--- a/sonoff/language/it-IT.h
+++ b/sonoff/language/it-IT.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h
index 00d658d0c..b8b159eff 100644
--- a/sonoff/language/nl-NL.h
+++ b/sonoff/language/nl-NL.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h
index 14161f0be..5d2db7afc 100644
--- a/sonoff/language/pl-PL.h
+++ b/sonoff/language/pl-PL.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h
index 013768607..94d7bea00 100644
--- a/sonoff/language/pt-BR.h
+++ b/sonoff/language/pt-BR.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h
index 11f10f750..47dec4ea2 100644
--- a/sonoff/language/pt-PT.h
+++ b/sonoff/language/pt-PT.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h
index b3641c647..038ba6615 100644
--- a/sonoff/language/ru-RU.h
+++ b/sonoff/language/ru-RU.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/sk-SK.h b/sonoff/language/sk-SK.h
index 76fa89e7a..ff05b471d 100644
--- a/sonoff/language/sk-SK.h
+++ b/sonoff/language/sk-SK.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/sv-SE.h b/sonoff/language/sv-SE.h
index eca87b7c7..9045b2e24 100644
--- a/sonoff/language/sv-SE.h
+++ b/sonoff/language/sv-SE.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h
index bb9aa1a4c..f971c9ba2 100755
--- a/sonoff/language/tr-TR.h
+++ b/sonoff/language/tr-TR.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h
index 289e9292c..1557a0d78 100644
--- a/sonoff/language/uk-UK.h
+++ b/sonoff/language/uk-UK.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h
index f37a127de..4e3a7d9fd 100644
--- a/sonoff/language/zh-CN.h
+++ b/sonoff/language/zh-CN.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h
index 5188db09b..f8526aa5b 100644
--- a/sonoff/language/zh-TW.h
+++ b/sonoff/language/zh-TW.h
@@ -302,7 +302,7 @@
#define D_TEMPLATE_PARAMETERS "Template parameters"
#define D_TEMPLATE_NAME "Name"
#define D_BASE_TYPE "Based on"
-#define D_TEMPLATE_FLAGS "Flags"
+#define D_TEMPLATE_FLAGS "Options"
#define D_ALLOW_ADC0 "ADC0 input"
#define D_ALLOW_PULLUP "User pull-up selection"
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 4817dde85..3370fda1f 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -368,7 +368,7 @@ const char HTTP_FORM_OTHER[] PROGMEM =
""
""
" "
"" D_WEB_ADMIN_PASSWORD "
"
@@ -1352,6 +1352,7 @@ void HandleOtherConfiguration(void)
page += FPSTR(HTTP_FORM_OTHER);
TemplateJson();
page.replace(F("{t1"), mqtt_data);
+ page.replace(F("{t2"), (USER_MODULE == Settings.module) ? F(" checked disabled") : F(""));
page.replace(F("{r1"), (Settings.flag.mqtt_enabled) ? F(" checked") : F(""));
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
From a6c7e3b5f421e942f283e9384e87f33e76366b69 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Mon, 18 Feb 2019 15:13:37 +0100
Subject: [PATCH 45/68] Update xdrv_01_webserver.ino
Force restart on any template change to fix page refresh hang (#5222)
---
sonoff/xdrv_01_webserver.ino | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 3370fda1f..c78a47c57 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -185,7 +185,7 @@ const char HTTP_SCRIPT_TEMPLATE[] PROGMEM =
"sk(g[i],j);" // Set GPIO
"j++;"
"}"
- "for(i=0;i<1;i++){" // Supports 1 FLAG
+ "for(i=0;i<" STR(GPIO_FLAG_USED) ";i++){"
"p=(g[13]>>i)&1;"
"eb('c'+i).checked=p;" // Set FLAG checkboxes
"}"
@@ -886,9 +886,7 @@ void HandleTemplateConfiguration(void)
if (WebServer->hasArg("save")) {
TemplateSaveSettings();
- if (USER_MODULE == Settings.module) {
- WebRestart(1);
- }
+ WebRestart(1);
return;
}
@@ -917,7 +915,6 @@ void HandleTemplateConfiguration(void)
String page = AnyModuleName(module); // NAME: Generic
-// page += F("}1'255'>" D_SENSOR_USER " (255)}2"); // GPIO: }1'255'>User (255)}2
for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) { // GPIO: }1'0'>None (0)}2}1'17'>Button1 (17)}2...
if (1 == i) {
@@ -932,7 +929,7 @@ void HandleTemplateConfiguration(void)
mqtt_data[0] = '\0';
for (uint8_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
- if ((i < 6) || ((i > 8) && (i < 11)) || (i > 11)) { // Ignore flash pins GPIO06, 7, 8 and 11
+ if ((i < 6) || ((i > 8) && (i != 11))) { // Ignore flash pins GPIO06, 7, 8 and 11
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d"), mqtt_data, (i>0)?",":"", cmodule.io[i]);
}
}
@@ -953,9 +950,9 @@ void HandleTemplateConfiguration(void)
page += FPSTR(HTTP_FORM_TEMPLATE);
page += F("
");
for (uint8_t i = 0; i < 17; i++) {
- if ((i < 6) || ((i > 8) && (i < 11)) || (i > 11)) { // Ignore flash pins GPIO06, 7, 8 and 11
+ if ((i < 6) || ((i > 8) && (i != 11))) { // Ignore flash pins GPIO06, 7, 8 and 11
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("" D_GPIO "%d | %s | | "),
- (0==i)?" style='width:80px'":"", i, ((9==i)||(10==i))? "ESP8285" :"", (0==i)?" style='width:176px'":"", i, i);
+ (0==i)?" style='width:74px'":"", i, ((9==i)||(10==i))? "ESP8285" :"", (0==i)?" style='width:176px'":"", i, i);
page += mqtt_data;
}
}
@@ -987,7 +984,7 @@ void TemplateSaveSettings(void)
}
uint8_t flag = 0;
- for (uint8_t i = 0; i < 2; i++) {
+ for (uint8_t i = 0; i < GPIO_FLAG_USED; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("c%d"), i);
uint8_t state = WebServer->hasArg(stemp) << i; // FLAG
flag += state;
From e898dc03e7d2ea09454817f2353ae6948bbd0774 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Mon, 18 Feb 2019 15:41:41 +0100
Subject: [PATCH 46/68] Add Wifi Link Connection Count
Add Wifi Link Connection (Retry) count to state message. Always starts with 1 being the initial connection.
---
sonoff/i18n.h | 1 +
sonoff/sonoff.ino | 4 ++--
sonoff/support_wifi.ino | 10 +++++++++-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/sonoff/i18n.h b/sonoff/i18n.h
index a35161433..b5a7f7697 100644
--- a/sonoff/i18n.h
+++ b/sonoff/i18n.h
@@ -89,6 +89,7 @@
#define D_JSON_INFRARED "Infrared"
#define D_JSON_UNKNOWN "Unknown"
#define D_JSON_LIGHT "Light"
+#define D_JSON_LINK_DOWN "LinkCount"
#define D_JSON_LOCAL_TIME "Local"
#define D_JSON_LOW "Low"
#define D_JSON_MAC "Mac"
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 4a62d5c88..9e0f4530e 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1775,8 +1775,8 @@ void MqttShowState(void)
MqttShowPWMState();
}
- snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d}}"),
- mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()));
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_LINK_DOWN "\":%d}}"),
+ mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkDown());
}
bool MqttShowSensor(void)
diff --git a/sonoff/support_wifi.ino b/sonoff/support_wifi.ino
index 90f0584b7..138768138 100644
--- a/sonoff/support_wifi.ino
+++ b/sonoff/support_wifi.ino
@@ -49,6 +49,7 @@ using namespace axTLS;
*/
#include // Wifi, MQTT, Ota, WifiManager
+uint32_t wifi_link_down = 0;
uint8_t wifi_counter;
uint8_t wifi_retry_init;
uint8_t wifi_retry;
@@ -222,7 +223,8 @@ void WifiBegin(uint8_t flag, uint8_t channel)
delay(200);
WiFi.mode(WIFI_STA); // Disable AP mode
WiFiSetSleepMode();
-// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); }
+// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N
+// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G
if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); }
// WiFi.setAutoReconnect(true);
switch (flag) {
@@ -339,6 +341,11 @@ void WifiBeginAfterScan()
}
}
+uint32_t WifiLinkDown()
+{
+ return wifi_link_down;
+}
+
void WifiSetState(uint8_t state)
{
if (state == global_state.wifi_down) {
@@ -346,6 +353,7 @@ void WifiSetState(uint8_t state)
rules_flag.wifi_connected = 1;
} else {
rules_flag.wifi_disconnected = 1;
+ wifi_link_down++;
}
}
global_state.wifi_down = state ^1;
From 0658ae19599e88432bbb20348f1d49279276acd7 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Mon, 18 Feb 2019 16:19:46 +0100
Subject: [PATCH 47/68] Update sonoff_template.h
Fix compile error
---
sonoff/sonoff_template.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h
index bf900ac6b..462ec3b3f 100644
--- a/sonoff/sonoff_template.h
+++ b/sonoff/sonoff_template.h
@@ -335,6 +335,8 @@ typedef struct MYCFGIO {
uint8_t io[MAX_GPIO_PIN - MIN_FLASH_PINS];
} mycfgio;
+#define GPIO_FLAG_USED 1 // Currently only one flag used
+
#define GPIO_FLAG_ADC0 1 // Allow ADC0 when define USE_ADC_VCC is disabled
#define GPIO_FLAG_SPARE01 2 // Allow input pull-up control using SetOption62 - Superseded by user template editing
#define GPIO_FLAG_SPARE02 4
From 4884a94b6d643a40ca60bdd4a6638b82bb185b18 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Mon, 18 Feb 2019 17:05:25 +0100
Subject: [PATCH 48/68] Add LinkCount and MqttCount
* Add property LinkCount to state and status 11 message representing number of Wifi Link re-connections
* Add property MqttCount to status 6 message representing number of Mqtt re-connections
---
sonoff/_changelog.ino | 2 ++
sonoff/i18n.h | 3 ++-
sonoff/sonoff.ino | 8 ++++----
sonoff/support_wifi.ino | 8 ++++----
sonoff/xdrv_02_mqtt.ino | 7 +++++++
5 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index 8872f0e4a..ad30eb7f7 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -5,6 +5,8 @@
* Add rule expression enabled by define USE_EXPRESSION in my_user_config.h (#5210)
* Add Configure Template menu option to GUI (#5222)
* Remove command SetOption62 as it's functionality is replaced by user changing the device template (#5255)
+ * Add property LinkCount to state and status 11 message representing number of Wifi Link re-connections
+ * Add property MqttCount to status 6 message representing number of Mqtt re-connections
*
* 6.4.1.16 20190211
* Initial support for online template change using command Template or GUI Configure Other (#5177)
diff --git a/sonoff/i18n.h b/sonoff/i18n.h
index b5a7f7697..d2e15e475 100644
--- a/sonoff/i18n.h
+++ b/sonoff/i18n.h
@@ -89,13 +89,14 @@
#define D_JSON_INFRARED "Infrared"
#define D_JSON_UNKNOWN "Unknown"
#define D_JSON_LIGHT "Light"
-#define D_JSON_LINK_DOWN "LinkCount"
+#define D_JSON_LINK_COUNT "LinkCount"
#define D_JSON_LOCAL_TIME "Local"
#define D_JSON_LOW "Low"
#define D_JSON_MAC "Mac"
#define D_JSON_MASK "Mask"
#define D_JSON_MINIMAL "minimal"
#define D_JSON_MODEL "Model"
+#define D_JSON_MQTT_COUNT "MqttCount"
#define D_JSON_NO "No"
#define D_JSON_NOISE "Noise"
#define D_JSON_NONE "None"
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 9e0f4530e..26198507b 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1682,8 +1682,8 @@ void PublishStatus(uint8_t payload)
}
if (((0 == payload) || (6 == payload)) && Settings.flag.mqtt_enabled) {
- snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS6_MQTT "\":{\"" D_CMND_MQTTHOST "\":\"%s\",\"" D_CMND_MQTTPORT "\":%d,\"" D_CMND_MQTTCLIENT D_JSON_MASK "\":\"%s\",\"" D_CMND_MQTTCLIENT "\":\"%s\",\"" D_CMND_MQTTUSER "\":\"%s\",\"MqttType\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d}}"),
- Settings.mqtt_host, Settings.mqtt_port, Settings.mqtt_client, mqtt_client, Settings.mqtt_user, MqttLibraryType(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS6_MQTT "\":{\"" D_CMND_MQTTHOST "\":\"%s\",\"" D_CMND_MQTTPORT "\":%d,\"" D_CMND_MQTTCLIENT D_JSON_MASK "\":\"%s\",\"" D_CMND_MQTTCLIENT "\":\"%s\",\"" D_CMND_MQTTUSER "\":\"%s\",\"MqttType\":%d,\"" D_JSON_MQTT_COUNT "\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d}}"),
+ Settings.mqtt_host, Settings.mqtt_port, Settings.mqtt_client, mqtt_client, Settings.mqtt_user, MqttLibraryType(), MqttConnectCount(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "6"));
}
@@ -1775,8 +1775,8 @@ void MqttShowState(void)
MqttShowPWMState();
}
- snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_LINK_DOWN "\":%d}}"),
- mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkDown());
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_LINK_COUNT "\":%d}}"),
+ mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkCount());
}
bool MqttShowSensor(void)
diff --git a/sonoff/support_wifi.ino b/sonoff/support_wifi.ino
index 138768138..ba3f81ac8 100644
--- a/sonoff/support_wifi.ino
+++ b/sonoff/support_wifi.ino
@@ -49,7 +49,7 @@ using namespace axTLS;
*/
#include // Wifi, MQTT, Ota, WifiManager
-uint32_t wifi_link_down = 0;
+uint16_t wifi_link_count = 0;
uint8_t wifi_counter;
uint8_t wifi_retry_init;
uint8_t wifi_retry;
@@ -341,9 +341,9 @@ void WifiBeginAfterScan()
}
}
-uint32_t WifiLinkDown()
+uint16_t WifiLinkCount()
{
- return wifi_link_down;
+ return wifi_link_count;
}
void WifiSetState(uint8_t state)
@@ -351,9 +351,9 @@ void WifiSetState(uint8_t state)
if (state == global_state.wifi_down) {
if (state) {
rules_flag.wifi_connected = 1;
+ wifi_link_count++;
} else {
rules_flag.wifi_disconnected = 1;
- wifi_link_down++;
}
}
global_state.wifi_down = state ^1;
diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino
index 64afb0ebd..fa681e309 100644
--- a/sonoff/xdrv_02_mqtt.ino
+++ b/sonoff/xdrv_02_mqtt.ino
@@ -73,6 +73,7 @@ const char kMqttCommands[] PROGMEM =
D_CMND_MQTTUSER "|" D_CMND_MQTTPASSWORD "|" D_CMND_FULLTOPIC "|" D_CMND_PREFIX "|" D_CMND_GROUPTOPIC "|" D_CMND_TOPIC "|" D_CMND_PUBLISH "|"
D_CMND_BUTTONTOPIC "|" D_CMND_SWITCHTOPIC "|" D_CMND_BUTTONRETAIN "|" D_CMND_SWITCHRETAIN "|" D_CMND_POWERRETAIN "|" D_CMND_SENSORRETAIN ;
+uint16_t mqtt_connect_count = 0; // MQTT re-connect count
uint16_t mqtt_retry_counter = 1; // MQTT connection retry counter
uint8_t mqtt_initial_connection_state = 2; // MQTT connection messages state
bool mqtt_connected = false; // MQTT virtual connection status
@@ -379,6 +380,11 @@ void MqttPublishPowerBlinkState(uint8_t device)
/*********************************************************************************************/
+uint16_t MqttConnectCount()
+{
+ return mqtt_connect_count;
+}
+
void MqttDisconnected(int state)
{
mqtt_connected = false;
@@ -398,6 +404,7 @@ void MqttConnected(void)
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_CONNECTED));
mqtt_connected = true;
mqtt_retry_counter = 0;
+ mqtt_connect_count++;
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(D_ONLINE));
From 3c3b5bb8ca1eaaa1684b6c042326a8fa2fdd9eb0 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Mon, 18 Feb 2019 18:02:22 +0100
Subject: [PATCH 49/68] Add property Downtime
Add property Downtime to state and status 11 message representing the duration of wifi connection loss
---
sonoff/_changelog.ino | 1 +
sonoff/i18n.h | 1 +
sonoff/sonoff.ino | 4 ++--
sonoff/support_rtc.ino | 52 ++++++++++++++++++++++-------------------
sonoff/support_wifi.ino | 11 ++++++++-
5 files changed, 42 insertions(+), 27 deletions(-)
diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index ad30eb7f7..a08bea0fc 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -7,6 +7,7 @@
* Remove command SetOption62 as it's functionality is replaced by user changing the device template (#5255)
* Add property LinkCount to state and status 11 message representing number of Wifi Link re-connections
* Add property MqttCount to status 6 message representing number of Mqtt re-connections
+ * Add property Downtime to state and status 11 message representing the duration of wifi connection loss
*
* 6.4.1.16 20190211
* Initial support for online template change using command Template or GUI Configure Other (#5177)
diff --git a/sonoff/i18n.h b/sonoff/i18n.h
index d2e15e475..7340a3484 100644
--- a/sonoff/i18n.h
+++ b/sonoff/i18n.h
@@ -54,6 +54,7 @@
#define D_JSON_DISTANCE "Distance"
#define D_JSON_DNSSERVER "DNSServer"
#define D_JSON_DONE "Done"
+#define D_JSON_DOWNTIME "Downtime"
#define D_JSON_ECO2 "eCO2"
#define D_JSON_EMPTY "Empty"
#define D_JSON_ENDDST "EndDST" // End Daylight Savings Time
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 26198507b..e54c23260 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1775,8 +1775,8 @@ void MqttShowState(void)
MqttShowPWMState();
}
- snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_LINK_COUNT "\":%d}}"),
- mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkCount());
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_LINK_COUNT "\":%d,\"" D_JSON_DOWNTIME "\":\"%s\"}}"),
+ mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkCount(), WifiDowntime().c_str());
}
bool MqttShowSensor(void)
diff --git a/sonoff/support_rtc.ino b/sonoff/support_rtc.ino
index 12a4d89ec..5c9f9e2b4 100644
--- a/sonoff/support_rtc.ino
+++ b/sonoff/support_rtc.ino
@@ -87,6 +87,23 @@ String GetTimeZone(void)
return String(tz); // -03:45
}
+String GetDuration(uint32_t time)
+{
+ char dt[16];
+
+ TIME_T ut;
+ BreakTime(time, ut);
+
+ // "P128DT14H35M44S" - ISO8601:2004 - https://en.wikipedia.org/wiki/ISO_8601 Durations
+// snprintf_P(dt, sizeof(dt), PSTR("P%dDT%02dH%02dM%02dS"), ut.days, ut.hour, ut.minute, ut.second);
+
+ // "128 14:35:44" - OpenVMS
+ // "128T14:35:44" - Tasmota
+ snprintf_P(dt, sizeof(dt), PSTR("%dT%02d:%02d:%02d"), ut.days, ut.hour, ut.minute, ut.second);
+
+ return String(dt); // 128T14:35:44
+}
+
String GetDT(uint32_t time)
{
// "2017-03-07T11:08:02" - ISO8601:2004
@@ -155,37 +172,24 @@ String GetTime(int type)
return String(stime); // Thu Nov 01 11:41:02 2018
}
+uint32_t UpTime(void)
+{
+ if (restart_time) {
+ return utc_time - restart_time;
+ } else {
+ return uptime;
+ }
+}
+
String GetUptime(void)
{
- char dt[16];
-
- TIME_T ut;
-
- if (restart_time) {
- BreakTime(utc_time - restart_time, ut);
- } else {
- BreakTime(uptime, ut);
- }
-
- // "P128DT14H35M44S" - ISO8601:2004 - https://en.wikipedia.org/wiki/ISO_8601 Durations
-// snprintf_P(dt, sizeof(dt), PSTR("P%dDT%02dH%02dM%02dS"), ut.days, ut.hour, ut.minute, ut.second);
-
- // "128 14:35:44" - OpenVMS
- // "128T14:35:44" - Tasmota
- snprintf_P(dt, sizeof(dt), PSTR("%dT%02d:%02d:%02d"), ut.days, ut.hour, ut.minute, ut.second);
-
- return String(dt); // 128T14:35:44
+ return GetDuration(UpTime());
}
uint32_t GetMinutesUptime(void)
{
TIME_T ut;
-
- if (restart_time) {
- BreakTime(utc_time - restart_time, ut);
- } else {
- BreakTime(uptime, ut);
- }
+ BreakTime(UpTime(), ut);
return (ut.days *1440) + (ut.hour *60) + ut.minute;
}
diff --git a/sonoff/support_wifi.ino b/sonoff/support_wifi.ino
index ba3f81ac8..c394005a1 100644
--- a/sonoff/support_wifi.ino
+++ b/sonoff/support_wifi.ino
@@ -49,7 +49,9 @@ using namespace axTLS;
*/
#include // Wifi, MQTT, Ota, WifiManager
-uint16_t wifi_link_count = 0;
+uint32_t wifi_last_event = 0; // Last wifi connection event
+uint32_t wifi_downtime = 0; // Wifi down duration
+uint16_t wifi_link_count = 0; // Number of wifi re-connect
uint8_t wifi_counter;
uint8_t wifi_retry_init;
uint8_t wifi_retry;
@@ -346,14 +348,21 @@ uint16_t WifiLinkCount()
return wifi_link_count;
}
+String WifiDowntime()
+{
+ return GetDuration(wifi_downtime);
+}
+
void WifiSetState(uint8_t state)
{
if (state == global_state.wifi_down) {
if (state) {
rules_flag.wifi_connected = 1;
wifi_link_count++;
+ wifi_downtime += UpTime() - wifi_last_event;
} else {
rules_flag.wifi_disconnected = 1;
+ wifi_last_event = UpTime();
}
}
global_state.wifi_down = state ^1;
From 1da8f94a05262f6e0878b9f619d24eac08e349fe Mon Sep 17 00:00:00 2001
From: andrethomas
Date: Mon, 18 Feb 2019 21:52:22 +0200
Subject: [PATCH 50/68] Introduce Reset 6
---
sonoff/sonoff.ino | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index e54c23260..058631a15 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1309,7 +1309,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
case 2:
case 3:
case 4:
- case 5:
+ case 5 ... 6:
restart_flag = 210 + payload;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RESET "\":\"" D_JSON_ERASE ", " D_JSON_RESET_AND_RESTARTING "\"}"));
break;
@@ -2084,14 +2084,33 @@ void Every250mSeconds(void)
}
}
if (restart_flag && (backlog_pointer == backlog_index)) {
- if ((214 == restart_flag) || (215 == restart_flag)) {
+ if ((214 == restart_flag) || (215 == restart_flag) || (216 == restart_flag)) {
char storage[sizeof(Settings.sta_ssid) + sizeof(Settings.sta_pwd)];
+ char storage_mqtt_host[sizeof(Settings.mqtt_host)];
+ uint16_t storage_mqtt_port;
+ char storage_mqtt_user[sizeof(Settings.mqtt_user)];
+ char storage_mqtt_pwd[sizeof(Settings.mqtt_pwd)];
+ char storage_mqtt_topic[sizeof(Settings.mqtt_topic)];
memcpy(storage, Settings.sta_ssid, sizeof(storage)); // Backup current SSIDs and Passwords
- if (215 == restart_flag) {
+ if (216 == restart_flag) {
+ memcpy(storage_mqtt_host, Settings.mqtt_host, sizeof(Settings.mqtt_host));
+ storage_mqtt_port = Settings.mqtt_port;
+ memcpy(storage_mqtt_user, Settings.mqtt_user, sizeof(Settings.mqtt_user));
+ memcpy(storage_mqtt_pwd, Settings.mqtt_pwd, sizeof(Settings.mqtt_pwd));
+ memcpy(storage_mqtt_topic, Settings.mqtt_topic, sizeof(Settings.mqtt_topic));
+ }
+ if ((215 == restart_flag) || (216 == restart_flag)) {
SettingsErase(0); // Erase all flash from program end to end of physical flash
}
SettingsDefault();
memcpy(Settings.sta_ssid, storage, sizeof(storage)); // Restore current SSIDs and Passwords
+ if (216 == restart_flag) { // Restore the mqtt host, port, username and password
+ memcpy(Settings.mqtt_host, storage_mqtt_host, sizeof(Settings.mqtt_host));
+ Settings.mqtt_port = storage_mqtt_port;
+ memcpy(Settings.mqtt_user, storage_mqtt_user, sizeof(Settings.mqtt_user));
+ memcpy(Settings.mqtt_pwd, storage_mqtt_pwd, sizeof(Settings.mqtt_pwd));
+ memcpy(Settings.mqtt_topic, storage_mqtt_topic, sizeof(Settings.mqtt_topic));
+ }
restart_flag = 2;
}
else if (213 == restart_flag) {
From 32c1e2d13c9b6fc28a7a5fd80e0a5d1fdb614b03 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Tue, 19 Feb 2019 10:48:19 +0100
Subject: [PATCH 51/68] Tuning uptime and add utctime
Tuning uptime and add utctime
---
sonoff/sonoff.ino | 5 +----
sonoff/support_rtc.ino | 18 ++++++++++--------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 058631a15..55d218456 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1306,10 +1306,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
restart_flag = 211;
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command , D_JSON_RESET_AND_RESTARTING);
break;
- case 2:
- case 3:
- case 4:
- case 5 ... 6:
+ case 2 ... 6:
restart_flag = 210 + payload;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RESET "\":\"" D_JSON_ERASE ", " D_JSON_RESET_AND_RESTARTING "\"}"));
break;
diff --git a/sonoff/support_rtc.ino b/sonoff/support_rtc.ino
index 5c9f9e2b4..e13dd540e 100644
--- a/sonoff/support_rtc.ino
+++ b/sonoff/support_rtc.ino
@@ -181,19 +181,16 @@ uint32_t UpTime(void)
}
}
+uint32_t GetMinutesUptime(void)
+{
+ return (UpTime() / 60);
+}
+
String GetUptime(void)
{
return GetDuration(UpTime());
}
-uint32_t GetMinutesUptime(void)
-{
- TIME_T ut;
- BreakTime(UpTime(), ut);
-
- return (ut.days *1440) + (ut.hour *60) + ut.minute;
-}
-
uint32_t GetMinutesPastMidnight(void)
{
uint32_t minutes = 0;
@@ -326,6 +323,11 @@ uint32_t RuleToTime(TimeRule r, int yr)
return t;
}
+uint32_t UtcTime(void)
+{
+ return utc_time;
+}
+
uint32_t LocalTime(void)
{
return local_time;
From 06c97c4e1954c7243493768b84bb7952eea0b158 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Tue, 19 Feb 2019 12:51:38 +0100
Subject: [PATCH 52/68] Fix command WebSend
Fix command WebSend intermittent results (#5273)
---
sonoff/_changelog.ino | 1 +
sonoff/xdrv_01_webserver.ino | 89 +++++++++++++++++-------------------
2 files changed, 43 insertions(+), 47 deletions(-)
diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index a08bea0fc..0549b2576 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -8,6 +8,7 @@
* Add property LinkCount to state and status 11 message representing number of Wifi Link re-connections
* Add property MqttCount to status 6 message representing number of Mqtt re-connections
* Add property Downtime to state and status 11 message representing the duration of wifi connection loss
+ * Fix command WebSend intermittent results (#5273)
*
* 6.4.1.16 20190211
* Initial support for online template change using command Template or GUI Configure Other (#5177)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index c78a47c57..46b6ca6eb 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -2146,23 +2146,22 @@ String UrlEncode(const String& text)
int WebSend(char *buffer)
{
- /* [sonoff] POWER1 ON --> Sends http://sonoff/cm?cmnd=POWER1 ON
- * [192.168.178.86:80,admin:joker] POWER1 ON --> Sends http://hostname:80/cm?user=admin&password=joker&cmnd=POWER1 ON
- * [sonoff] /any/link/starting/with/a/slash.php?log=123 --> Sends http://sonoff/any/link/starting/with/a/slash.php?log=123
- * [sonoff,admin:joker] /any/link/starting/with/a/slash.php?log=123 --> Sends http://sonoff/any/link/starting/with/a/slash.php?log=123
- */
+ // [sonoff] POWER1 ON --> Sends http://sonoff/cm?cmnd=POWER1 ON
+ // [192.168.178.86:80,admin:joker] POWER1 ON --> Sends http://hostname:80/cm?user=admin&password=joker&cmnd=POWER1 ON
+ // [sonoff] /any/link/starting/with/a/slash.php?log=123 --> Sends http://sonoff/any/link/starting/with/a/slash.php?log=123
+ // [sonoff,admin:joker] /any/link/starting/with/a/slash.php?log=123 --> Sends http://sonoff/any/link/starting/with/a/slash.php?log=123
char *host;
char *port;
char *user;
char *password;
char *command;
- uint16_t nport = 80;
int status = 1; // Wrong parameters
// buffer = | [ 192.168.178.86 : 80 , admin : joker ] POWER1 ON |
host = strtok_r(buffer, "]", &command); // host = | [ 192.168.178.86 : 80 , admin : joker |, command = | POWER1 ON |
if (host && command) {
+ String url = F("http:"); // url = |http:|
host = Trim(host); // host = |[ 192.168.178.86 : 80 , admin : joker|
host++; // host = | 192.168.178.86 : 80 , admin : joker| - Skip [
host = strtok_r(host, ",", &user); // host = | 192.168.178.86 : 80 |, user = | admin : joker|
@@ -2170,66 +2169,62 @@ int WebSend(char *buffer)
host = Trim(host); // host = |192.168.178.86|
if (port) {
port = Trim(port); // port = |80|
- nport = atoi(port);
+ url += port; // url = |http:80|
}
+ url += F("//"); // url = |http://| or |http:80//|
+ url += host; // url = |http://192.168.178.86|
+
if (user) {
user = strtok_r(user, ":", &password); // user = | admin |, password = | joker|
user = Trim(user); // user = |admin|
if (password) { password = Trim(password); } // password = |joker|
}
+
command = Trim(command); // command = |POWER1 ON| or |/any/link/starting/with/a/slash.php?log=123|
-
- String nuri = "";
if (command[0] != '/') {
- nuri = "/cm?";
+ url += F("/cm?"); // url = |http://192.168.178.86/cm?|
if (user && password) {
- nuri += F("user=");
- nuri += user;
- nuri += F("&password=");
- nuri += password;
- nuri += F("&");
+ url += F("user="); // url = |http://192.168.178.86/cm?user=|
+ url += user; // url = |http://192.168.178.86/cm?user=admin|
+ url += F("&password="); // url = |http://192.168.178.86/cm?user=admin&password=|
+ url += password; // url = |http://192.168.178.86/cm?user=admin&password=joker|
+ url += F("&"); // url = |http://192.168.178.86/cm?user=admin&password=joker&|
}
- nuri += F("cmnd=");
+ url += F("cmnd="); // url = |http://192.168.178.86/cm?cmnd=| or |http://192.168.178.86/cm?user=admin&password=joker&cmnd=|
}
- nuri += command;
- String uri = UrlEncode(nuri);
+ url += command; // url = |http://192.168.178.86/cm?cmnd=POWER1 ON|
- IPAddress host_ip;
- if (WiFi.hostByName(host, host_ip)) {
- WiFiClient client;
-
- bool connected = false;
- uint8_t retry = 2;
- while ((retry > 0) && !connected) {
- --retry;
- connected = client.connect(host_ip, nport);
- if (connected) break;
- }
-
- if (connected) {
- String url = F("GET ");
- url += uri;
- url += F(" HTTP/1.1\r\nHost: ");
-// url += IPAddress(host_ip).toString();
- url += host; // https://tools.ietf.org/html/rfc7230#section-5.4 (#4331)
- if (port) {
- url += F(":");
- url += port;
- }
- url += F("\r\nConnection: close\r\n\r\n");
-
-//snprintf_P(log_data, sizeof(log_data), PSTR("DBG: Url |%s|"), url.c_str());
+//snprintf_P(log_data, sizeof(log_data), PSTR("DBG: Uri |%s|"), url.c_str());
//AddLog(LOG_LEVEL_DEBUG);
- client.print(url.c_str());
- client.flush();
- client.stop();
+ HTTPClient http;
+ if (http.begin(UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
+ int http_code = http.GET(); // Start connection and send HTTP header
+ if (http_code > 0) { // http_code will be negative on error
+ if (http_code == HTTP_CODE_OK || http_code == HTTP_CODE_MOVED_PERMANENTLY) {
+/*
+ // Return received data to the user - Adds 900+ bytes to the code
+ String result = http.getString(); // File found at server - may need lot of ram or trigger out of memory!
+ uint16_t j = 0;
+ for (uint16_t i = 0; i < result.length(); i++) {
+ char text = result.charAt(i);
+ if (text > 31) { // Remove control characters like linefeed
+ mqtt_data[j] = result.charAt(i);
+ j++;
+ if (j == sizeof(mqtt_data) -2) { break; }
+ }
+ }
+ mqtt_data[j] = '\0';
+ MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_WEBSEND));
+*/
+ }
status = 0; // No error - Done
} else {
status = 2; // Connection failed
}
+ http.end();
} else {
- status = 3; // Host not found
+ status = 3; // Host not found or connection error
}
}
return status;
From 280dd25a8b65aa0f58ec1719ba290ec3d3cd7bcf Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Tue, 19 Feb 2019 14:49:15 +0100
Subject: [PATCH 53/68] Optimize RAM for expression
Optimize RAM for expression and add two more constant variables (#5275)
---
sonoff/support_rtc.ino | 4 +--
sonoff/xdrv_09_timers.ino | 2 +-
sonoff/xdrv_10_rules.ino | 56 +++++++++++++++++++--------------------
3 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/sonoff/support_rtc.ino b/sonoff/support_rtc.ino
index e13dd540e..35f9b61e9 100644
--- a/sonoff/support_rtc.ino
+++ b/sonoff/support_rtc.ino
@@ -181,7 +181,7 @@ uint32_t UpTime(void)
}
}
-uint32_t GetMinutesUptime(void)
+uint32_t MinutesUptime(void)
{
return (UpTime() / 60);
}
@@ -191,7 +191,7 @@ String GetUptime(void)
return GetDuration(UpTime());
}
-uint32_t GetMinutesPastMidnight(void)
+uint32_t MinutesPastMidnight(void)
{
uint32_t minutes = 0;
diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino
index 1b0f480fb..3c3b1f376 100644
--- a/sonoff/xdrv_09_timers.ino
+++ b/sonoff/xdrv_09_timers.ino
@@ -232,7 +232,7 @@ String GetSun(uint8_t dawn)
return String(stime);
}
-uint16_t GetSunMinutes(uint8_t dawn)
+uint16_t SunMinutes(uint8_t dawn)
{
uint8_t hour[2];
uint8_t minute[2];
diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino
index 9603e549b..08c6c362b 100644
--- a/sonoff/xdrv_10_rules.ino
+++ b/sonoff/xdrv_10_rules.ino
@@ -185,11 +185,11 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule)
}
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIME%%"));
if (rule_param.startsWith(stemp)) {
- rule_param = String(GetMinutesPastMidnight());
+ rule_param = String(MinutesPastMidnight());
}
snprintf_P(stemp, sizeof(stemp), PSTR("%%UPTIME%%"));
if (rule_param.startsWith(stemp)) {
- rule_param = String(GetMinutesUptime());
+ rule_param = String(MinutesUptime());
}
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMESTAMP%%"));
if (rule_param.startsWith(stemp)) {
@@ -198,11 +198,11 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule)
#if defined(USE_TIMERS) && defined(USE_SUNRISE)
snprintf_P(stemp, sizeof(stemp), PSTR("%%SUNRISE%%"));
if (rule_param.startsWith(stemp)) {
- rule_param = String(GetSunMinutes(0));
+ rule_param = String(SunMinutes(0));
}
snprintf_P(stemp, sizeof(stemp), PSTR("%%SUNSET%%"));
if (rule_param.startsWith(stemp)) {
- rule_param = String(GetSunMinutes(1));
+ rule_param = String(SunMinutes(1));
}
#endif // USE_TIMERS and USE_SUNRISE
rule_param.toUpperCase();
@@ -347,12 +347,12 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
snprintf_P(stemp, sizeof(stemp), PSTR("%%mem%d%%"), i +1);
commands.replace(stemp, Settings.mems[i]);
}
- commands.replace(F("%time%"), String(GetMinutesPastMidnight()));
- commands.replace(F("%uptime%"), String(GetMinutesUptime()));
+ commands.replace(F("%time%"), String(MinutesPastMidnight()));
+ commands.replace(F("%uptime%"), String(MinutesUptime()));
commands.replace(F("%timestamp%"), GetDateAndTime(DT_LOCAL).c_str());
#if defined(USE_TIMERS) && defined(USE_SUNRISE)
- commands.replace(F("%sunrise%"), String(GetSunMinutes(0)));
- commands.replace(F("%sunset%"), String(GetSunMinutes(1)));
+ commands.replace(F("%sunrise%"), String(SunMinutes(0)));
+ commands.replace(F("%sunset%"), String(SunMinutes(1)));
#endif // USE_TIMERS and USE_SUNRISE
char command[commands.length() +1];
@@ -505,8 +505,8 @@ void RulesEvery50ms(void)
json_event[0] = '\0';
switch (i) {
case 0: strncpy_P(json_event, PSTR("{\"System\":{\"Boot\":1}}"), sizeof(json_event)); break;
- case 1: snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Initialized\":%d}}"), GetMinutesPastMidnight()); break;
- case 2: snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Set\":%d}}"), GetMinutesPastMidnight()); break;
+ case 1: snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Initialized\":%d}}"), MinutesPastMidnight()); break;
+ case 2: snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Set\":%d}}"), MinutesPastMidnight()); break;
case 3: strncpy_P(json_event, PSTR("{\"MQTT\":{\"Connected\":1}}"), sizeof(json_event)); break;
case 4: strncpy_P(json_event, PSTR("{\"MQTT\":{\"Disconnected\":1}}"), sizeof(json_event)); break;
case 5: strncpy_P(json_event, PSTR("{\"WIFI\":{\"Connected\":1}}"), sizeof(json_event)); break;
@@ -549,7 +549,7 @@ void RulesEverySecond(void)
if (RtcTime.valid) {
if ((uptime > 60) && (RtcTime.minute != rules_last_minute)) { // Execute from one minute after restart every minute only once
rules_last_minute = RtcTime.minute;
- snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Minute\":%d}}"), GetMinutesPastMidnight());
+ snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Minute\":%d}}"), MinutesPastMidnight());
RulesProcessEvent(json_event);
}
}
@@ -625,7 +625,7 @@ bool findNextNumber(char * &pNumber, double &value)
*/
bool findNextVariableValue(char * &pVarname, double &value)
{
- bool succeed = false;
+ bool succeed = true;
value = 0;
String sVarName = "";
while (*pVarname) {
@@ -637,32 +637,32 @@ bool findNextVariableValue(char * &pVarname, double &value)
}
}
sVarName.toUpperCase();
- if (sVarName.startsWith("VAR")) {
+ if (sVarName.startsWith(F("VAR"))) {
int index = sVarName.substring(3).toInt();
if (index > 0 && index <= MAX_RULE_VARS) {
value = CharToDouble(vars[index -1]);
- succeed = true;
}
- } else if (sVarName.startsWith("MEM")) {
+ } else if (sVarName.startsWith(F("MEM"))) {
int index = sVarName.substring(3).toInt();
if (index > 0 && index <= MAX_RULE_MEMS) {
value = CharToDouble(Settings.mems[index -1]);
- succeed = true;
}
- } else if (sVarName.equals("TIME")) {
- value = GetMinutesPastMidnight();
- succeed = true;
- } else if (sVarName.equals("UPTIME")) {
- value = GetMinutesUptime();
- succeed = true;
+ } else if (sVarName.equals(F("TIME"))) {
+ value = MinutesPastMidnight();
+ } else if (sVarName.equals(F("UPTIME"))) {
+ value = MinutesUptime();
+ } else if (sVarName.equals(F("UTCTIME"))) {
+ value = UtcTime();
+ } else if (sVarName.equals(F("LOCALTIME"))) {
+ value = LocalTime();
#if defined(USE_TIMERS) && defined(USE_SUNRISE)
- } else if (sVarName.equals("SUNRISE")) {
- value = GetSunMinutes(0);
- succeed = true;
- } else if (sVarName.equals("SUNSET")) {
- value = GetSunMinutes(1);
- succeed = true;
+ } else if (sVarName.equals(F("SUNRISE"))) {
+ value = SunMinutes(0);
+ } else if (sVarName.equals(F("SUNSET"))) {
+ value = SunMinutes(1);
#endif
+ } else {
+ succeed = false;
}
return succeed;
From 51227b1d951476effa4458e3566e31563f6f1312 Mon Sep 17 00:00:00 2001
From: Jason2866
Date: Wed, 20 Feb 2019 21:07:01 +0100
Subject: [PATCH 54/68] Update platformio.ini
---
platformio.ini | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/platformio.ini b/platformio.ini
index f5d958ebf..21816c3ab 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -65,8 +65,8 @@ build_flags = ${esp82xx_defaults.build_flags}
-DVTABLES_IN_FLASH
[core_2_5_0]
-; *** Esp8266 core for Arduino version 2.5.0 release (still not available via platformio)
-platform = https://github.com/Jason2866/platform-espressif8266.git#Tasmota
+; *** Esp8266 core for Arduino version 2.5.0
+platform = espressif8266@2.0.0
build_flags = ${esp82xx_defaults.build_flags}
-Wl,-Teagle.flash.1m.ld
; lwIP 1.4 (Default)
From cfd3f3f4f5dd095e9cc1c294c905b48be2a5e7cc Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Thu, 21 Feb 2019 09:48:58 +0100
Subject: [PATCH 55/68] Fix WebSend compile warning
Fix WebSend compile warning
---
sonoff/xdrv_01_webserver.ino | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 46b6ca6eb..2bdf55248 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -2179,7 +2179,7 @@ int WebSend(char *buffer)
user = Trim(user); // user = |admin|
if (password) { password = Trim(password); } // password = |joker|
}
-
+
command = Trim(command); // command = |POWER1 ON| or |/any/link/starting/with/a/slash.php?log=123|
if (command[0] != '/') {
url += F("/cm?"); // url = |http://192.168.178.86/cm?|
@@ -2197,8 +2197,14 @@ int WebSend(char *buffer)
//snprintf_P(log_data, sizeof(log_data), PSTR("DBG: Uri |%s|"), url.c_str());
//AddLog(LOG_LEVEL_DEBUG);
+#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
HTTPClient http;
if (http.begin(UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
+#else
+ WiFiClient http_client;
+ HTTPClient http;
+ if (http.begin(client, UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
+#endif
int http_code = http.GET(); // Start connection and send HTTP header
if (http_code > 0) { // http_code will be negative on error
if (http_code == HTTP_CODE_OK || http_code == HTTP_CODE_MOVED_PERMANENTLY) {
@@ -2209,8 +2215,7 @@ int WebSend(char *buffer)
for (uint16_t i = 0; i < result.length(); i++) {
char text = result.charAt(i);
if (text > 31) { // Remove control characters like linefeed
- mqtt_data[j] = result.charAt(i);
- j++;
+ mqtt_data[j++] = text;
if (j == sizeof(mqtt_data) -2) { break; }
}
}
@@ -2222,7 +2227,7 @@ int WebSend(char *buffer)
} else {
status = 2; // Connection failed
}
- http.end();
+ http.end(); // Clean up connection data
} else {
status = 3; // Host not found or connection error
}
From 05b02800198a1ef592c0bc6099a6c8cefc239e83 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Thu, 21 Feb 2019 14:31:31 +0100
Subject: [PATCH 56/68] 6.4.1.18 - Fix some exceptions and watchdogs
6.4.1.18 20191221
* Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
---
sonoff/_changelog.ino | 5 ++++-
sonoff/sonoff.ino | 40 ++++++------------------------------
sonoff/sonoff_version.h | 2 +-
sonoff/support.ino | 36 ++++++++++++++++++++++++++++++++
sonoff/xdrv_01_webserver.ino | 2 ++
5 files changed, 49 insertions(+), 36 deletions(-)
diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index 0549b2576..0d4fef299 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -1,4 +1,7 @@
-/* 6.4.1.17 20190214
+/* 6.4.1.18 20191221
+ * Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
+ *
+ * 6.4.1.17 20190214
* Change template update by removing possibility to add user module config keeping template as defined (#5222)
* Fix regression from 6.4.1.16 where GPIO9 and GPIO10 connected devices did not work (#5197)
* Fix GUI wifi password acception starting with asteriks (*) (#5231, #5242)
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 55d218456..39f0d7e0b 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -963,41 +963,12 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
}
}
- else if (data_len > 9) { // Workaround exception if empty JSON like {} - Needs checks
- StaticJsonBuffer<350> jb; // 331 from https://arduinojson.org/v5/assistant/
- JsonObject& obj = jb.parseObject(dataBuf);
- if (!obj.success()) {
+ else if (data_len > 9) { // Workaround exception if empty JSON like {} - Needs checks
+ if (JsonTemplate(dataBuf)) { // Free 336 bytes StaticJsonBuffer stack space by moving code to function
+ if (USER_MODULE == Settings.module) { restart_flag = 2; }
+ } else {
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_INVALID_JSON);
error = true;
- } else {
- // All parameters are optional allowing for partial changes
- const char* name = obj[D_JSON_NAME];
- if (name != nullptr) {
- strlcpy(Settings.user_template.name, name, sizeof(Settings.user_template.name));
- }
- if (obj[D_JSON_GPIO].success()) {
- for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
- Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0;
- }
- }
- if (obj[D_JSON_FLAG].success()) {
- uint8_t flag = obj[D_JSON_FLAG] | 0;
- memcpy(&Settings.user_template.flag, &flag, sizeof(gpio_flag));
- }
- if (obj[D_JSON_BASE].success()) {
- uint8_t base = obj[D_JSON_BASE];
- if ((0 == base) || (base >= MAXMODULE)) { base = 17; } else { base--; }
- Settings.user_template_base = base; // Default WEMOS
- }
-
- // Validate GPIO
-// for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
- // For now do not allow non-user configurable GPIO
-// if ((Settings.user_template.gp.io[i] > GPIO_FIX_START) && (Settings.user_template.gp.io[i] < GPIO_USER)) {
-// Settings.user_template.gp.io[i] = GPIO_NONE;
-// };
-// }
- if (USER_MODULE == Settings.module) { restart_flag = 2; }
}
}
if (!error) { TemplateJson(); }
@@ -2223,7 +2194,8 @@ void ArduinoOTAInit(void)
void SerialInput(void)
{
while (Serial.available()) {
- yield();
+// yield();
+ delay(0);
serial_in_byte = Serial.read();
/*-------------------------------------------------------------------------------------------*\
diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h
index 3816029fd..bba08f9de 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 0x06040111
+#define VERSION 0x06040112
#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"
diff --git a/sonoff/support.ino b/sonoff/support.ino
index d37185e3f..113968974 100644
--- a/sonoff/support.ino
+++ b/sonoff/support.ino
@@ -845,6 +845,42 @@ bool GetUsedInModule(uint8_t val, uint8_t *arr)
return false;
}
+bool JsonTemplate(const char* dataBuf)
+{
+ StaticJsonBuffer<350> jb; // 331 from https://arduinojson.org/v5/assistant/
+ JsonObject& obj = jb.parseObject(dataBuf);
+ if (!obj.success()) { return false; }
+
+ // All parameters are optional allowing for partial changes
+ const char* name = obj[D_JSON_NAME];
+ if (name != nullptr) {
+ strlcpy(Settings.user_template.name, name, sizeof(Settings.user_template.name));
+ }
+ if (obj[D_JSON_GPIO].success()) {
+ for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
+ Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0;
+ }
+ }
+ if (obj[D_JSON_FLAG].success()) {
+ uint8_t flag = obj[D_JSON_FLAG] | 0;
+ memcpy(&Settings.user_template.flag, &flag, sizeof(gpio_flag));
+ }
+ if (obj[D_JSON_BASE].success()) {
+ uint8_t base = obj[D_JSON_BASE];
+ if ((0 == base) || (base >= MAXMODULE)) { base = 17; } else { base--; }
+ Settings.user_template_base = base; // Default WEMOS
+ }
+
+ // Validate GPIO
+// for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
+ // For now do not allow non-user configurable GPIO
+// if ((Settings.user_template.gp.io[i] > GPIO_FIX_START) && (Settings.user_template.gp.io[i] < GPIO_USER)) {
+// Settings.user_template.gp.io[i] = GPIO_NONE;
+// };
+// }
+ return true;
+}
+
void TemplateJson()
{
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), Settings.user_template.name);
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 2bdf55248..e8aab33db 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -1968,6 +1968,7 @@ void HandleHttpCommand(void)
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
if (message.length() > 1) { message += F(","); }
size_t JSONlen = len - (JSON - tmp);
+ if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); }
strlcpy(mqtt_data, JSON +1, JSONlen -2);
message += mqtt_data;
}
@@ -2047,6 +2048,7 @@ void HandleAjaxConsoleRefresh(void)
} else {
cflg = true;
}
+ if (len > sizeof(mqtt_data) -2) { len = sizeof(mqtt_data); }
strlcpy(mqtt_data, tmp, len);
message += mqtt_data; // mqtt_data used as scratch space
}
From 95da493325fbad0be9e88f950f6bc0c3a51c90e6 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Thu, 21 Feb 2019 14:56:39 +0100
Subject: [PATCH 57/68] Update xdrv_01_webserver.ino
Fix compile error
---
sonoff/xdrv_01_webserver.ino | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index e8aab33db..a056c48ef 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -2205,7 +2205,7 @@ int WebSend(char *buffer)
#else
WiFiClient http_client;
HTTPClient http;
- if (http.begin(client, UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
+ if (http.begin(http_client, UrlEncode(url))) { // UrlEncode(url) = |http://192.168.178.86/cm?cmnd=POWER1%20ON|
#endif
int http_code = http.GET(); // Start connection and send HTTP header
if (http_code > 0) { // http_code will be negative on error
From eb08bb07ee2c37aaa1a73b70746655cc0ec9ecef Mon Sep 17 00:00:00 2001
From: Norbert Richter
Date: Thu, 21 Feb 2019 15:37:46 +0100
Subject: [PATCH 58/68] decode-config.py: adapt settings
- remove SetOption62 (no_pullup)
- remove obsolete Tasmota command converter
---
tools/decode-config.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/decode-config.py b/tools/decode-config.py
index 642c31954..0b76ece85 100755
--- a/tools/decode-config.py
+++ b/tools/decode-config.py
@@ -866,11 +866,15 @@ Setting_6_4_1_16.update({
'pullup': ('B', (0x73C,1,1), (None, None, ('Management', None)) ),
}, 0x73C, (None, None, ('Management', None))
),
- }, 0x720, (None, None, ('Management', '"Template GPIO:{}".format(@["user_template"]["gp"][0])'))
+ }, 0x720, (None, None, ('Management', None))
),
})
# ======================================================================
+Setting_6_4_1_17 = copy.deepcopy(Setting_6_4_1_16)
+Setting_6_4_1_17['flag3'][0].pop('no_pullup',None)
+# ======================================================================
Settings = [
+ (0x6040111, 0xe00, Setting_6_4_1_17),
(0x6040110, 0xe00, Setting_6_4_1_16),
(0x604010D, 0xe00, Setting_6_4_1_13),
(0x604010B, 0xe00, Setting_6_4_1_11),
From 3c58f5b7b9a3fe937f6365f4a2d461b1a267693e Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 15:53:29 +0100
Subject: [PATCH 59/68] Add password validation to password command
---
sonoff/sonoff.ino | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 39f0d7e0b..24a3d5723 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1144,7 +1144,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.sta_ssid[index -1]);
}
else if ((CMND_PASSWORD == command_code) && (index > 0) && (index <= 2)) {
- if ((data_len > 0) && (data_len < sizeof(Settings.sta_pwd[0]))) {
+ if ((data_len > 4 || SC_CLEAR == Shortcut(dataBuf) || SC_DEFAULT == Shortcut(dataBuf)) && (data_len < sizeof(Settings.sta_pwd[0]))) {
strlcpy(Settings.sta_pwd[index -1], (SC_CLEAR == Shortcut(dataBuf)) ? "" : (SC_DEFAULT == Shortcut(dataBuf)) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0]));
Settings.sta_active = index -1;
restart_flag = 2;
From e035a3253a0b23fb69dd3466ce633c79da1517a9 Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 15:58:37 +0100
Subject: [PATCH 60/68] Add password validation to WebUI
---
sonoff/xdrv_01_webserver.ino | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index a056c48ef..8c9f373a8 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -1236,9 +1236,9 @@ void WifiSaveSettings(void)
WebGetArg("s2", tmp, sizeof(tmp));
strlcpy(Settings.sta_ssid[1], (!strlen(tmp)) ? STA_SSID2 : tmp, sizeof(Settings.sta_ssid[1]));
WebGetArg("p1", tmp, sizeof(tmp));
- strlcpy(Settings.sta_pwd[0], (!strlen(tmp)) ? "" : (!strcmp(tmp,D_ASTERISK_PWD)) ? Settings.sta_pwd[0] : tmp, sizeof(Settings.sta_pwd[0]));
+ strlcpy(Settings.sta_pwd[0], (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? Settings.sta_pwd[0] : tmp, sizeof(Settings.sta_pwd[0]));
WebGetArg("p2", tmp, sizeof(tmp));
- strlcpy(Settings.sta_pwd[1], (!strlen(tmp)) ? "" : (!strcmp(tmp,D_ASTERISK_PWD)) ? Settings.sta_pwd[1] : tmp, sizeof(Settings.sta_pwd[1]));
+ strlcpy(Settings.sta_pwd[1], (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? Settings.sta_pwd[1] : tmp, sizeof(Settings.sta_pwd[1]));
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_CMND_HOSTNAME " %s, " D_CMND_SSID "1 %s, " D_CMND_SSID "2 %s"),
Settings.hostname, Settings.sta_ssid[0], Settings.sta_ssid[1]);
AddLog(LOG_LEVEL_INFO);
@@ -2181,7 +2181,7 @@ int WebSend(char *buffer)
user = Trim(user); // user = |admin|
if (password) { password = Trim(password); } // password = |joker|
}
-
+
command = Trim(command); // command = |POWER1 ON| or |/any/link/starting/with/a/slash.php?log=123|
if (command[0] != '/') {
url += F("/cm?"); // url = |http://192.168.178.86/cm?|
From 4993d16ecb1c19a2c182b6405297c51efc2a5335 Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 17:49:11 +0100
Subject: [PATCH 61/68] Implement WifiConfig 7
---
sonoff/sonoff.h | 2 +-
sonoff/support_wifi.ino | 4 +-
sonoff/xdrv_01_webserver.ino | 223 +++++++++++++++++++----------------
3 files changed, 124 insertions(+), 105 deletions(-)
diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h
index 790059450..c86733621 100644
--- a/sonoff/sonoff.h
+++ b/sonoff/sonoff.h
@@ -212,7 +212,7 @@ enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_ENERGY };
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
-enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, MAX_WIFI_OPTION};
+enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY, MAX_WIFI_OPTION};
enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, MAX_SWITCH_OPTION};
diff --git a/sonoff/support_wifi.ino b/sonoff/support_wifi.ino
index c394005a1..23f4b20c1 100644
--- a/sonoff/support_wifi.ino
+++ b/sonoff/support_wifi.ino
@@ -174,9 +174,9 @@ void WifiConfig(uint8_t type)
}
#endif // USE_WPS
#ifdef USE_WEBSERVER
- else if (WIFI_MANAGER == wifi_config_type) {
+ else if (WIFI_MANAGER == wifi_config_type || WIFI_MANAGER_RESET_ONLY == wifi_config_type) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_2_WIFIMANAGER " " D_ACTIVE_FOR_3_MINUTES));
- WifiManagerBegin();
+ WifiManagerBegin(WIFI_MANAGER_RESET_ONLY == wifi_config_type);
}
#endif // USE_WEBSERVER
}
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index a056c48ef..5d975ac1b 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -294,12 +294,14 @@ const char HTTP_BTN_RSTRT[] PROGMEM =
const char HTTP_BTN_MENU_MODULE[] PROGMEM =
""
"";
+const char HTTP_BTN_RESET[] PROGMEM =
+ " "
+ "";
const char HTTP_BTN_MENU4[] PROGMEM =
""
""
- ""
- " "
- ""
+ "";
+const char HTTP_BTN_MENU5[] PROGMEM =
""
"";
const char HTTP_BTN_MAIN[] PROGMEM =
@@ -437,7 +439,7 @@ const char HDR_CTYPE_JSON[] PROGMEM = "application/json";
const char HDR_CTYPE_STREAM[] PROGMEM = "application/octet-stream";
#define DNS_PORT 53
-enum HttpOptions {HTTP_OFF, HTTP_USER, HTTP_ADMIN, HTTP_MANAGER};
+enum HttpOptions {HTTP_OFF, HTTP_USER, HTTP_ADMIN, HTTP_MANAGER, HTTP_MANAGER_RESET_ONLY};
DNSServer *DnsServer;
ESP8266WebServer *WebServer;
@@ -460,6 +462,10 @@ static void WebGetArg(const char* arg, char* out, size_t max)
// out[max-1] = '\0'; // Ensure terminating NUL
}
+static bool WifiIsInManagerMode(){
+ return (HTTP_MANAGER == webserver_state || HTTP_MANAGER_RESET_ONLY == webserver_state);
+}
+
void ShowWebSource(int source)
{
if ((source > 0) && (source < SRC_MAX)) {
@@ -480,34 +486,39 @@ void StartWebserver(int type, IPAddress ipweb)
if (!Settings.web_refresh) { Settings.web_refresh = HTTP_REFRESH_TIME; }
if (!webserver_state) {
if (!WebServer) {
- WebServer = new ESP8266WebServer((HTTP_MANAGER==type) ? 80 : WEB_PORT);
+ WebServer = new ESP8266WebServer((HTTP_MANAGER==type || HTTP_MANAGER_RESET_ONLY == type) ? 80 : WEB_PORT);
WebServer->on("/", HandleRoot);
- WebServer->on("/up", HandleUpgradeFirmware);
- WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA
- WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop);
- WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest);
- WebServer->on("/cs", HandleConsole);
- WebServer->on("/ax", HandleAjaxConsoleRefresh);
- WebServer->on("/ay", HandleAjaxStatusRefresh);
- WebServer->on("/cm", HandleHttpCommand);
WebServer->onNotFound(HandleNotFound);
#ifndef FIRMWARE_MINIMAL
- WebServer->on("/cn", HandleConfiguration);
- WebServer->on("/md", HandleModuleConfiguration);
- WebServer->on("/wi", HandleWifiConfiguration);
- WebServer->on("/lg", HandleLoggingConfiguration);
- WebServer->on("/tp", HandleTemplateConfiguration);
- WebServer->on("/co", HandleOtherConfiguration);
- WebServer->on("/dl", HandleBackupConfiguration);
- WebServer->on("/rs", HandleRestoreConfiguration);
WebServer->on("/rt", HandleResetConfiguration);
- WebServer->on("/in", HandleInformation);
+#endif // FIRMWARE_MINIMAL
+ if(HTTP_MANAGER_RESET_ONLY != type){
+ WebServer->on("/up", HandleUpgradeFirmware);
+ WebServer->on("/u1", HandleUpgradeFirmwareStart); // OTA
+ WebServer->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop);
+ WebServer->on("/u2", HTTP_OPTIONS, HandlePreflightRequest);
+ WebServer->on("/cs", HandleConsole);
+ WebServer->on("/ax", HandleAjaxConsoleRefresh);
+ WebServer->on("/ay", HandleAjaxStatusRefresh);
+ WebServer->on("/cm", HandleHttpCommand);
+#ifndef FIRMWARE_MINIMAL
+ WebServer->on("/cn", HandleConfiguration);
+ WebServer->on("/md", HandleModuleConfiguration);
+ WebServer->on("/wi", HandleWifiConfiguration);
+ WebServer->on("/lg", HandleLoggingConfiguration);
+ WebServer->on("/tp", HandleTemplateConfiguration);
+ WebServer->on("/co", HandleOtherConfiguration);
+ WebServer->on("/dl", HandleBackupConfiguration);
+ WebServer->on("/rs", HandleRestoreConfiguration);
+ WebServer->on("/rt", HandleResetConfiguration);
+ WebServer->on("/in", HandleInformation);
#ifdef USE_EMULATION
- HueWemoAddHandlers();
+ HueWemoAddHandlers();
#endif // USE_EMULATION
- XdrvCall(FUNC_WEB_ADD_HANDLER);
- XsnsCall(FUNC_WEB_ADD_HANDLER);
+ XdrvCall(FUNC_WEB_ADD_HANDLER);
+ XsnsCall(FUNC_WEB_ADD_HANDLER);
#endif // Not FIRMWARE_MINIMAL
+ }
}
reset_web_log_flag = false;
WebServer->begin(); // Web server start
@@ -529,7 +540,7 @@ void StopWebserver(void)
}
}
-void WifiManagerBegin(void)
+void WifiManagerBegin(bool reset_only)
{
// setup AP
if (!global_state.wifi_down) {
@@ -553,7 +564,7 @@ void WifiManagerBegin(void)
DnsServer->setErrorReplyCode(DNSReplyCode::NoError);
DnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
- StartWebserver(HTTP_MANAGER, WiFi.softAPIP());
+ StartWebserver((reset_only ? HTTP_MANAGER_RESET_ONLY : HTTP_MANAGER), WiFi.softAPIP());
}
void PollDnsWebserver(void)
@@ -576,7 +587,7 @@ void SetHeader(void)
bool WebAuthenticate(void)
{
- if (Settings.web_password[0] != 0) {
+ if (Settings.web_password[0] != 0 && HTTP_MANAGER_RESET_ONLY != webserver_state) {
return WebServer->authenticate(WEB_USERNAME, Settings.web_password);
} else {
return true;
@@ -611,7 +622,7 @@ void ShowPage(String &page, bool auth)
}
page.replace(F("{j}"), info);
- if (HTTP_MANAGER == webserver_state) {
+ if (WifiIsInManagerMode()) {
if (WifiConfigCounter()) {
page.replace(F(""), FPSTR(HTTP_SCRIPT_COUNTER));
page += FPSTR(HTTP_COUNTER);
@@ -690,12 +701,12 @@ void HandleRoot(void)
return;
}
- if (HTTP_MANAGER == webserver_state) {
+ if (WifiIsInManagerMode()) {
#ifndef FIRMWARE_MINIMAL
- if ((Settings.web_password[0] != 0) && !(WebServer->hasArg("USER1")) && !(WebServer->hasArg("PASS1"))) {
+ if ((Settings.web_password[0] != 0) && !(WebServer->hasArg("USER1")) && !(WebServer->hasArg("PASS1")) && HTTP_MANAGER_RESET_ONLY != webserver_state) {
HandleWifiLogin();
} else {
- if (!(Settings.web_password[0] != 0) || ((WebServer->arg("USER1") == WEB_USERNAME ) && (WebServer->arg("PASS1") == Settings.web_password ))) {
+ if (!(Settings.web_password[0] != 0) || ((WebServer->arg("USER1") == WEB_USERNAME ) && (WebServer->arg("PASS1") == Settings.web_password ) || HTTP_MANAGER_RESET_ONLY == webserver_state)) {
HandleWifiConfiguration();
} else {
// wrong user and pass
@@ -874,6 +885,8 @@ void HandleConfiguration(void)
page += String(mqtt_data);
page += FPSTR(HTTP_BTN_MENU4);
+ page += FPSTR(HTTP_BTN_RESET);
+ page += FPSTR(HTTP_BTN_MENU5);
page += FPSTR(HTTP_BTN_MAIN);
ShowPage(page);
}
@@ -1125,7 +1138,7 @@ void HandleWifiConfiguration(void)
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_WIFI);
- if (WebServer->hasArg("save")) {
+ if (WebServer->hasArg("save") && HTTP_MANAGER_RESET_ONLY != webserver_state) {
WifiSaveSettings();
WebRestart(2);
return;
@@ -1136,90 +1149,96 @@ void HandleWifiConfiguration(void)
page += FPSTR(HTTP_SCRIPT_WIFI);
page += FPSTR(HTTP_HEAD_STYLE);
- if (WebServer->hasArg("scan")) {
-#ifdef USE_EMULATION
- UdpDisconnect();
-#endif // USE_EMULATION
- int n = WiFi.scanNetworks();
- AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SCAN_DONE));
- if (0 == n) {
- AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, S_NO_NETWORKS_FOUND);
- page += FPSTR(S_NO_NETWORKS_FOUND);
- page += F(". " D_REFRESH_TO_SCAN_AGAIN ".");
- } else {
- //sort networks
- int indices[n];
- for (int i = 0; i < n; i++) {
- indices[i] = i;
- }
+ if(HTTP_MANAGER_RESET_ONLY != webserver_state){
+ if (WebServer->hasArg("scan")) {
+ #ifdef USE_EMULATION
+ UdpDisconnect();
+ #endif // USE_EMULATION
+ int n = WiFi.scanNetworks();
+ AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SCAN_DONE));
- // RSSI SORT
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
- std::swap(indices[i], indices[j]);
- }
- }
- }
-
- // remove duplicates ( must be RSSI sorted )
- if (remove_duplicate_access_points) {
- String cssid;
+ if (0 == n) {
+ AddLog_P(LOG_LEVEL_DEBUG, S_LOG_WIFI, S_NO_NETWORKS_FOUND);
+ page += FPSTR(S_NO_NETWORKS_FOUND);
+ page += F(". " D_REFRESH_TO_SCAN_AGAIN ".");
+ } else {
+ //sort networks
+ int indices[n];
+ for (int i = 0; i < n; i++) {
+ indices[i] = i;
+ }
+
+ // RSSI SORT
for (int i = 0; i < n; i++) {
- if (-1 == indices[i]) { continue; }
- cssid = WiFi.SSID(indices[i]);
for (int j = i + 1; j < n; j++) {
- if (cssid == WiFi.SSID(indices[j])) {
- snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
- AddLog(LOG_LEVEL_DEBUG);
- indices[j] = -1; // set dup aps to index -1
+ if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
+ std::swap(indices[i], indices[j]);
}
}
}
- }
- //display networks in page
- for (int i = 0; i < n; i++) {
- if (-1 == indices[i]) { continue; } // skip dups
- snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), WiFi.RSSI(indices[i]));
- AddLog(LOG_LEVEL_DEBUG);
- int quality = WifiGetRssiAsQuality(WiFi.RSSI(indices[i]));
-
- if (minimum_signal_quality == -1 || minimum_signal_quality < quality) {
- String item = FPSTR(HTTP_LNK_ITEM);
- String rssiQ;
- rssiQ += quality;
- item.replace(F("{v}"), htmlEscape(WiFi.SSID(indices[i])));
- item.replace(F("{w}"), String(WiFi.channel(indices[i])));
- item.replace(F("{r}"), rssiQ);
- uint8_t auth = WiFi.encryptionType(indices[i]);
- item.replace(F("{i}"), (ENC_TYPE_WEP == auth) ? F(D_WEP) : (ENC_TYPE_TKIP == auth) ? F(D_WPA_PSK) : (ENC_TYPE_CCMP == auth) ? F(D_WPA2_PSK) : (ENC_TYPE_AUTO == auth) ? F(D_AUTO) : F(""));
- page += item;
- delay(0);
- } else {
- AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SKIPPING_LOW_QUALITY));
+ // remove duplicates ( must be RSSI sorted )
+ if (remove_duplicate_access_points) {
+ String cssid;
+ for (int i = 0; i < n; i++) {
+ if (-1 == indices[i]) { continue; }
+ cssid = WiFi.SSID(indices[i]);
+ for (int j = i + 1; j < n; j++) {
+ if (cssid == WiFi.SSID(indices[j])) {
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
+ AddLog(LOG_LEVEL_DEBUG);
+ indices[j] = -1; // set dup aps to index -1
+ }
+ }
+ }
}
- }
- page += " ";
- }
- } else {
- page += FPSTR(HTTP_LNK_SCAN);
- }
+ //display networks in page
+ for (int i = 0; i < n; i++) {
+ if (-1 == indices[i]) { continue; } // skip dups
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), WiFi.RSSI(indices[i]));
+ AddLog(LOG_LEVEL_DEBUG);
+ int quality = WifiGetRssiAsQuality(WiFi.RSSI(indices[i]));
- page += FPSTR(HTTP_FORM_WIFI);
- page.replace(F("{h1"), Settings.hostname);
- page.replace(F("{s1"), Settings.sta_ssid[0]);
- page.replace(F("{s2"), Settings.sta_ssid[1]);
- page += FPSTR(HTTP_FORM_END);
- if (HTTP_MANAGER == webserver_state) {
+ if (minimum_signal_quality == -1 || minimum_signal_quality < quality) {
+ String item = FPSTR(HTTP_LNK_ITEM);
+ String rssiQ;
+ rssiQ += quality;
+ item.replace(F("{v}"), htmlEscape(WiFi.SSID(indices[i])));
+ item.replace(F("{w}"), String(WiFi.channel(indices[i])));
+ item.replace(F("{r}"), rssiQ);
+ uint8_t auth = WiFi.encryptionType(indices[i]);
+ item.replace(F("{i}"), (ENC_TYPE_WEP == auth) ? F(D_WEP) : (ENC_TYPE_TKIP == auth) ? F(D_WPA_PSK) : (ENC_TYPE_CCMP == auth) ? F(D_WPA2_PSK) : (ENC_TYPE_AUTO == auth) ? F(D_AUTO) : F(""));
+ page += item;
+ delay(0);
+ } else {
+ AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SKIPPING_LOW_QUALITY));
+ }
+
+ }
+ page += " ";
+ }
+ } else {
+ page += FPSTR(HTTP_LNK_SCAN);
+ }
+
+ page += FPSTR(HTTP_FORM_WIFI);
+ page.replace(F("{h1"), Settings.hostname);
+ page.replace(F("{s1"), Settings.sta_ssid[0]);
+ page.replace(F("{s2"), Settings.sta_ssid[1]);
+ page += FPSTR(HTTP_FORM_END);
+ }
+ if (WifiIsInManagerMode()) {
page += FPSTR(HTTP_BTN_RSTRT);
+ #ifndef FIRMWARE_MINIMAL
+ page += FPSTR(HTTP_BTN_RESET);
+ #endif // FIRMWARE_MINIMAL
} else {
page += FPSTR(HTTP_BTN_CONF);
}
// ShowPage(page);
- ShowPage(page, !(HTTP_MANAGER == webserver_state));
+ ShowPage(page, !(WifiIsInManagerMode()));
}
void WifiSaveSettings(void)
@@ -2089,7 +2108,7 @@ void HandleNotFound(void)
/* Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
bool CaptivePortal(void)
{
- if ((HTTP_MANAGER == webserver_state) && !ValidIpAddress(WebServer->hostHeader())) {
+ if ((WifiIsInManagerMode()) && !ValidIpAddress(WebServer->hostHeader())) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_REDIRECTED));
WebServer->sendHeader(F("Location"), String("http://") + WebServer->client().localIP().toString(), true);
From 731154cc9bc3c3f1434b329b21b074994e011a12 Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 19:45:03 +0100
Subject: [PATCH 62/68] Handle authentication on reset/restart
---
sonoff/xdrv_01_webserver.ino | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 5d975ac1b..05f095010 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -666,14 +666,16 @@ void WebRestart(uint8_t type)
page.replace(F("{v}"), FPSTR(S_RESTART));
}
+ bool reset_only = (HTTP_MANAGER_RESET_ONLY == webserver_state);
+
page += FPSTR(HTTP_MSG_RSTRT);
- if (HTTP_MANAGER == webserver_state) {
+ if (HTTP_MANAGER == webserver_state || reset_only) {
webserver_state = HTTP_ADMIN;
} else {
page += FPSTR(HTTP_BTN_MAIN);
}
page.replace(F(""), FPSTR(HTTP_SCRIPT_RELOAD));
- ShowPage(page);
+ ShowPage(page, !reset_only);
ShowWebSource(SRC_WEBGUI);
restart_flag = 2;
@@ -1494,7 +1496,7 @@ void HandleResetConfiguration(void)
page += F("" D_CONFIGURATION_RESET " ");
page += FPSTR(HTTP_MSG_RSTRT);
page += FPSTR(HTTP_BTN_MAIN);
- ShowPage(page);
+ ShowPage(page, HTTP_MANAGER_RESET_ONLY != webserver_state);
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RESET " 1"));
ExecuteWebCommand(svalue, SRC_WEBGUI);
From e9396d0ed42864835fef78e61a142cb87809e953 Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 19:45:21 +0100
Subject: [PATCH 63/68] Add missing localization strings
---
sonoff/i18n.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sonoff/i18n.h b/sonoff/i18n.h
index 7340a3484..e0b3af57b 100644
--- a/sonoff/i18n.h
+++ b/sonoff/i18n.h
@@ -248,6 +248,7 @@
#define D_WCFG_4_RETRY "Retry"
#define D_WCFG_5_WAIT "Wait"
#define D_WCFG_6_SERIAL "Serial"
+ #define D_WCFG_7_WIFIMANAGER_RESET_ONLY "ManagerRst"
#define D_CMND_FRIENDLYNAME "FriendlyName"
#define D_CMND_SWITCHMODE "SwitchMode"
#define D_CMND_INTERLOCK "Interlock"
@@ -540,7 +541,8 @@ const char kWifiConfig[MAX_WIFI_OPTION][WCFG_MAX_STRING_LENGTH] PROGMEM = {
D_WCFG_3_WPSCONFIG,
D_WCFG_4_RETRY,
D_WCFG_5_WAIT,
- D_WCFG_6_SERIAL };
+ D_WCFG_6_SERIAL,
+ D_WCFG_7_WIFIMANAGER_RESET_ONLY };
const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = {
D_CMND,
D_STAT,
From b3adab40979b6882bab6f8a8277e84f23f112805 Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 21:27:52 +0100
Subject: [PATCH 64/68] Add flag for no hold retain
---
sonoff/settings.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sonoff/settings.h b/sonoff/settings.h
index bc39d7d8a..447db10c0 100644
--- a/sonoff/settings.h
+++ b/sonoff/settings.h
@@ -75,7 +75,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t hass_tele_on_power : 1; // bit 9 (v6.3.0.13)
uint32_t sleep_normal : 1; // bit 10 (v6.3.0.15) - SetOption60 - Enable normal sleep instead of dynamic sleep
uint32_t button_switch_force_local : 1;// bit 11 (v6.3.0.16) - SetOption61 - Force local operation when button/switch topic is set
- uint32_t spare12 : 1;
+ uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages
uint32_t spare13 : 1;
uint32_t spare14 : 1;
uint32_t spare15 : 1;
From 6cbfb0308aede1b6d2161b51c36f377151e077ba Mon Sep 17 00:00:00 2001
From: netpok
Date: Thu, 21 Feb 2019 21:28:35 +0100
Subject: [PATCH 65/68] Check no hold retain flag on hold action sending
---
sonoff/sonoff.ino | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 24a3d5723..5cb6379f9 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -1434,10 +1434,10 @@ bool SendKey(uint8_t key, uint8_t device, uint8_t state)
}
#ifdef USE_DOMOTICZ
if (!(DomoticzSendKey(key, device, state, strlen(mqtt_data)))) {
- MqttPublishDirect(stopic, (key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain);
+ MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != 3 || !Settings.flag3.no_hold_retain));
}
#else
- MqttPublishDirect(stopic, (key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain);
+ MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != 3 || !Settings.flag3.no_hold_retain));
#endif // USE_DOMOTICZ
result = !Settings.flag3.button_switch_force_local;
} else {
From 49f0b514ebae8f9f17a48eada91361258ee92585 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Fri, 22 Feb 2019 12:04:05 +0100
Subject: [PATCH 66/68] Fix some exceptions and watchdogs
* Fix some exceptions and watchdogs due to lack of stack space - part 2
* Add command SetOption62 0/1 to disable retain on Button or Swith hold messages (#5299)
* Add option WifiConfig 7 to allow reset of device in AP mode without admin password (#5297)
---
sonoff/_changelog.ino | 3 +++
sonoff/sonoff.ino | 14 +++++++-------
sonoff/xdrv_01_webserver.ino | 24 +++++++++++-------------
3 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index 0d4fef299..0ca38587b 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -1,5 +1,8 @@
/* 6.4.1.18 20191221
* Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
+ * Fix some exceptions and watchdogs due to lack of stack space - part 2
+ * Add command SetOption62 0/1 to disable retain on Button or Swith hold messages (#5299)
+ * Add option WifiConfig 7 to allow reset of device in AP mode without admin password (#5297)
*
* 6.4.1.17 20190214
* Change template update by removing possibility to add user module config keeping template as defined (#5222)
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 5cb6379f9..161c26ed8 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -866,9 +866,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
restart_flag = 2;
}
- uint8_t module = Settings.module;
- if (USER_MODULE == Settings.module) { module = 0; } else { module++; }
- snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SVALUE, command, module, ModuleName().c_str());
+ snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str());
}
else if (CMND_MODULES == command_code) {
for (uint8_t i = 0; i <= MAXMODULE; i++) {
@@ -1566,8 +1564,6 @@ void StopAllPowerBlink(void)
void ExecuteCommand(char *cmnd, int source)
{
- char stopic[CMDSZ];
- char svalue[INPUT_BUFFER_SIZE];
char *start;
char *token;
@@ -1579,9 +1575,13 @@ void ExecuteCommand(char *cmnd, int source)
start = strrchr(token, '/'); // Skip possible cmnd/sonoff/ preamble
if (start) { token = start +1; }
}
+ uint16_t size = (token != NULL) ? strlen(token) : 0;
+ char stopic[size +2]; // / + \0
snprintf_P(stopic, sizeof(stopic), PSTR("/%s"), (token == NULL) ? "" : token);
+
token = strtok(NULL, "");
-// snprintf_P(svalue, sizeof(svalue), (token == NULL) ? "" : token); // Fails with command FullTopic home/%prefix%/%topic% as it processes %p of %prefix%
+ size = (token != NULL) ? strlen(token) : 0;
+ char svalue[size +1];
strlcpy(svalue, (token == NULL) ? "" : token, sizeof(svalue)); // Fixed 5.8.0b
MqttDataHandler(stopic, (uint8_t*)svalue, strlen(svalue));
}
@@ -1610,7 +1610,7 @@ void PublishStatus(uint8_t payload)
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%s%d" ), stemp2, (i > 0 ? "," : ""), Settings.switchmode[i]);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS "\":{\"" D_CMND_MODULE "\":%d,\"" D_CMND_FRIENDLYNAME "\":[%s],\"" D_CMND_TOPIC "\":\"%s\",\"" D_CMND_BUTTONTOPIC "\":\"%s\",\"" D_CMND_POWER "\":%d,\"" D_CMND_POWERONSTATE "\":%d,\"" D_CMND_LEDSTATE "\":%d,\"" D_CMND_SAVEDATA "\":%d,\"" D_JSON_SAVESTATE "\":%d,\"" D_CMND_SWITCHTOPIC "\":\"%s\",\"" D_CMND_SWITCHMODE "\":[%s],\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_SWITCHRETAIN "\":%d,\"" D_CMND_SENSORRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
- (USER_MODULE == Settings.module)?0:Settings.module +1, stemp, mqtt_topic, Settings.button_topic, power, Settings.poweronstate, Settings.ledstate, Settings.save_data, Settings.flag.save_state, Settings.switch_topic, stemp2, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_switch_retain, Settings.flag.mqtt_sensor_retain, Settings.flag.mqtt_power_retain);
+ ModuleNr(), stemp, mqtt_topic, Settings.button_topic, power, Settings.poweronstate, Settings.ledstate, Settings.save_data, Settings.flag.save_state, Settings.switch_topic, stemp2, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_switch_retain, Settings.flag.mqtt_sensor_retain, Settings.flag.mqtt_power_retain);
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS));
}
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 0258484b9..779872bb9 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -1956,8 +1956,6 @@ void HandleHttpCommand(void)
{
if (!HttpCheckPriviledgedAccess(false)) { return; }
- char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
-
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
uint8_t valid = 1;
@@ -1972,9 +1970,9 @@ void HandleHttpCommand(void)
String message = F("{\"" D_RSLT_WARNING "\":\"");
if (valid) {
uint8_t curridx = web_log_index;
- WebGetArg("cmnd", svalue, sizeof(svalue));
- if (strlen(svalue)) {
- ExecuteWebCommand(svalue, SRC_WEBCOMMAND);
+ String svalue = WebServer->arg("cmnd");
+ if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
+ ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE);
if (web_log_index != curridx) {
uint8_t counter = curridx;
@@ -2032,19 +2030,19 @@ void HandleAjaxConsoleRefresh(void)
{
if (!HttpCheckPriviledgedAccess()) { return; }
- char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
bool cflg = true;
uint8_t counter = 0; // Initial start, should never be 0 again
- WebGetArg("c1", svalue, sizeof(svalue));
- if (strlen(svalue)) {
- snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue);
+ String svalue = WebServer->arg("c1");
+ if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
+ snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue.c_str());
AddLog(LOG_LEVEL_INFO);
- ExecuteWebCommand(svalue, SRC_WEBCONSOLE);
+ ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE);
}
- WebGetArg("c2", svalue, sizeof(svalue));
- if (strlen(svalue)) { counter = atoi(svalue); }
+ char stmp[10];
+ WebGetArg("c2", stmp, sizeof(stmp));
+ if (strlen(stmp)) { counter = atoi(stmp); }
bool last_reset_web_log_flag = reset_web_log_flag;
// mqtt_data used as scratch space
@@ -2202,7 +2200,7 @@ int WebSend(char *buffer)
user = Trim(user); // user = |admin|
if (password) { password = Trim(password); } // password = |joker|
}
-
+
command = Trim(command); // command = |POWER1 ON| or |/any/link/starting/with/a/slash.php?log=123|
if (command[0] != '/') {
url += F("/cm?"); // url = |http://192.168.178.86/cm?|
From d219d1c9b5d482f5233e37caa63071a194c7240b Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Fri, 22 Feb 2019 12:11:15 +0100
Subject: [PATCH 67/68] Update support.ino
Houskeeping
---
sonoff/support.ino | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/sonoff/support.ino b/sonoff/support.ino
index 113968974..ff488d008 100644
--- a/sonoff/support.ino
+++ b/sonoff/support.ino
@@ -699,6 +699,13 @@ void ShowSource(int source)
* GPIO Module and Template management
\*********************************************************************************************/
+uint8_t ModuleNr()
+{
+ // 0 = User module (255)
+ // 1 up = Template module 0 up
+ return (USER_MODULE == Settings.module) ? 0 : Settings.module +1;
+}
+
String AnyModuleName(uint8_t index)
{
if (USER_MODULE == index) {
@@ -720,7 +727,6 @@ void ModuleGpios(myio *gp)
uint8_t src[sizeof(mycfgio)];
if (USER_MODULE == Settings.module) {
-// src = Settings.user_template.gp;
memcpy(&src, &Settings.user_template.gp, sizeof(mycfgio));
} else {
memcpy_P(&src, &kModules[Settings.module].gp, sizeof(mycfgio));
@@ -870,14 +876,6 @@ bool JsonTemplate(const char* dataBuf)
if ((0 == base) || (base >= MAXMODULE)) { base = 17; } else { base--; }
Settings.user_template_base = base; // Default WEMOS
}
-
- // Validate GPIO
-// for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
- // For now do not allow non-user configurable GPIO
-// if ((Settings.user_template.gp.io[i] > GPIO_FIX_START) && (Settings.user_template.gp.io[i] < GPIO_USER)) {
-// Settings.user_template.gp.io[i] = GPIO_NONE;
-// };
-// }
return true;
}
@@ -887,8 +885,6 @@ void TemplateJson()
for (uint8_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d"), mqtt_data, (i>0)?",":"", Settings.user_template.gp.io[i]);
}
-// snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":\"%d (%s)\"}"),
-// mqtt_data, Settings.user_template.flag, Settings.user_template_base +1, AnyModuleName(Settings.user_template_base).c_str());
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"),
mqtt_data, Settings.user_template.flag, Settings.user_template_base +1);
}
From e315be06198ae481b102967359c886ed1e9bd6da Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Fri, 22 Feb 2019 15:19:59 +0100
Subject: [PATCH 68/68] Fix command WebSend
Fix command WebSend when using a port number as regression from 6.4.1.17 (#5304)
---
sonoff/_changelog.ino | 1 +
sonoff/xdrv_01_webserver.ino | 9 +++++----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index 0ca38587b..d9762ec24 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -3,6 +3,7 @@
* Fix some exceptions and watchdogs due to lack of stack space - part 2
* Add command SetOption62 0/1 to disable retain on Button or Swith hold messages (#5299)
* Add option WifiConfig 7 to allow reset of device in AP mode without admin password (#5297)
+ * Fix command WebSend when using a port number as regression from 6.4.1.17 (#5304)
*
* 6.4.1.17 20190214
* Change template update by removing possibility to add user module config keeping template as defined (#5222)
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 779872bb9..cb2717db3 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -2182,18 +2182,19 @@ int WebSend(char *buffer)
// buffer = | [ 192.168.178.86 : 80 , admin : joker ] POWER1 ON |
host = strtok_r(buffer, "]", &command); // host = | [ 192.168.178.86 : 80 , admin : joker |, command = | POWER1 ON |
if (host && command) {
- String url = F("http:"); // url = |http:|
+ String url = F("http://"); // url = |http://|
host = Trim(host); // host = |[ 192.168.178.86 : 80 , admin : joker|
host++; // host = | 192.168.178.86 : 80 , admin : joker| - Skip [
host = strtok_r(host, ",", &user); // host = | 192.168.178.86 : 80 |, user = | admin : joker|
host = strtok_r(host, ":", &port); // host = | 192.168.178.86 |, port = | 80 |
host = Trim(host); // host = |192.168.178.86|
+ url += host; // url = |http://192.168.178.86|
+
if (port) {
port = Trim(port); // port = |80|
- url += port; // url = |http:80|
+ url += F(":"); // url = |http://192.168.178.86:|
+ url += port; // url = |http://192.168.178.86:80|
}
- url += F("//"); // url = |http://| or |http:80//|
- url += host; // url = |http://192.168.178.86|
if (user) {
user = strtok_r(user, ":", &password); // user = | admin |, password = | joker|
|
---|