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

How I can use multiple wifi network

Hi everybody

How I can do more than one wifi network.
Because I’m making is a portable device and hence we will be using it in different locations.
I’m using Arduino uno and ESP8266.

char ssid[] = “xxxxxxxxxxxxx”;

char pass[] = “xxxxxxxxxx”;

I mean If one network not available trying to other one.

You can explain more please

@Moosa Please read the How It Works section of the above link, it explains it in as much detail as anyone here could.

And that is just one way of picking any available WiFi connection in the area of your device.

If you have pre-set WiFi options, then you can set up something similar to how typical re-connection management works for reconnecting if Server link is lost… only using different connections each time.

  • Boot…

  • Try to connect to A… if after x time with no connection…

  • Try to connect to B… if after x time with no connection…

  • Try to connect to C… if after x time with no connection… curl up and have a nap.

You are going to have to figure most of this out, as no one is going to code it all for you.

1 Like

Thanks

I’m use Arduino uno with ESP8266

 #include <ESP8266WiFi.h>        
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>      

void setup() {
  Serial.begin(115200);
    WiFiManager wifiManager;
  wifiManager.setTimeout(180);
 
  if(!wifiManager.autoConnect("AutoConnectAP")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    ESP.reset();
    delay(5000);
  } 

  Serial.println("connected...yeey :)");
 
}

void loop() {

}

I get Error compling for board
When I using with NodeMcu It is works. How I can use in arduino uno?

Totally different process… requiring a different library and setup.

You should read though the Documentation and Help Pages.

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware

To make you clear I uesed this code and everything fine but I’m asking if any method to get multiple wifi networks

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>

char auth[] = "xxxxxxxxxxxxxccxxxxxxxxxxxx";

char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxxx";

//#define EspSerial Serial


#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // TX, RX

#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

#define DHTPIN 7


#define DHTTYPE DHT11     // DHT 11

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

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

//****************************************  
   Serial.print("Humidity: ");
  Serial.print(h);
Serial.println (" % ");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println (" C ");
 //*******************************

  if (isnan(h) || isnan(t)) {
  }
  
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  
}

void setup()
{

  Serial.begin(9600);


  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

  dht.begin();

  timer.setInterval(1000L, sendSensor);
}

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

Because I’m making is a portable device and hence we will be using it in different locations.

If I can make multiple ssid & pass.

I take it that you didn’t like @GTT’s suggestion of hard-coding multiple SSIDs and passwords then trying to connect to each in turn?

Pete.

Thanks for trying to help
That you mean need to be known which ssid used to put in the code.
Any method can use like wifimanager. I mean no need enter the ssid & pass in the code for my program.

Then use WiFi Manager (linked above)… that is the best way to do it without hard coding… period.

1 Like

That’s not available for shield connections.

@Moosa use the ESP as an ESP, not a shield and use the Arduino as a shield. Then you can use WiFiManager.

2 Likes

Right you are :blush: … so many repeated “how can I use” that I got confused (it happens :innocent:).

1 Like

Just a suggestion here if you use a board with WiFi like the ESPxxxx boards.

I used to use the wifimanager but have developed a small bit of code that on boot will scan the available wifis and dynamically select and connect to the strongest wifi without the need for a web interface. It will also check connection periodically and if there is a disconnect then it will reset and select the best wifi. I have about 15 devices around the property with about 6 available wifis. This setup means I don’t need to play around with resetting the wifi via coding or wifimanager as I move them around the property. It just does it itself.

The Blynk interface looks like this. I use the device selector to select the device. You will see I have a button which rescans the available wifis and this populates a menu so I can reselect the wifi on the fly.

If you are interested in the code I can make it available on an as is where is basis :slight_smile:

I have no passwords on my wifi so that makes the above very easy. If you have passwords then it probably doesn’t work :slight_smile:

I want to share my decision. I use this code if, for example, I take the device from home to work where there are different wi-fi networks, or if I want to connect on the street, I simply distribute wi-fi from a mobile access point on my phone.
Please note that if none of the listed networks is still connected, the program will still work offline, unlike the standard Blynk.begin (auth, ssid, pass);
If there is a solution easier and more interesting I will be glad to discuss. :slightly_smiling_face:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "your_token";
char* ssid[] = {"ssid_1","ssid_2","ssid_Mobil"}; //list a necessary wifi networks
char* pass[] = {"pass_1","pass_2","pass_Mobil"}; //list a passwords

void setup()
{
  Serial.begin(9600);
  MultyWiFiBlynkBegin(); //instead Blynk.begin(auth, ssid, pass);
}

void MultyWiFiBlynkBegin() {
  int ssid_count=0;
  int ssid_mas_size = sizeof(ssid) / sizeof(ssid[0]);
  do {
    Serial.println("Trying to connect to wi-fi " + String(ssid[ssid_count]));
    WiFi.begin(ssid[ssid_count], pass[ssid_count]);    
    int WiFi_timeout_count=0;
    while (WiFi.status() != WL_CONNECTED && WiFi_timeout_count<50) { //waiting 10 sec
      delay(200);
      Serial.print(".");
      ++WiFi_timeout_count;
    }
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("Connected to WiFi! Now I will check the connection to the Blynk server");
      Blynk.config(auth);
      Blynk.connect(5000); //waiting 5 sec
    }
    ++ssid_count; 
  }
  while (!Blynk.connected() && ssid_count<ssid_mas_size);
  if (!Blynk.connected() && ssid_count==ssid_mas_size) {
    Serial.println("I could not connect to blynk =( Ignore and move on. but still I will try to connect to wi-fi " + String(ssid[ssid_count-1]));
  }
}

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

То же самое на родном русском языке. Код для проверки и подключению к нескольким wi-fi сетям. Я использую этот код, если устройство к примеру уношу из дома на работу где разные wi-fi сети, или если хочу подключиться на улице просто раздаю wi-fi с мобильной точки доступа на своем телефоне.
Обратите внимание, что если ни одна из перечисленных сетей все таки не будет подключена, программа все равно будет работать в офлайн, в отличии от стандартного Blynk.begin(auth, ssid, pass);

1 Like

Ok , I tried this on my test sketch and I’m happy to report that this indeed works, with hidden SSID’s too !! :raised_hands:

My only gripe is this :sweat_smile:

while (!Blynk.connected() && ssid_count<ssid_mas_size);
if (!Blynk.connected() && ssid_count==ssid_mas_size) {
Serial.println("I could not connect to blynk =( Ignore and move on. but still I will try to connect to wi-fi " + String(ssid[ssid_count-1]));
}

with this,even if it doesn’t connect to Blynk Servers it stays connected to that Access point (“Ignore and move on. but still I will try to connect to wi-fi”) . Somewhat defeating the whole purpose of redundancy (Connect to the access point that has internet connectivity or else try the next one ).Any ideas for this ?

@blink_fast please don’t post the same thing in multiple places, it gets very messy when people start responding to both and the two conversations diverge.

Anyone wanting to respond top @blink_fast’s question please do so here:

I’ve temporarily locked this topic.

Pete.

This topic was automatically opened after 6 days.