Good Morning I'm using blynk from a network, how can I add another network in the program?


#define BLYNK_PRINT Serial


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

char auth[] = "___________________________";

char ssid[] = "Anderson_oliv";
char pass[] = "__________________";


const int ledPin18 = 18;
const int ledPin19 = 19;
const int ledPin21 = 21;
int valor = 1;
int valor_5 = 0;

   BLYNK_WRITE (V5){  
   int valor_5 = param.asInt();
   Serial.print("V5 Slider value is: ");
   Serial.println(valor_5);
  } 


void setup()
{ 
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);


  pinMode (ledPin18, OUTPUT);
  pinMode (ledPin19, OUTPUT);
  pinMode (ledPin21, OUTPUT);

  digitalWrite (ledPin18, LOW);     
  digitalWrite (ledPin19, LOW);
  digitalWrite (ledPin21, LOW);
  
}

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

I don’t understand you… what is what you are asking? You want to use 2 differents SSIDs at the same time in your project? With only 1 wifi device? is this what you want? if is this… you can’t… you need at least 2 wifi devices one per each ssid… (ESP devices can make 1 wifi ap at the same time is connected to another wifi device… like a router… but can’t be connected to 2 different router at the same time)

in fact, it would not be at the same time, if it is not in the area of a connection, the device enters the other one already registered.

Yes, you can check if ESP device is connected or not, you can search near ssid… and if you know ssid and password of your wifi networks… you can do it without problems… but you must do it manually due to ESP can’t remember 2 different SSIDs like a smartphone do…

I understand.
is it not even possible to search for a second network?
Can I create a button, when the button is pressed it searches the other network?

I don’t know if you can search another ssid while ESP is already connected (i think taht no)… but you always can use a button to start a function that disconnect from actual ssid… make a search, select know ssids and if you can connect to more than 1 near ssid… you can select the ssid with the biggest strength and connect after select it…

Or make the program starts that function after detect a connection loss… automatically…

104/5000
in case I can use a button to disconnect from the network, then it is possible for the program to restart in another network?

Yes, that could be done using EEPROM to program different startup routines and/or networks.

And without using EEPROM :wink:

1 Like

It’s been discussed a few times already:
https://community.blynk.cc/search?q=Backup%20ssid

Pete.

You can use a button to disconnect from a network and without restart the program you can connect to another network or 5 or even 1000 different ssids… one at time of course

Great.
Would you have a sample program?
So that I can change my

No, i don’t have any example, but if you like send me your code by pm and i’ll use it as a base to make an example for you…

include second network

name: net_2
password: abc123456

if possible, an aid

The initial code I created was this one.

#define BLYNK_PRINT Serial


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

char auth[] = "___________________________";

char ssid[] = "Anderson_oliv";
char pass[] = "12345678ABC";


const int ledPin18 = 18;
const int ledPin19 = 19;
const int ledPin21 = 21;
int valor = 1;
int valor_5 = 0;

   BLYNK_WRITE (V5){  
   int valor_5 = param.asInt();
   Serial.print("V5 Slider value is: ");
   Serial.println(valor_5);
  } 


void setup()
{ 
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);


  pinMode (ledPin18, OUTPUT);
  pinMode (ledPin19, OUTPUT);
  pinMode (ledPin21, OUTPUT);

  digitalWrite (ledPin18, LOW);     
  digitalWrite (ledPin19, LOW);
  digitalWrite (ledPin21, LOW);
  
}

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

This is an example with one switch to select a wifi between 2. With some changes (using a button instead a switch) you can connect with dozens of wifis… or more :smiley:

I don’t have your hardware, check if this works for you.
With Interrupts:

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>


#define ledPin18 18
#define ledPin19 19
#define ledPin21 21
#define ButtonPin 12 // change this to a pin where you can use attachinterrupt with your hardware

int valor = 1;
int valor_5 = 0;
char auth[] = "___________________________";

BLYNK_WRITE (V5)
{  
  int valor_5 = param.asInt();
  Serial.print("V5 Slider value is: ");
  Serial.println(valor_5);
} 

void MakeConnect(int Wssid)
{
  Blynk.disconnect();
  Blynk.config(auth);
  switch (Wssid)
  {
    case 0:
      Blynk.connectWiFi("Anderson_oliv","12345678ABC");
    break;
    case 1:
      Blynk.connectWiFi("net_2","abc123456");
    break;
  }
}
void ChangeConnect()
{
  MakeConnect(digitalRead(ButtonPin)); // HIGH==TRUE==1, LOW==FALSE==0
}
void setup()
{ 
  Serial.begin(115200);
  pinMode (ledPin18, OUTPUT);
  pinMode (ledPin19, OUTPUT);
  pinMode (ledPin21, OUTPUT);
  pinMode (ButtonPin,INPUT_PULLUP);
  digitalWrite (ledPin18, LOW);     
  digitalWrite (ledPin19, LOW);
  digitalWrite (ledPin21, LOW);
  ChangeConnect();
  attachInterrupt(digitalPinToInterrupt(ButtonPin), ChangeConnect, CHANGE);
}

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

Without it:

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Tasker.h>


#define ledPin18 18
#define ledPin19 19
#define ledPin21 21
#define SwitchPin 12

int valor = 1;
int valor_5 = 0;
char auth[] = "___________________________";
bool PrevState=false;
Tasker Task(true);

BLYNK_WRITE (V5)
{  
  int valor_5 = param.asInt();
  Serial.print("V5 Slider value is: ");
  Serial.println(valor_5);
} 

void MakeConnect(int Wssid)
{
  Blynk.disconnect();
  Blynk.config(auth);
  switch (Wssid)
  {
    case 0:
      Blynk.connectWiFi("Anderson_oliv","12345678ABC");
    break;
    case 1:
      Blynk.connectWiFi("net_2","abc123456");
    break;
  }
}
void ChangeConnect()
{
  PrevState=digitalRead(SwitchPin);// HIGH==TRUE==1, LOW==FALSE==0
  MakeConnect(PrevState); 
}
void CheckSwith()
{
  if (digitalRead(SwitchPin)!=PrevState) ChangeConnect();
}
void setup()
{ 
  Serial.begin(115200);
  pinMode (ledPin18, OUTPUT);
  pinMode (ledPin19, OUTPUT);
  pinMode (ledPin21, OUTPUT);
  pinMode (SwitchPin,INPUT_PULLUP);
  digitalWrite (ledPin18, LOW);     
  digitalWrite (ledPin19, LOW);
  digitalWrite (ledPin21, LOW);
  ChangeConnect();
  Task.setInterval(CheckSwith,3000);
}

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

I’m going to take the test here.
Thank you.

Good evening.

I tried to use the example you showed, I did not succeed.
I made a new program, with only 3 leds to turn on / off, where I can understand.

Take a look where I may have been wrong, because the code is not working.

The hardware is only with 3 buttons, as simple as possible

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
//---------------------------------------------------------------------------------
#define ledPin12 12  
#define ledPin13 13
#define ledPin14 14       
#define ButtonPin 25      

//-----novo--------------------------------------------------------------------------
char auth[] = "____________________";//ok

//------------------------------------------------------------------------------------
void MakeConnect(int Wssid)
{
  Blynk.disconnect();
  Blynk.config(auth);
  switch (Wssid)
  {
    case 0:
      Blynk.connectWiFi("Anderson_oliv","________");
    break;
    case 1:
      Blynk.connectWiFi("notebook","_________");
    break;
  }
}
//----novo-----------------------------------------------------------------------------
void ChangeConnect()
{
   MakeConnect(digitalRead(ButtonPin)); // HIGH==TRUE==1, LOW==FALSE==0
 }
 
//---------------------------------------------------------------------------------
 void setup()
{
  Serial.begin(115200);
  
  pinMode (ledPin12, OUTPUT);
  pinMode (ledPin13, OUTPUT);
  pinMode (ledPin14, OUTPUT);
  pinMode (ButtonPin,INPUT_PULLUP);
  ChangeConnect();
  attachInterrupt(digitalPinToInterrupt(ButtonPin), ChangeConnect, CHANGE);
}

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

As i said i don’t have your hardware… i’ll try to make a port with my hardware and check if it works

Thank you for your help

This is the app I used for testing.