0
\$\begingroup\$

I am using the following code to connect with the WiFi router:

#include <ESP8266WiFi.h>
    
const char *ssid =  "Your wifi Network name"; // replace with your wifi ssid and wpa2 key
const char *pass =  "Network password";
    
WiFiClient client;
     
void setup() 
{
  Serial.begin(9600);
  delay(10);
                   
  Serial.println("Connecting to ");
  Serial.println(ssid); 
     
  WiFi.begin(ssid, pass); 
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected"); 
}
     
void loop() 
{}

When I am connected to the WiFi router, it says "connected". When I am not connected to WiFi it shows "............" until I am connected to the WiFi.

All OK. But the issue is, if I have limited WiFi connection, it still gets connected to the WiFi and shows "connected".

I actually want that if there is a limited WiFi connection it prints:

Serial.Print ("Connected. No internet access/Limited network");
\$\endgroup\$
2
  • \$\begingroup\$ Tip: for each section of code quoted in your question - select the code and then press the {} code formatting button. Alternatively you can indent each line a minimum of four spaces. \$\endgroup\$
    – Transistor
    Commented Jan 18, 2022 at 9:34
  • \$\begingroup\$ I’m voting to close this question because wrong stack exchange \$\endgroup\$ Commented Jan 18, 2022 at 23:10

1 Answer 1

1
\$\begingroup\$

First thing you have to understand - the WiFi connection is not the same as Internet access. WiFi are just network and it doesn't always presumes that the AP network will have an Internet access behind it. So it's perfectly fine that your example sketch shows just "WiFi connected" even if there is no Internet access. It is just true that it did connected to WiFi AP. Your sketch doesn't includes anything to test Internet connection.

So if you got 1st paragraph, next thing you should know is that if you need to test if there is a working Internet connection, you have to test it with your sketch. For example you can ping or try to fetch a HTTP/HTTPS webpage of some well-know major resources on the Internet. I mean like Google, Facebook, etc. That is usually how such things work on other devices, like Windows OS or others. They just test if they connect some reliable resources over the Internet. Just pick a few reliable resources and add your tests to see if they are accessible after connection.

Similar question was answered here with the same suggestions: https://iot.stackexchange.com/questions/4120/how-to-test-internet-connectivity-of-network-to-which-esp32-is-connected

You probably can try to search for some code examples, snippets on the Internet. But this is out of scope of this site to write a complete code example for your case, because it's quite complex piece of code and this is a not a free design house.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.