Skip to content

Commit

Permalink
Merge pull request #24 from shufps/fix-0.0.0.0
Browse files Browse the repository at this point in the history
fix random 0.0.0.0 display
  • Loading branch information
shufps authored Oct 8, 2024
2 parents c39094b + d8c6f06 commit 02fd8f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
14 changes: 13 additions & 1 deletion components/connect/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ static const char *TAG = "wifi station";

static int s_retry_num = 0;

static char s_ip_addr[20]={0};
static bool ip_valid = false;

bool connect_get_ip_addr(char *buf, size_t buf_len) {
strncpy(buf, s_ip_addr, buf_len);
return ip_valid;
}

static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
Expand All @@ -77,7 +85,9 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_
}
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
ESP_LOGI(TAG, "Nerdaxe ip:" IPSTR, IP2STR(&event->ip_info.ip));
snprintf(s_ip_addr, sizeof(s_ip_addr), IPSTR, IP2STR(&event->ip_info.ip));
ip_valid = true;
ESP_LOGI(TAG, "Device ip: %s", s_ip_addr);
s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
}
Expand Down Expand Up @@ -175,6 +185,8 @@ void wifi_init(const char *wifi_ssid, const char *wifi_pass, const char *hostnam
{
s_wifi_event_group = xEventGroupCreate();

strcpy(s_ip_addr, "0.0.0.0");

ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());

Expand Down
1 change: 1 addition & 0 deletions components/connect/include/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void wifi_softap_off(void);
void wifi_init(const char *wifi_ssid, const char *wifi_pass, const char *hostname);
EventBits_t wifi_connect(void);
void generate_ssid(char *ssid);
bool connect_get_ip_addr(char *buf, size_t buf_len);

#ifdef __cplusplus
}
Expand Down
3 changes: 0 additions & 3 deletions main/displays/displayDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,11 @@ void DisplayDriver::updateGlobalState()

void DisplayDriver::updateIpAddress(char *ip_address_str)
{
char strData[20];

if (m_ui->ui_MiningScreen == NULL)
return;
if (m_ui->ui_SettingsScreen == NULL)
return;

snprintf(strData, sizeof(strData), "%s", ip_address_str);
lv_label_set_text(m_ui->ui_lbIP, ip_address_str); // Update label
lv_label_set_text(m_ui->ui_lbIPSet, ip_address_str); // Update label
}
Expand Down
11 changes: 7 additions & 4 deletions main/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@ void System::task() {
uint8_t countCycle = 10;
bool showsOverlay = false;
char ipAddressStr[IP4ADDR_STRLEN_MAX] = "0.0.0.0";
bool validIp = false;

// show initial 0.0.0.0
m_display->updateIpAddress(ipAddressStr);

while (1) {
// Check if the IP address is still "0.0.0.0" and update if not valid
if (strcmp(ipAddressStr, "0.0.0.0") == 0) {
esp_netif_get_ip_info(m_netif, &m_ipInfo);
esp_ip4addr_ntoa(&m_ipInfo.ip, ipAddressStr, IP4ADDR_STRLEN_MAX);
// update IP on the screen if it is available
if (!validIp && connect_get_ip_addr(ipAddressStr, sizeof(ipAddressStr))) {
ESP_LOGI(TAG, "ip address: %s", ipAddressStr);
m_display->updateIpAddress(ipAddressStr);
validIp = true;
}

if (m_overheated && !showsOverlay) {
Expand Down

0 comments on commit 02fd8f9

Please sign in to comment.