fix broken sysinfo (#2381)

Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
CaCO3
2023-05-01 23:34:55 +02:00
committed by GitHub
parent 5a00bdd7f6
commit 13d01a6c96
3 changed files with 20 additions and 16 deletions

View File

@@ -49,14 +49,13 @@
#define ets_delay_us(a) esp_rom_delay_us(a) #define ets_delay_us(a) esp_rom_delay_us(a)
#endif #endif
esp_netif_t *sta_netif = NULL;
static const char *TAG = "WIFI"; static const char *TAG = "WIFI";
static bool APWithBetterRSSI = false; static bool APWithBetterRSSI = false;
static bool WIFIConnected = false; static bool WIFIConnected = false;
static int WIFIReconnectCnt = 0; static int WIFIReconnectCnt = 0;
esp_netif_t *my_sta;
void strinttoip4(const char *ip, int &a, int &b, int &c, int &d) { 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; 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()) 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() bool getWIFIisConnected()
{ {
return WIFIConnected; return WIFIConnected;

View File

@@ -9,6 +9,8 @@ int wifi_init_sta(void);
std::string* getIPAddress(); std::string* getIPAddress();
std::string* getSSID(); std::string* getSSID();
int get_WIFI_RSSI(); int get_WIFI_RSSI();
std::string* getHostname();
bool getWIFIisConnected(); bool getWIFIisConnected();
void WIFIDestroy(); void WIFIDestroy();

View File

@@ -25,8 +25,6 @@
httpd_handle_t server = NULL; httpd_handle_t server = NULL;
std::string starttime = ""; std::string starttime = "";
extern esp_netif_t *sta_netif;
static const char *TAG = "MAIN SERVER"; static const char *TAG = "MAIN SERVER";
/* An HTTP GET handler */ /* An HTTP GET handler */
@@ -353,15 +351,6 @@ esp_err_t sysinfo_handler(httpd_req_t *req)
char freeheapmem[11]; char freeheapmem[11];
sprintf(freeheapmem, "%lu", (long) getESPHeapSize()); 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("[{") + zw = string("[{") +
"\"firmware\": \"" + gitversion + "\"," + "\"firmware\": \"" + gitversion + "\"," +
"\"buildtime\": \"" + buildtime + "\"," + "\"buildtime\": \"" + buildtime + "\"," +
@@ -370,8 +359,8 @@ esp_err_t sysinfo_handler(httpd_req_t *req)
"\"gitrevision\": \"" + gitrevision + "\"," + "\"gitrevision\": \"" + gitrevision + "\"," +
"\"html\": \"" + htmlversion + "\"," + "\"html\": \"" + htmlversion + "\"," +
"\"cputemp\": \"" + cputemp + "\"," + "\"cputemp\": \"" + cputemp + "\"," +
"\"hostname\": \"" + hostname + "\"," + "\"hostname\": \"" + *getHostname() + "\"," +
"\"IPv4\": \"" + string(ipFormated) + "\"," + "\"IPv4\": \"" + *getIPAddress() + "\"," +
"\"freeHeapMem\": \"" + freeheapmem + "\"" + "\"freeHeapMem\": \"" + freeheapmem + "\"" +
"}]"; "}]";