Questions about WiFi connection in new Blynk platform

Hello everyone!
I’m quite excited about the new Blynk platform, I have not migrated yet since I need to figure out some things first.
I am using an ESP32Thing board, platformIO and C++

In my code I have two sets of Wifi credentials (for net1 and net2), periodically a function is called to check the Wifi connection and tries to reconnect either to net1 or net2, this beacuse the ESP is in a location where it can be disconnected from net1, so i used this to give it another network connection when that happens.
Here’s the function just for reference:


void conectarWifi() 
{
   WiFi.mode(WIFI_STA);
  if(WiFi.status() != WL_CONNECTED) // revisa el estado de conexion
 {
  //Serial.println("desconectado, reintentando en Red1");
  WiFi.begin(Red1.ssid,Red1.pass);
  unsigned long startTime = millis();
  while(WiFi.status() != WL_CONNECTED && millis() - startTime < wifiTimeout )
 {
  delay(10);
 } 
 }  
 if(WiFi.status() != WL_CONNECTED)
  {
  //Serial.println("desconectado, reintentando en Red2");
  WiFi.begin(Red2.ssid,Red2.pass);
  unsigned long startTime = millis();
  while(WiFi.status() != WL_CONNECTED && millis() - startTime < wifiTimeout )
  {
  delay(10);
  } 
 } 
 else{
   // Serial.println("conectado");
     }
 
 } 

Now, my questions are the following:
Can I still implement this method with the new Blynk platform?
Is there another way to give the hardware access to 2 or more WiFi APs?

I am still learning about the new Blynk, any help would be appreciated!

Hi,

Can’t comment specifically on your code, but I have successfully tested a basic sketch that was developed in old Blynk onto new Blynk (Blynk2.0 - Web Dashboard - Map Widget Not Working)

I only had to make a few minor changes to the sketch:

  1. Add two new lines at the start of the sketch (these are generated in the dashboard when you create the template for your device)
#define BLYNK_TEMPLATE_ID "TMPLnnnnFDs"
#define BLYNK_DEVICE_NAME "LED Button"
  1. Added a new Auth Code (again generated when you add a new device).

Everything else worked as expected, including my WiFi connection code.

Sign up (you need a new Blynk 2.0 account) and experiment.
cul
billd

1 Like

Thanks!
I guess your WiFi connection code was the normal “hard-coded” WiFi credentials.
If that is the case I think my code should work too, since it is the same but the only difference is that the hardware has 2 options for WiFi connection.
How does it work with the new App if you change the network you are connected to? the firmware credentials stay as the default when you restart the hardware i guess, but if you change them in the app it just works fine also?
My understanding is that in the new App you can change this in the App directly.

HI Rob,

Yes, the usual hard coded in Arduino IDE and flashed to the MCU (ESP8266 in my case). I do have a few projects that use WiFiManager to allow for connecting to unknown networks, but nothing to do with Blynk, and I haven’t tested this, but it should work - WiFi connection works independent of Blynk unless you choose to integrate it.

The new Blynk does have functionality to allow apps/devices to connect to new WiFi networks, and/or be remotely provisioned with WiFi details, but I have not tested this, and probably won’t.

All my projects are pretty much one-offs, around the house and garage, they stay connected to a fixed network, and I can update them using AdruinoOTA.h - I don’t really need the complexity of adding this into Blynk code as well (Basically I just use Blynk as a mobile dashboard to visualize data from devices/sensors, and control outputs on devices).

I think your WiFi code should work OK as it’s independent of Blynk.
cul
billd

1 Like

We currently don’t support multiple wifi networks with WiFi provisioning. If you believe that this is something many can benefit from, please post a feature here

If you need 2 credentials you would need to pre-define them in code and code your own switching logic.

1 Like

Hi Bill
Thanks for the help!! I have a better understanding now

Oh I see, thanks!
Maybe it is a commodity and not a necessity, for example our smartphones connect automatically to previously known WiFi networks and that commodity has become a feature.
I think in the future that feature would be helpful for other hardware connected to the internet like the many devices using Blynk.
But if the firmware option still works I’m fine with that. :slight_smile:

1 Like