After we have successfully connetcted to wifi the next step is test our connection to internet or specific ip. i am using additional library to do ping job, and the as below :
#include <Arduino.h> #include <WiFi.h> #include <ESP32Ping.h> String wifiSSID = "smartbuilding_wifi"; String wifiPassword = "smartbuilding@2020"; String googlDotCom = "www.google.com"; void setup() { Serial.begin(9600); Serial.println("Connecting To Wifi"); WiFi.begin(wifiSSID.c_str(), wifiPassword.c_str()); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println("Wifi Connected"); Serial.println(WiFi.SSID()); Serial.println(WiFi.RSSI()); Serial.println(WiFi.macAddress()); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.dnsIP()); if (Ping.ping(googlDotCom.c_str())) { Serial.println("Connected to Router"); } } void loop() { }
detail for this tutorial available on my youtube channel