BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Hanging up at Blynk.begin()

I’m trying a very basic test with Blynk 2.0 and an ESP32 in Platform IO. I have no problems connecting this ESP32 to my WiFi network under other circumstances, but it just hangs at the Blynk.begin() command. I’m at a loss here.

platformio.ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = blynkkk/Blynk@^1.0.1

main.cpp

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"

char auth[] =  BLYNK_AUTH_TOKEN;
char ssid[] = "xxx";
char pass[] = "xxx";

void setup() {
  // establish serial comms ...
  Serial.begin(9600);
  while(!Serial) {;}                // wait for connection
  Serial.printf("\n\nGreetings!\n");

  Blynk.begin(auth, ssid, pass);
  Serial.print("Blynk connected?: "); Serial.println(Blynk.connected());
}

void loop() {
  Blynk.run();
}

Your template ID and device name need to be at the very top of your code.

Otherwise the Blynk library will see the sketch as a Legacy sketch and try to connect your device to the Legacy servers and that will fail with an Invalid Auth token error.

Pete.

1 Like

That did the trick. Thanks for the explanation. In the legacy version of Blynk, I was able to move all of my Blynk-related function definitions into a separate .cpp file as long as it contained the appropriate include statement, for example:

#include <BlynkSimpleEsp8266.h>

Unless there is something else I’m missing, this no longer appears to be the case. Instead, it seems that I need to place the include statement with the template ID and device name definitions at the top of the main.cpp file.

Correct.

Pete.

1 Like