ESP32 freezes for a couple of seconds when the Wifi network is lost.

rjrajbir
Posts: 5
Joined: Mon Jun 10, 2019 5:51 am

ESP32 freezes for a couple of seconds when the Wifi network is lost.

Postby rjrajbir » Wed Jun 19, 2019 5:38 am

Hi, When I turn off the Wi-Fi router, the LED starts to interrupt the blinking after it is restored. As soon as I turn on the router again, the LED stops flashing, it happens several times, and then everything works fine. Probably the loop starts to slow down while working on connecting to Wifi. How can I avoid this?

I have the following sketch:

Code: Select all

#include <WiFi.h>
#include <WebSocketsClient.h>

unsigned int timer;

void setup() {
  pinMode(2, OUTPUT);
  /* Connect Wifi Network */
 WiFi.begin("SSID", "PASS");
  /* Connect WebSocket Server */
  webSocket.begin("ip", 2342, "/"); // Connect WebSocket Server
  webSocket.onEvent(webSocketEvent); // Set WebSocket Event Function
  webSocket.setReconnectInterval(5000); // Set WebSocket Reconnect Interval
}

void loop() {
  webSocket.loop();
  if((millis() - timer) >= 250) {
   if(digitalRead(2) == LOW) {
     digitalWrite(2, HIGH);
   } else {
     digitalWrite(2, LOW);
   }
   timer = millis();
 }
}

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
   String payload_str = String((char*) payload);
   const char* payload_set_str = payload_str.c_str();
	switch(type) {
		case WStype_CONNECTED:			
			break;
		case WStype_TEXT:
     	break;
  }
}

Who is online

Users browsing this forum: Baidu [Spider] and 109 guests