Hi everyone.
I am facing some software reset issues with the APROXIMATELLY same code Hossein listed:
void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
{
ip_address = *ipaddr;
ESP_LOGE(TAG , "google.com ip is = %d" , ip_address.u_addr.ip4.addr);
ESP_LOGI(TAG , "internet connection : %s and ip : %d" , error ? "false" : "true" , ip_address.u_addr.ip4.addr);
}
void connection_status_task(void * parm){
while(1){
xEventGroupWaitBits(event_group, CONNECTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
error = dns_gethostbyname(url , &ip_address , dns_found_cb , NULL);
ESP_LOGE(TAG , "dns_gethostbyname return value = %d" , error);
while( !DNSFound ) ;
vTaskDelay(30000/portTICK_PERIOD_MS);
}
}
If the wifi AP is operating normally BUT without internet connection, the function dns_gethostbyname() got stucked (do not return) and after 10 seconds (more or less), ESP32 is reseted by software (esp-idf/components/lwip/lwip/src/core/timeouts.c:175). If the internet connection returns, the same code above works normally.
Is there a version of dns_gethostbyname() that is NON-BLOCKING?
Sergio
how to check if internet is available
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: how to check if internet is available
The software reset is odd. Can you tell a bit more about this?
In general: no, gethostbyname *cannot* be non-blocking as it uses DNS to resolve a hostname, which involves sending UDP packets to a DNS server and waiting for a reply. UDP packets can get lost and DNS servers can be slow to respond, so there has to be some amount of retransmits and waiting to see if there is a response as part of the process.
In general, there is no instant way to check for 'internet access' as a matter of how the Internet protocols work. Anything that *seems* instant (i.e. has low timeouts) runs a high risk of failing when there is a high-latency or congested link or a slow server involved.
In general: no, gethostbyname *cannot* be non-blocking as it uses DNS to resolve a hostname, which involves sending UDP packets to a DNS server and waiting for a reply. UDP packets can get lost and DNS servers can be slow to respond, so there has to be some amount of retransmits and waiting to see if there is a response as part of the process.
In general, there is no instant way to check for 'internet access' as a matter of how the Internet protocols work. Anything that *seems* instant (i.e. has low timeouts) runs a high risk of failing when there is a high-latency or congested link or a slow server involved.
Re: how to check if internet is available
Did anyone manage to make a working version?
Share example of checking your internet connection!
Share example of checking your internet connection!
-
- Posts: 2
- Joined: Sun Dec 27, 2020 8:15 pm
Re: how to check if internet is available
Ping is not enough to know if there is an actual viable internet connection. To be sure there is a connection you need to open a TCP connection with a known host. You can generate a 204 response from google.com and be sure you can actually connect. Or you would need to build a full connection with some host and load some data. You may be able to check AP connection settings if you have a cooperative access point but if you are connecting through some computer you may not be able to check beyond knowing if it has a network connection.
A connection that is not configured or is filtered by the router/network operator (data capped) can still ping an address. So it really depends what you need it for to see what level of connection checking you need. Android has an API to check service availability you may want to checkout.
Maybe it would even be worth setting up a server that sends a custom response. like sending your own version of a ping. Similar to a 204 response with only a couple bytes/bits instead of a full header. As long as you control it you don't need to use the standardized formats to signal a connection. Responding at all can be your signal so 1 bit would be plenty.
A connection that is not configured or is filtered by the router/network operator (data capped) can still ping an address. So it really depends what you need it for to see what level of connection checking you need. Android has an API to check service availability you may want to checkout.
Maybe it would even be worth setting up a server that sends a custom response. like sending your own version of a ping. Similar to a 204 response with only a couple bytes/bits instead of a full header. As long as you control it you don't need to use the standardized formats to signal a connection. Responding at all can be your signal so 1 bit would be plenty.
Re: how to check if internet is available
Yes. You are correct and also it can be helpful if you connect with your own external cloud network and send/receive some data to make sure that external network connectivity is there.excitedbox wrote: ↑Sun Dec 27, 2020 9:08 pmPing is not enough to know if there is an actual viable internet connection. To be sure there is a connection you need to open a TCP connection with a known host. You can generate a 204 response from google.com and be sure you can actually connect. Or you would need to build a full connection with some host and load some data. You may be able to check AP connection settings if you have a cooperative access point but if you are connecting through some computer you may not be able to check beyond knowing if it has a network connection.
A connection that is not configured or is filtered by the router/network operator (data capped) can still ping an address. So it really depends what you need it for to see what level of connection checking you need. Android has an API to check service availability you may want to checkout.
Maybe it would even be worth setting up a server that sends a custom response. like sending your own version of a ping. Similar to a 204 response with only a couple bytes/bits instead of a full header. As long as you control it you don't need to use the standardized formats to signal a connection. Responding at all can be your signal so 1 bit would be plenty.
Regards,
Ritesh Prajapati
Ritesh Prajapati
-
- Posts: 75
- Joined: Fri Dec 04, 2020 9:56 pm
Re: how to check if internet is available
In most of the applications one needs to connect to their own host. If that is the case, I would simply try to connect and exchange data with that target host. The reason is that something on the way to your own host can e.g. block or redirect the connection (antivirus, firewall, etc.). It's also a proof that at this particular moment your own host server is running.
Re: how to check if internet is available
Yes. Exactly...Victoria Nope wrote: ↑Sun Jan 03, 2021 8:45 amIn most of the applications one needs to connect to their own host. If that is the case, I would simply try to connect and exchange data with that target host. The reason is that something on the way to your own host can e.g. block or redirect the connection (antivirus, firewall, etc.). It's also a proof that at this particular moment your own host server is running.
Regards,
Ritesh Prajapati
Ritesh Prajapati
Who is online
Users browsing this forum: Google [Bot] and 111 guests