How to Connect Blynk IoT Device to Any Wi-Fi Network Without Re-uploading Code?

Hey Guys,

I recently used the Blynk IoT Platform to build a project with NodeMCU8266 called "Weather Monitoring System." I started with the following code to control an LED:

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""


#define LED D2


// Include required libraries
#include <ESP8266WiFi.h>          // Handles Wi-Fi connection
#include <BlynkSimpleEsp8266.h>   // Blynk library for ESP8266


// Wi-Fi credentials (update these with your network details)
char ssid[] = "";          // Wi-Fi SSID
char pass[] = "";      // Wi-Fi Password


BLYNK_WRITE(V0)
{
  int value = param.asInt();  // Read incoming value (0 or 1)


  if (value == 1) {
    digitalWrite(LED, HIGH);  // Turn LED ON
    Serial.println("LED ON");
  } else {
    digitalWrite(LED, LOW);   // Turn LED OFF
    Serial.println("LED OFF");
  }
}


void setup()
{
  Serial.begin(115200);      // Start Serial Monitor
  pinMode(LED, OUTPUT);      // Configure LED pin as output
  digitalWrite(LED, LOW);    // Start with LED OFF


  // Connect to Wi-Fi and Blynk Cloud
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}


void loop()
{
  Blynk.run();  // Continuously handle Blynk events
}

Right now I have to hardcode the Wi-Fi credentials for each access point in the sketch. Since I travel between states, it’s impractical to re-upload the code every time I change networks.

Is there a way to let the device connect to any Wi-Fi and configure it without reflashing? If you have any ideas or suggestions, please share them below.

Thanks,
Rifat

You could consider using WiFimanager.h or create your own webserver to do something similar.

Isn't this possible with ESP8266WiFi.h?

That just manages WiFi connection, but if you want to change the credentials on the fly, you will need some way of having the user enter these. For that you could use a Webserver you create yourself, or use a ready-made solution.
If you have multiple credentials that you know at compile time, you could though.

Thank you. Let me try and let you know!

I found a example file named Edgent_ESP8266 which first make a hotspot then allow esp8266 connect to Wifi using Blynk App. Do you have any idea with it?

Add functionality to input hotspot name and password . E.g. this device could do the trick (2 versions one with buttons and the other one with pot and a button) https://youtu.be/tpUkqxKpRVE, https://youtu.be/Iueek8hVl8E. So you use this device to enter both and then you initiate connectivity based on those input values