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

@Anderson_oliv:

One remarks from my side:
I see you use:

attachInterrupt(digitalPinToInterrupt(ButtonPin), ChangeConnect, CHANGE);

I don’t think this what you want and it most likely cause a problem.
With this setting the interrupt is triggered when you press the button AND when you release it because you use “CHANGE” as a trigger.
This will cause “ChangeConnect()” to be called a second time before it has even finished.

With …

pinMode (ButtonPin,INPUT_PULLUP);

… defined (i.e. button is low active) I’d strongly suggest to use:

attachInterrupt(digitalPinToInterrupt(ButtonPin), ChangeConnect, FALLING);

It will then only trigger once you press the button - not on release.

Side note: There is not need to define …

  pinMode (ledPin12, OUTPUT);
  pinMode (ledPin13, OUTPUT);
  pinMode (ledPin14, OUTPUT);

… in this particular case as this is handled by Blynk internally already if you use the digital pins gp12,gp13 and gp14 with your buttons.

The example code was for to be used with a switch not with a button… So interrupt with “CHANGE” must work properly…

… sure it will, if the debouncing of the switch is done properly - either in hardware or in the program.

I will make these changes.
but I did not quite understand how to position the information that passed

Mmm we are talking about change the wiffi settings with a swtich… not about turn on/off the leds… you didn’t wrote the code for do it…

The wifi switch don’t work properly?

I agree with you. The LEDs are only to test that it connected to the blynk

No, it does not connect to the wifi. :sweat_smile:

I’m doing a example for you with my hardware now, i’ll post it when finish…

Here is the example, i’m using an Arduino Uno with an ESP8266 shield…

#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Tasker.h>

#define PinSwitch 2
#define ESP8266_BAUD 115200

int PrevValue=0;
char auth[] = "abcdefgh";
char SSID1[] = "NETGEAR";
char Pass1[] = "123456789";
char SSID2[] = "Belkin";
char Pass2[] = "987654321";

SoftwareSerial EspSerial(4,5); // RX, TX
Tasker Task(true);

ESP8266 wifi(&EspSerial);

void MakeConnect()
{
  if (Blynk.connected()) Blynk.disconnect();
  switch (PrevValue)
  {
    case 0:
      Serial.println("Switch Changed to 0");
      Blynk.begin(auth,wifi,SSID1,Pass1);
    break;
    case 1:
      Serial.println("Switch Changed to 1");
      Blynk.begin(auth,wifi,SSID2,Pass2);
    break;
  }
}
void Changed()
{
  int Value=digitalRead(PinSwitch);
  if (PrevValue!=Value)
  {
    Serial.println("changed");
    PrevValue=Value;
    if (Task.scheduledIn(MakeConnect))  Task.cancel(MakeConnect);
    Task.setInterval(Changed,2000);
    Task.setTimeout(MakeConnect,500);
  }
}
void setup()
{
  Serial.begin(115200);
  EspSerial.begin(ESP8266_BAUD);
  pinMode(PinSwitch,INPUT_PULLUP);
  PrevValue=!digitalRead(PinSwitch);
  Changed();
}

void loop()
{
  if (Blynk.connected())  Blynk.run();
  Task.loop();
}

And here the Blynk Log:

[500] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.3 on Arduino Uno

  Give Blynk a Github star! => https://github.com/blynkkk/blynk-library

[1014] Connecting to NETGEAR
[14047] AT wersion:1.3.0.0(Jul 14 2016 18:54:01(
SDK vershon:2.0.0(5a87501,CLOSED

[21318] +CIFSR:STAIP,"10.0.0/6"
+CIFSR:STAMAC,"b4:e7:2d:23:03:7d"
[21319] Connected to WiFi
[67961] Ready (ping: 12ms).
[69036] Disconnected
Switch Changed to 1
[69036] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.3 on Arduino Uno

  Give Blynk a Github star! => https://github.com/blynkkk/blynk-library

[69552] Connecting to Belkin
[82586] AT vdrsion:1.3.0/0(Jul 14 2006 18:54:01(
SDK version:2.0.0(5a8751
[88843] +CIFSR:ST@IP,"192.168/1.34"
+CICSR:STAMAC,"c4:e6:2d:23:03:7d"


[88844] Connected to WiFi

You must deal with the others parts (led, blynk communication, etc) by yourself.

Thank you.
I’ll test on my ESP-32 card