diff --git a/at_socket_esp8266.c b/at_socket_esp8266.c index 0e6e416..7d8785f 100644 --- a/at_socket_esp8266.c +++ b/at_socket_esp8266.c @@ -323,7 +323,9 @@ __exit: */ static int esp8266_domain_resolve(const char *name, char ip[16]) { - int result = RT_EOK; +#define RESOLVE_RETRY 5 + + int i, result = RT_EOK; char recv_ip[16] = { 0 }; at_response_t resp = RT_NULL; @@ -339,26 +341,37 @@ static int esp8266_domain_resolve(const char *name, char ip[16]) rt_mutex_take(at_event_lock, RT_WAITING_FOREVER); -__restart: - if (at_exec_cmd(resp, "AT+CIPDOMAIN=\"%s\"", name) < 0) + for(i = 0; i < RESOLVE_RETRY; i++) { - result = -RT_ERROR; - goto __exit; + if (at_exec_cmd(resp, "AT+CIPDOMAIN=\"%s\"", name) < 0) + { + result = -RT_ERROR; + goto __exit; + } + + /* parse the third line of response data, get the IP address */ + if(at_resp_parse_line_args(resp, at_resp_get_line_num_by_kw(resp, "+CIPDOMAIN:"), + "+CIPDOMAIN:%s", recv_ip) < 0) + { + rt_thread_delay(rt_tick_from_millisecond(100)); + /* resolve failed, maybe receive an URC CRLF */ + continue; + } + + if (strlen(recv_ip) < 8) + { + rt_thread_delay(rt_tick_from_millisecond(100)); + /* resolve failed, maybe receive an URC CRLF */ + continue; + } + else + { + strncpy(ip, recv_ip, 15); + ip[15] = '\0'; + break; + } } - /* parse the third line of response data, get the IP address */ - at_resp_parse_line_args(resp, 1, "+CIPDOMAIN:%s", recv_ip); - - if (strlen(recv_ip) < 8) - { - rt_thread_delay(rt_tick_from_millisecond(100)); - /* resolve failed, maybe receive an URC CRLF */ - goto __restart; - } - - strncpy(ip, recv_ip, 15); - ip[15] = '\0'; - __exit: rt_mutex_release(at_event_lock); @@ -623,7 +636,12 @@ int esp8266_ping(int argc, char **argv) return -RT_ERROR; } - at_resp_parse_line_args(resp, 1, "+%d", &req_time); + if(at_resp_parse_line_args(resp, at_resp_get_line_num_by_kw(resp, "+"), + "+%d", &req_time) < 0) + { + continue; + } + if (req_time) { rt_kprintf("32 bytes from %s icmp_seq=%d time=%d ms\n", argv[1], icmp_seq, req_time); diff --git a/at_socket_m26.c b/at_socket_m26.c index 8c95485..858e2ea 100644 --- a/at_socket_m26.c +++ b/at_socket_m26.c @@ -384,7 +384,8 @@ static int m26_domain_resolve(const char *name, char ip[16]) RT_ASSERT(name); RT_ASSERT(ip); - resp = at_create_resp(128, 4, rt_tick_from_millisecond(5000)); + /* The maximum response time is 14 seconds, affected by network status */ + resp = at_create_resp(128, 4, rt_tick_from_millisecond(14 * 1000)); if (!resp) { LOG_E("No memory for response structure!");