BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

ESP32 cannot auto connect to WiFi


#1

Hi friends. can anyone help me why ESP32 cannot auto connect to wifi network ? is problem with void loop ? or … ?

my sketch:

#include <HardwareSerial.h>
#include <TinyGPS++.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>

TinyGPSPlus gps; // The TinyGPS++ object
HardwareSerial ss(1);

SimpleTimer timer;

char auth[] = "8b7e5fc4e68d43d9862145bbbcf0c136";
char ssid[] = "MikroTik Home";
char pass[] = "12345678";
char server[] = "10.5.51.3";

//unsigned int move_index;
unsigned int move_index = 1;
bool simulation = false;
bool IranHack = false; 
    
WidgetMap myMap(V15);

void setup()
{
  Serial.begin(115200);
  Serial.println();
  ss.begin(9600, SERIAL_8N1, 16, 17);
  Blynk.begin(auth, ssid, pass, server, 8080);
  timer.setInterval(5000L, checkGPS);
  timer.setInterval(2000L, check);
}

void checkGPS(){
  if (gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    Blynk.virtualWrite(V18, "GPS ERROR");
    Blynk.virtualWrite(V16, "--------");
    Blynk.virtualWrite(V17, "--------");
  }
}

void displayInfo()
{ 
  if (gps.location.isValid() || simulation == true || IranHack == true)
  {
    Blynk.virtualWrite(V18, "GPS OK");
    float latitude = (gps.location.lat());
    float longitude = (gps.location.lng());

    if(latitude == 0 && longitude == 0 )
    {
      Blynk.virtualWrite(V16, "--------");   
      Blynk.virtualWrite(V17, "--------");
      Blynk.virtualWrite(V18, "0,0");
    }
    Serial.print("LAT:  ");
    Serial.println(latitude, 6);
    Serial.print("LONG: ");
    Serial.println(longitude, 6);
      
    Blynk.virtualWrite(V16, String(latitude, 6));   
    Blynk.virtualWrite(V17, String(longitude, 6));  

    myMap.location(move_index, latitude, longitude, "ESP32Location");
  }
  else
  {
    Serial.print(F("INVALID"));
    Blynk.virtualWrite(V18, "GPS INVALID");
    Blynk.virtualWrite(V16, "--------");   
    Blynk.virtualWrite(V17, "--------");  
  }

  Serial.println();
}

void check()
{
  if(simulation == true || IranHack == true)
  {
   displayInfo();
  }
  else
  {
    while (ss.available() > 0)
      if (gps.encode(ss.read()))
        displayInfo();
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}

thanks


#2

@ErfanDL Can you paste the serial monitor output?

Try blynk.config instead of blynk.begin and see if it connects.

Edit: It would be better to manage the connections in sequence. Wifi first, see if it connects and then blynk connect. Use of BLYNK_CONNECTED() will also allow you to print some info or turn on/off LEDs as indicators.


#3

thanks for reply
here SM output

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371 
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13256
entry 0x40078a90

[18] Connecting to MikroTik Home
[3592] Connected to WiFi
[3592] IP: 10.5.50.15
[3592] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.1 on ESP32

[3597] Connecting to 10.5.51.3:8080
[3636] Ready (ping: 15ms).
LAT:  32.xx
LONG: 51.xx

LAT:  32.xx
LONG: 51.xx



[8637] Connecting to 10.5.51.3:8080

#4

@ErfanDL You could do a timed routine to check wifi connection and reconnect or have a set of set of statements in loop() to check for wifi or blynk connections. Ideally, blynk.run() should re-establish the blynk connection which in turn will re-establish the wifi connection. It works like that for me.


#5

thanks. is any example for blynk.config ?


#6

Can anyone help?


#7

https://community.blynk.cc/search?q=Auto%20reconnect

Pete.


#8

And this here is for ESP8266, but only a few library changes needed for ESP32


#9

Try not using a space in your SSID. That might help…


#10

Is the server’s IP correct?


#11

That would be the OPs Local Server… and it seems correct on initial boot

image