Multiple SSID's With ESP8266 as Arduino Shield

Hi all,

I have searched around and tried for a few days to include multiple SSID’s in my Blynk code. The idea is that if the device is at my uni house or home it will still connect.

This is an example of one of the methods I have tried. The project uses an esp8266 which is used as a wifi shield with an arduino mega.

The code gets stuck after the first Blynk.begin and the serial monitor says “failed to connect to wifi”

Thanks for any help.


void setup()
{
 ucg.begin(UCG_FONT_MODE_SOLID);
 ucg.clearScreen(); 
  //ucg.setFont(ucg_font_inr38_mr);
ucg.setFont(ucg_font_inr16_mr); 
ucg.setRotate270();

  Serial.begin(115200);

  EspSerial.begin(115200);
  delay(5000);
 
connection();

flash=0;
buttonvalue = digitalRead(button);
  timer.setInterval(1000L, myTimerEvent);

  
  
}

BLYNK_CONNECTED() {
  Serial.println("connected");
  ReCnctCount = 0;
}

void connection()
{
   Blynk.begin(auth, wifi, "SSID", "pswd");

   while (Blynk.connect() == false) {
      Blynk.begin(auth, wifi, "SSID2", "pswd2");
            
   }
}


Blynk.begin is a blocking function. If it can’t connect to either the specified SSID or to the Blynk server then code execution will stop at that point.

You should research manual connection to WiFi, followed by the use of Blynk.config and Blynk.connect.

It’s a subject that’s been covered many times in the past on this forum.

Pete.

Thanks Pete, i’ll look into it.

Thanks for putting me in the right direction Pete. Added this to my setup and it works great.

 Serial.begin(115200);

  EspSerial.begin(115200);
  delay(5000);
 Serial.println("connecting to hotspot");
 Blynk.config(wifi, auth, "blynk-cloud.com", 80);
 Blynk.connectWiFi("ssid", "password");
 Blynk.connect();


if(Blynk.connect()==false)
{
  Serial.println("connecting to wifi");
 Blynk.config(wifi, auth, "blynk-cloud.com", 80);
 Blynk.connectWiFi("ssid1", "password1");
 Blynk.connect();
  
}
1 Like