diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index fa454840..085e4b67 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -49,14 +49,13 @@ #define ets_delay_us(a) esp_rom_delay_us(a) #endif -esp_netif_t *sta_netif = NULL; - static const char *TAG = "WIFI"; static bool APWithBetterRSSI = false; static bool WIFIConnected = false; static int WIFIReconnectCnt = 0; +esp_netif_t *my_sta; void strinttoip4(const char *ip, int &a, int &b, int &c, int &d) { @@ -531,7 +530,7 @@ esp_err_t wifi_init_sta(void) return retval; } - esp_netif_t *my_sta = esp_netif_create_default_wifi_sta(); + my_sta = esp_netif_create_default_wifi_sta(); if (!wlan_config.ipaddress.empty() && !wlan_config.gateway.empty() && !wlan_config.netmask.empty()) { @@ -674,6 +673,20 @@ int get_WIFI_RSSI() } +/*std::string getIp() { + esp_netif_ip_info_t ip_info; + ESP_ERROR_CHECK(esp_netif_get_ip_info(my_sta, ip_info)); + char ipFormated[4*3+3+1]; + sprintf(ipFormated, IPSTR, IP2STR(&ip_info.ip)); + return std::string(ipFormated); +}*/ + + +std::string* getHostname() { + return &wlan_config.hostname; +} + + bool getWIFIisConnected() { return WIFIConnected; diff --git a/code/components/jomjol_wlan/connect_wlan.h b/code/components/jomjol_wlan/connect_wlan.h index f635966f..a97168c3 100644 --- a/code/components/jomjol_wlan/connect_wlan.h +++ b/code/components/jomjol_wlan/connect_wlan.h @@ -9,6 +9,8 @@ int wifi_init_sta(void); std::string* getIPAddress(); std::string* getSSID(); int get_WIFI_RSSI(); +std::string* getHostname(); + bool getWIFIisConnected(); void WIFIDestroy(); diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index e69854c5..1a8ce905 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -25,8 +25,6 @@ httpd_handle_t server = NULL; std::string starttime = ""; -extern esp_netif_t *sta_netif; - static const char *TAG = "MAIN SERVER"; /* An HTTP GET handler */ @@ -353,15 +351,6 @@ esp_err_t sysinfo_handler(httpd_req_t *req) char freeheapmem[11]; sprintf(freeheapmem, "%lu", (long) getESPHeapSize()); - esp_netif_ip_info_t ip_info; - ESP_ERROR_CHECK(esp_netif_get_ip_info(sta_netif, &ip_info)); - const char *hostname; - ESP_ERROR_CHECK(esp_netif_get_hostname(sta_netif, &hostname)); - - char ipFormated[4*3+3+1]; - - sprintf(ipFormated, IPSTR, IP2STR(&ip_info.ip)); - zw = string("[{") + "\"firmware\": \"" + gitversion + "\"," + "\"buildtime\": \"" + buildtime + "\"," + @@ -370,8 +359,8 @@ esp_err_t sysinfo_handler(httpd_req_t *req) "\"gitrevision\": \"" + gitrevision + "\"," + "\"html\": \"" + htmlversion + "\"," + "\"cputemp\": \"" + cputemp + "\"," + - "\"hostname\": \"" + hostname + "\"," + - "\"IPv4\": \"" + string(ipFormated) + "\"," + + "\"hostname\": \"" + *getHostname() + "\"," + + "\"IPv4\": \"" + *getIPAddress() + "\"," + "\"freeHeapMem\": \"" + freeheapmem + "\"" + "}]";