Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix broken sysinfo #2381

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions code/components/jomjol_wlan/connect_wlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions code/components/jomjol_wlan/connect_wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 2 additions & 13 deletions code/main/server_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 + "\"," +
Expand All @@ -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 + "\"" +
"}]";

Expand Down