WiFi connection via network using Captive Portal

Dear Blynk community,

I try to get a WiFi connection via a network using a Captive Portal.

When I log in to the WiFi with my phone, I just have push the “connect” button at the captive portal, which opens automatically, and everything is fine.

When I connect my nodeMCU using the basic Blynk.begin(auth, ssid, pass); , then it successfully connects to the Blynk servers and sends data to the App, but only for like 10 seconds, then no data are sent anymore. After like 60 to 70 seconds, it works again for like 10 seconds, before it stops working againg, and so on…

I assume my code should somehow virtually press that “connect” button on the Captive Portal to have a stable connection. Can anyone help me?

Hardware model + communication type: nodeMCU v3 with ESP8266

Thanks in advance
Max

Are you using Blynk Legacy or IoT ?
Is this the WiFiManager captive portal, or Blynk Edgent?
What do you see in your Serial Monitor?
What version of the Blynk C++ library are you using?

Pete.

Thanks for the quick reply! to your questions

Are you using Blynk Legacy or IoT ?

IoT

Is this the WiFiManager captive portal, or Blynk Edgent?

So it’s not about a captive portal I created on my ESP, but from the provider of the WiFi I want to connect. So the other way round. I want to connect to this WiFi and don’t know how to handle this, since it needs the push on a confirmation button before stable internet connection is provided. But I don’t know how to virtually “push” this button with my code.

What do you see in your Serial Monitor?

After starting I see:

[5076] Connected to WiFi
[5076] IP: 100.80.163.164
[5076] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on ESP8266

 #StandWithUkraine 


[5203] Connecting to blynk-cloud.com:80
[5366] Ready (ping: 21ms).
WIFI connection established.
Writing data: V5: 0, V6: 6
Writing data: V5: 0, V6: 7
Writing data: V5: 0, V6: 8
Writing data: V5: 0, V6: 9

The last lines print every second to indicate what goes to the virtual pins.
On my Blynk App, I receive the data successfully for like 10 seconds, but not any longer. Like 60 seconds later my serial sais:

Writing data: V5: 0, V6: 59
Writing data: V5: 1, V6: 60
Writing data: V5: 1, V6: 61
Writing data: V5: 1, V6: 75
[75344] Connecting to blynk-cloud.com:80
Writing data: V5: 1, V6: 75
[75391] Ready (ping: 23ms).
Writing data: V5: 1, V6: 75
Writing data: V5: 1, V6: 76
Writing data: V5: 1, V6: 77

and the data transmission to my app works again for like 10 seconds.

What version of the Blynk C++ library are you using?

v 1.1.0.

@max2 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your serial monitor text so that it displays correctly.
Triple backticks look like this:
```

In addition, you also need to post your sketch, also with triple backticks, as you are currently connecting to the Legacy cloud server.

Pete.

Alright, I updated my post. Thanks for the hint!

Below you find my sketch:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
//#include <Ethernet.h>
//#include <BlynkSimpleEthernet.h>

char auth[] = "wcFU-eAd8vJ-eUzC4IOnxlbHu45ux-PZ";

char ssid[] = "@BayernWLAN"; // 
char pass[] =  ""; 

BlynkTimer timer;

void myTimerEvent()
{
  Blynk.virtualWrite(V5, millis() / 60000);
  Blynk.virtualWrite(V6, millis() / 1000);
  Serial.print("Writing data: ");
  Serial.print("V5: ");
  Serial.print(millis() / 60000);
  Serial.print(", V6: ");
  Serial.println(millis() / 1000);
  if (WiFi.status() != WL_CONNECTED)
  {
    Serial.println("WIFI connection failed.");
  }
}

void setup()
{
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  if (WiFi.status() == WL_CONNECTED)
  {
    Serial.println("WIFI connection established.");
  }

  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

You need to have the Blynk IoT BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME defined at the top of your sketch, otherwise the compiler treats it as a Legacy sketch and tries to connect it to the wrong server.

Also, I’d expect to see an invalid Auth token message at the moment. Is this an IoT Auth token?

Pete.

Thanks for the response. I will get back to this on monday.

One further question: Since my sketch perfectly works using a different WiFi, I really see the main problem on the captive page of the WiFi as described above. Could you please comment on that?

There’s no way that this can be working perfectly if you’re using Blynk IoT.

Pete.

For other people with the same problem: I found a work around which on the first glance works!

Steps:

  • Log into the WiFi network using any device
  • Push the button on the captive page
  • Write down the device’s MAC address for this connection
  • Deconnect from the WiFi
  • In the setup() of your sketch: Change your ESP’s MAC address to the address of the device before the blynk function starts, see: Get ESP32/ESP8266 MAC Address and Change It (Arduino IDE) | Random Nerd Tutorials
  • Enjoy Blynk with a network using captive pages! :slight_smile:

It is possible to assign a new MAC address to the ESP board: