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

Add retries if the stratum hostname is not found #27

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 22 additions & 6 deletions main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static const char *TAG = "stratum_task";
static ip_addr_t ip_Addr;
static bool bDNSFound = false;
static int8_t bDNSFound = 0;

static StratumApiV1Message stratum_api_v1_message = {};

Expand All @@ -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)
Expand All @@ -46,16 +53,25 @@ 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
{
// it's a hostname. Lookup the ip address.
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
Expand Down
Loading