From 7d8489181364e8ced88facb53e28ed533f845c3e Mon Sep 17 00:00:00 2001 From: phlupp Date: Tue, 15 Sep 2020 22:12:35 +0200 Subject: [PATCH 1/2] =?UTF-8?q?HostName=20=C3=84nderungen=20aufger=C3=A4um?= =?UTF-8?q?t=20und=20standard=20Hostname=20auf=20"watermeter"=20gesetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/lib/connect_wlan/connect_wlan.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/code/lib/connect_wlan/connect_wlan.cpp b/code/lib/connect_wlan/connect_wlan.cpp index e492b6ac..99ae2369 100644 --- a/code/lib/connect_wlan/connect_wlan.cpp +++ b/code/lib/connect_wlan/connect_wlan.cpp @@ -23,6 +23,8 @@ std::string ssid; std::string passphrase; std::string hostname; +std::string std_hostname = "watermeter"; + static EventGroupHandle_t wifi_event_group; @@ -107,8 +109,9 @@ void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _ho wifi_event_group = xEventGroupCreate(); ssid = _ssid; passphrase = _passphrase; - if(_hostname.length() <= 0){ - _hostname = "watermeter"; + hostname = _hostname; + if(hostname.length() <= 0){ + hostname = std_hostname; } esp_log_level_set("wifi", ESP_LOG_NONE); // disable wifi driver logging tcpip_adapter_init(); @@ -116,7 +119,7 @@ void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _ho ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); ESP_ERROR_CHECK( esp_wifi_start() ); - esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA , _hostname.c_str()); + esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA , hostname.c_str()); if(ret != ESP_OK ){ ESP_LOGE(MAIN_TAG,"failed to set hostname:%d",ret); } @@ -124,7 +127,7 @@ void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _ho tcpip_adapter_ip_info_t ip_info; ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); printf("IPv4 : %s\n", ip4addr_ntoa(&ip_info.ip)); - printf("HostName : %s\n", _hostname.c_str()); + printf("HostName : %s\n", hostname.c_str()); } @@ -132,7 +135,7 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra { string line = ""; std::vector zerlegt; - _hostname = "iciruit"; + _hostname = std_hostname; FILE* pFile; fn = FormatFileName(fn); From fb0fb551ffd1779778bb1c66d42405169a505519 Mon Sep 17 00:00:00 2001 From: phlupp Date: Tue, 15 Sep 2020 22:26:59 +0200 Subject: [PATCH 2/2] =?UTF-8?q?update=20Hostname,=20aufger=C3=A4umt=20und?= =?UTF-8?q?=20optimiert,=20Standar=20auf=20"watermeter"=20gesetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/lib/connect_wlan/connect_wlan.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/lib/connect_wlan/connect_wlan.cpp b/code/lib/connect_wlan/connect_wlan.cpp index 99ae2369..e42bf64c 100644 --- a/code/lib/connect_wlan/connect_wlan.cpp +++ b/code/lib/connect_wlan/connect_wlan.cpp @@ -110,9 +110,6 @@ void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _ho ssid = _ssid; passphrase = _passphrase; hostname = _hostname; - if(hostname.length() <= 0){ - hostname = std_hostname; - } esp_log_level_set("wifi", ESP_LOG_NONE); // disable wifi driver logging tcpip_adapter_init(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); @@ -161,6 +158,10 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra if ((_hostname[0] == '"') && (_hostname[_hostname.length()-1] == '"')){ _hostname = _hostname.substr(1, _hostname.length()-2); } + // Check if Hostname was empty in .ini if yes set to std_hostname + if(_hostname.length() <= 0){ + _hostname = std_hostname; + } } if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "SSID")){