Connection switching

Hi everyone, I need some help for my coding. Is it possible to program this and how to do it?

When ESP32 power is ON, I want to check the wifi connection, if the connection is successful, then wifi be used to send data to Blynk. But, if the wifi connection is unsuccessful, will switch to using GSM to send data to BLYNK.
And during the power on, it can also switch the connection itself(so put it in loop and always check connection?).

void loop()
{
  Blynk.run();
  timer.run();
  if (WiFi.status() == WL_CONNECTED)
   {
  Blynk.begin(auth, ssid, pass2);
}
else {
  Blynk.begin(auth, client, apn, user, pass);
}
}
```

I don’t think you’d want to use Blynk.begin, as that’s a blocking command and it attempts to create the internet connection for you, but in the case of WiFi you already have that connection created
You’d probably be far better to use Blynk.config and manage the connection(s) yourself, then use Blynk.connect and put Blynk.run inside a Blynk.connected if test to ensure that it’s not executed when there is no connection.

Pete.