diff --git a/src/core/system.cpp b/src/core/system.cpp index aa39b3b34..af70e6ee6 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1789,6 +1789,28 @@ std::string System::get_metrics_prometheus() { return result; } +// return IP or hostname of the EMS-ESP device +String System::get_ip_or_hostname() { + String result = "ems-esp"; + EMSESP::esp32React.getNetworkSettingsService()->read([&](NetworkSettings & settings) { + if (settings.enableMDNS) { + if (EMSESP::system_.ethernet_connected()) { + result = ETH.getHostname(); + } else if (WiFi.status() == WL_CONNECTED) { + result = WiFi.getHostname(); + } + } else { + // no DNS, use the IP + if (EMSESP::system_.ethernet_connected()) { + result = ETH.localIP().toString(); + } else if (WiFi.status() == WL_CONNECTED) { + result = WiFi.localIP().toString(); + } + } + }); + return result; +} + // export status information including the device information // http://ems-esp/api/system/info bool System::command_info(const char * value, const int8_t id, JsonObject output) { @@ -2356,7 +2378,6 @@ String System::getBBQKeesGatewayDetails(uint8_t detail) { // This is to avoid timeouts in callback functions, like calling from a web hook. bool System::uploadFirmwareURL(const char * url) { #ifndef EMSESP_STANDALONE - static String saved_url; if (url && strlen(url) > 0) { diff --git a/src/core/system.h b/src/core/system.h index a265c65c5..c7f3adaa7 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -92,8 +92,8 @@ class System { static bool command_response(const char * value, const int8_t id, JsonObject output); static bool command_service(const char * cmd, const char * value); - static bool get_value_info(JsonObject root, const char * cmd); - static void get_value_json(JsonObject output, const std::string & circuit, const std::string & name, JsonVariant val); + static bool get_value_info(JsonObject root, const char * cmd); + static void get_value_json(JsonObject output, const std::string & circuit, const std::string & name, JsonVariant val); static std::string get_metrics_prometheus(); #if defined(EMSESP_TEST) @@ -151,6 +151,8 @@ class System { static bool readCommand(const char * data); + static String get_ip_or_hostname(); + void dallas_gpio(uint8_t gpio) { dallas_gpio_ = gpio; }