From acad0437d9a306c9f680c4cdadd949e30d3a8191 Mon Sep 17 00:00:00 2001 From: SatoshyBoy <132848052+SatoshyBoy@users.noreply.github.com> Date: Mon, 4 Sep 2023 21:30:04 -0400 Subject: [PATCH 1/2] dns_found_cb bug Fix After restoring the Wi-Fi connection, the router may still try to connect to the internet. Therefore, it will fail to solve the IP address, and then the *ipaddr returns a NULL pointer. --- main/tasks/stratum_task.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/main/tasks/stratum_task.c b/main/tasks/stratum_task.c index bf882a88..50ea4891 100644 --- a/main/tasks/stratum_task.c +++ b/main/tasks/stratum_task.c @@ -18,7 +18,7 @@ static const char *TAG = "stratum_task"; static ip_addr_t ip_Addr; -static bool bDNSFound = false; +static uint8_t bDNSFound = 0; static StratumApiV1Message stratum_api_v1_message = {}; @@ -27,8 +27,15 @@ static SystemTaskModule SYSTEM_TASK_MODULE = { void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg) { - ip_Addr = *ipaddr; - bDNSFound = true; + if(ipaddr != NULL) + { + ip_Addr = *ipaddr; + bDNSFound = 1; + } + else + { + bDNSFound= -1; + } } void stratum_task(void *pvParameters) @@ -46,7 +53,7 @@ void stratum_task(void *pvParameters) // check to see if the STRATUM_URL is an ip address already if (inet_pton(AF_INET, stratum_url, &ip_Addr) == 1) { - bDNSFound = true; + bDNSFound = 1; } else { @@ -54,8 +61,17 @@ void stratum_task(void *pvParameters) IP_ADDR4(&ip_Addr, 0, 0, 0, 0); ESP_LOGI(TAG, "Get IP for URL: %s\n", stratum_url); dns_gethostbyname(stratum_url, &ip_Addr, dns_found_cb, NULL); - while (!bDNSFound) - ; + while (true) + { + vTaskDelay(500 / portTICK_PERIOD_MS); + + //try again + if (bDNSFound == -1) + dns_gethostbyname(stratum_url, &ip_Addr, dns_found_cb, NULL); + + if(bDNSFound == 1) + break; + } } // make IP address string from ip_Addr From 6962ec3b6b0e4c530971fe52c99f54db2ceb02c5 Mon Sep 17 00:00:00 2001 From: SatoshyBoy <132848052+SatoshyBoy@users.noreply.github.com> Date: Mon, 4 Sep 2023 21:31:55 -0400 Subject: [PATCH 2/2] dns_found_cb bug Fix After restoring the Wi-Fi connection, the router may still try to connect to the internet. Therefore, it will fail to solve the IP address, and then the *ipaddr returns a NULL pointer. --- main/tasks/stratum_task.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/tasks/stratum_task.c b/main/tasks/stratum_task.c index 50ea4891..5f44d424 100644 --- a/main/tasks/stratum_task.c +++ b/main/tasks/stratum_task.c @@ -18,7 +18,7 @@ static const char *TAG = "stratum_task"; static ip_addr_t ip_Addr; -static uint8_t bDNSFound = 0; +static int8_t bDNSFound = 0; static StratumApiV1Message stratum_api_v1_message = {};