Unable to connect my board ESP32 to Hotspot

Hi, I’m working in my project that it’s giving a big headache because for a time i had success to connect my board to hotspot and i was testing the DHT11 sensor, but for a moment the board didn’t connect anymore. When I connect it via my phone’s Hotspot, Blynk shows that it is offline and will not connect and sometimes shoes that is connected and the board is resetting immediately. What is causing this?

#define BLYNK_TEMPLATE_ID "TM********i"
#define BLYNK_TEMPLATE_NAME "Avicultor2023"
#define BLYNK_AUTH_TOKEN "Blk******************"

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHT.h"

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,4);

bool fetch_blynk_state = true;  //true or false
char auth[] = BLYNK_AUTH_TOKEN;//Paste auth token you copied

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "The ***";
char pass[] = "nana**************";

#define DHTPIN 32      
#define wifiLed 2

#define DHTTYPE DHT11     // DHT 11

#define VPIN_t      V0
#define VPIN_h      V1

int wifiFlag = 0;


BlynkTimer timer;

void sendSensor()
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, h); // select your virtual pins accordingly
  Blynk.virtualWrite(V0, t); // select your virtual pins accordingly

void checkBlynkStatus() { // called every 2 seconds by SimpleTimer

  bool isconnected = Blynk.connected();
  if (isconnected == false) {
    wifiFlag = 1;
   Serial.println("Blynk Not Connected");
     lcd.print("Mod Manual");
    digitalWrite(wifiLed, LOW);
    digitalWrite(wifiLed, HIGH);
  if (isconnected == true) {
    wifiFlag = 0;
    if (!fetch_blynk_state){
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Blynk.virtualWrite(VPIN_Wsensor_1, toggleStW1_1);
    Blynk.virtualWrite(VPIN_Wsensor_2, toggleStW1_2);
    Blynk.virtualWrite(VPIN_Wsensor_3, toggleStW1_3);
    digitalWrite(wifiLed, HIGH);
    Serial.println("Blynk Connected");
//    sendData();
   // lcd.clear();
     lcd.print("Mod Web On");

  // Request the latest state from the server
  if (fetch_blynk_state){
   // Blynk.syncVirtual(VPIN_BUTTON_0);
   // Blynk.syncVirtual(VPIN_BUTTON_1);
    //Blynk.syncVirtual(VPIN_MQ2, mq2Val );
   // Blynk.syncVirtual(VPIN_LDR, ldrVal);  
void setup()
  // Debug console
 // lcd.begin();
    pinMode(wifiLed, OUTPUT);
  digitalWrite(wifiLed, LOW);

  //Blynk.begin(auth , ssid, pass);
  WiFi.begin( ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,43,21), 8080);

timer.setInterval(2000L, checkBlynkStatus); // check if Blynk server is connected every 2 seconds
  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
  if (!fetch_blynk_state){
   // Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
   // Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    //Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    //Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
  lcd.setCursor(4, 0);
  lcd.setCursor(1, 1);
  lcd.print("Automatico ESP32");

void loop()
} ```

Like this Pete?

@Anderson1 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:

Copy and paste these if you can’t find the correct symbol on your keyboard.


1 Like

Dear Pete, i did the thing that you suggested.

Okay, your code is a bit of a mess, and I assume that it’s not something you’ve written yourself.

I’d suggest that you stop using all of the flags to indicate if WiFi or Blynk is connected, because these are part of the mess within the code.
I’d also remove all of the commented-out code too.

When you connect an ESP32 to WiFi it takes more than this to consistently get a successful connection…

If you do a…

test and it’s false (not connected) then that could be because WiFi isn’t connected. Without WiFi you will never connect to the Blynk server.
So, you need to do two tests - is WiFi connected and is Blynk connected.

The Blynk.config() command can also accept an optional timeout period in millis. Without this, the default timeout is around 18 seconds. You shouldn’t go for a timeout of less than about 2500 millis though, as it takes a couple of seconds to negotiate the Blynk connection.

Also, every time your code encounters a Blynk.run() command it will try to re-connect to Blynk, and if this isn’t possible you’ll encounter the timeout period (18 seconds in your case). To avoid this you need to put Blynk.run() inside a logical Blynk.connected() test (an if statement).

You also need to ensure that your test of WiFi and Blynk connectivity runs far less frequently than your Blynk.config timeout period.

Do some forum searches for Blynk.config() and timeout and you’ll see examples of how to do all of this.


Thanks Pete

Hi Anderson1. I had bizzarre Wifi issues off my phone hotspot when working on esp32. I noticed a fleeting message from a text box serial monitor that amongst garbage, "Too many connections to hotspot (5). So, I connected a wireless access point to the back of my imac by lan cable, , shared the Macs Internet’ from its connection to my iphone ten. on Mac, Preferences, Sharing. fixed my issue. lost weeks of work tracking it down,

1 Like