From cc56677ba30adf89c05ea98af631a6484b5afba1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 29 Oct 2018 12:21:27 +0100 Subject: [PATCH] Add Gui Hostname display Add command SetOption53 0/1 to toggle gui display of Hostname and IP address --- sonoff/_changelog.ino | 1 + sonoff/settings.h | 2 +- sonoff/xdrv_01_webserver.ino | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index aace62b7d..8fa067b63 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /* 6.2.1.20 20181028 * Add command SetOption35 0..255 (seconds) to delay mDNS initialization to control possible Wifi connect problems + * Add command SetOption53 0/1 to toggle gui display of Hostname and IP address * * 6.2.1.19 20181023 * Fix header file execution order by renaming user_config.h to my_user_config.h diff --git a/sonoff/settings.h b/sonoff/settings.h index 29aaf2121..8e0a22a2f 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -66,7 +66,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t timers_enable : 1; // bit 0 (v6.1.1b) uint32_t user_esp8285_enable : 1; // bit 1 (v6.1.1.14) uint32_t time_append_timezone : 1; // bit 2 (v6.2.1.2) - uint32_t spare03 : 1; + uint32_t gui_hostname_ip : 1; // bit 3 (v6.2.1.20) uint32_t spare04 : 1; uint32_t spare05 : 1; uint32_t spare06 : 1; diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 3cb2b31cb..261510924 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -119,7 +119,7 @@ const char HTTP_HEAD_STYLE[] PROGMEM = #else "

{ha " D_MODULE "

" #endif - "

{h}

"; + "

{h}

{j}"; const char HTTP_SCRIPT_CONSOL[] PROGMEM = "var sn=0;" // Scroll position "var id=0;" // Get most of weblog initially @@ -453,6 +453,25 @@ void ShowPage(String &page, bool auth) page.replace(F("{a}"), String(Settings.web_refresh)); page.replace(F("{ha"), my_module.name); page.replace(F("{h}"), Settings.friendlyname[0]); + + String info = ""; + if (Settings.flag3.gui_hostname_ip) { + uint8_t more_ips = 0; + info += F("

"); info += my_hostname; + if (mdns_begun) { info += F(".local"); } + info += F(" ("); + if (static_cast(WiFi.localIP()) != 0) { + info += WiFi.localIP().toString(); + more_ips++; + } + if (static_cast(WiFi.softAPIP()) != 0) { + if (more_ips) { info += F(", "); } + info += WiFi.softAPIP().toString(); + } + info += F(")

"); + } + page.replace(F("{j}"), info); + if (HTTP_MANAGER == webserver_state) { if (WifiConfigCounter()) { page.replace(F(""), F("")); @@ -1241,6 +1260,7 @@ void HandleInformation() func += F("}1" D_AP); func += String(Settings.sta_active +1); func += F(" " D_SSID " (" D_RSSI ")}2"); func += Settings.sta_ssid[Settings.sta_active]; func += F(" ("); func += WifiGetRssiAsQuality(WiFi.RSSI()); func += F("%)"); func += F("}1" D_HOSTNAME "}2"); func += my_hostname; + if (mdns_begun) { func += F(".local"); } if (static_cast(WiFi.localIP()) != 0) { func += F("}1" D_IP_ADDRESS "}2"); func += WiFi.localIP().toString(); func += F("}1" D_GATEWAY "}2"); func += IPAddress(Settings.ip_address[1]).toString();