Hi,
I am working on ESP32 DEVKITV1 and making it a server with a static IP.
When i am connecting my laptop which is acting as a client to ESP32 server on a particular IP.
When i disconnecting client manually then client.connected() function return 0 and everything is working fine.
But when laptop/client lose internet connectivity over which communication was taking place then client.connected() function still return 1, due to which my ESP32 get stucked in that loop.
Please help me out how to solve this .
I am attaching my code of void loop() here.
WiFiClient client = server.available();
if(client){
while(client.connected())
{ Serial.println(client)
String st = "";
st = client.connected();
Serial.println(st);
delay(1000);
}
client.stop();
}
Sorry Sir, i will go through the rules.
Here my doubt is that is can i send the same information to server when client disconnected due to internet connectivity and disconnected manually.
I just want that ESP32 can detect client disconnection when internet connectivity got lost.
Please help me out, if this is possible.
Regards
Akansha
void printWiFiEventDetails(WiFiEvent_t event)
{
Serial.printf("[WiFi-event] event: %d\n", event);
switch (event) {
case SYSTEM_EVENT_WIFI_READY:
Serial.println("WiFi interface ready");
break;
case SYSTEM_EVENT_SCAN_DONE:
Serial.println("Completed scan for access points");
break;
case SYSTEM_EVENT_STA_START:
Serial.println("WiFi client started");
break;
case SYSTEM_EVENT_STA_STOP:
Serial.println("WiFi clients stopped");
break;
case SYSTEM_EVENT_STA_CONNECTED:
Serial.println("Connected to access point");
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
Serial.println("Disconnected from WiFi access point");
break;
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
Serial.println("Authentication mode of access point has changed");
break;
case SYSTEM_EVENT_STA_GOT_IP:
Serial.print("Obtained IP address: ");
Serial.println(WiFi.localIP());
break;
case SYSTEM_EVENT_STA_LOST_IP:
Serial.println("Lost IP address and IP address is reset to 0");
break;
case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
Serial.println("WiFi Protected Setup (WPS): succeeded in enrollee mode");
break;
case SYSTEM_EVENT_STA_WPS_ER_FAILED:
Serial.println("WiFi Protected Setup (WPS): failed in enrollee mode");
break;
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
Serial.println("WiFi Protected Setup (WPS): timeout in enrollee mode");
break;
case SYSTEM_EVENT_STA_WPS_ER_PIN:
Serial.println("WiFi Protected Setup (WPS): pin code in enrollee mode");
break;
case SYSTEM_EVENT_AP_START:
Serial.println("WiFi access point started");
break;
case SYSTEM_EVENT_AP_STOP:
Serial.println("WiFi access point stopped");
break;
case SYSTEM_EVENT_AP_STACONNECTED:
Serial.println("Client connected");
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
Serial.println("Client disconnected");
break;
case SYSTEM_EVENT_AP_STAIPASSIGNED:
Serial.println("Assigned IP address to client");
break;
case SYSTEM_EVENT_AP_PROBEREQRECVED:
Serial.println("Received probe request");
break;
case SYSTEM_EVENT_GOT_IP6:
Serial.println("IPv6 is preferred");
break;
case SYSTEM_EVENT_ETH_START:
Serial.println("Ethernet started");
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("Ethernet stopped");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("Ethernet connected");
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("Ethernet disconnected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.println("Obtained IP address");
break;
default: break;
}
}
void WiFiEvent(WiFiEvent_t event)
{
printWiFiEventDetails(event);
if (event == XXX) {
// handle your specific event here
}
}
Thanks for your reply!
I gone through these WiFi handler events.
These events concerned with the WiFi connection status on ESP32 end either in STA mode or AP mode.
But i wanted to know WiFi connection status on client end which my PC in this case.
As we got to know the WiFi connection status at ESP end by WiFi.status() finction.
Is there any way out to know about internet connectivity of client which is PC in my case.
Because when PC losing its internet connectivity then ESP is getting no notification about it.
Is there way out to notify ESP32 about client connectivity?
Regards
Akansha
think about it for a second... it the PC has no connectivity, how would he let the ESP know about it ? give it a phone call? shout loud enough to be heard?
Again When the PC is done sending a request, it's disconnected. There is no heartbeat (unless you implement one) that will say "the PC has a working internet connexion and can reach the ESP".
(if you were to implement a server function on the PC, the ESP could try to reach out and see if the PC answers)
"Is there any way out to know about internet connectivity of client which is PC in my case.
Because when PC losing its internet connectivity then ESP is getting no notification about it."
Kind of clunky, but you might put a meta refresh web page in a browser that simply sends "ok" on a selected time interval to the ESP server. The ESP server then might have code that checks for the receipt of the "ok" request from the client on a timed interval. If the "ok" is not received, then the ESP can do some type of notification.
If you want to test whether Internet is available, you can periodically ping some random, high-reliability server, like google.com. If you can't reach it, odds are the Internet is down.
J-M-L:
Yep, that would be a way to do the heartbeat. not receiving it might mean that the cat walked on the keyboard and closed the browser window
Been a long time, but I think in the past I've used IE to send client request by using a command line in a batch file, which itself could be executed by the windows scheduler application.
RayLivingston:
If you want to test whether Internet is available, you can periodically ping some random, high-reliability server, like google.com. If you can't reach it, odds are the Internet is down.
As you mentioned that i should ping a reliable server then i gone through ping library.
I am able to ping server like google.com, using ESP32 ,
Is there any way to ping this server (google.com)from my client and return status to ESP32 which is acting as server.
library WiFi.ping can ping any server(google.com) using ESP32 ans also can ping any device, but is there any possibility of pinging google.com from device (client/PC) and return the status to ESP32?
Regards
Akansha
you can write a program on your PC pinging the world and then calling an http (or anything else) service on your esp32. It’s just a matter of coding (and has nothing to do with arduino programming). On Linux or on a Mac à simple cron Shell script can do that in the background with very few lines of code - probably the same with PowerShell on Windows