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

Invalid Auth Token messages when converting code to Blynk 2.0

A few people that are trying to convert Blynk 0.1 legacy sketches to Blynk 2.0 are seeing “Invalid auth token messages”

A closer inspection of the message will show that the device is trying to connect to the legacy cloud servers at blynk-cloud.com instead of the new blynk.cloud servers.

Connected to WiFi
IP: xxx.xxx.xxx.xxx

     ___  __          __
    / _ )/ /_ _____  / /__
   / _  / / // / _ \/  '_/
  /____/_/\_, /_//_/_/\_\
         /___/ v1.0.1 on [your board type]
 
Connecting to blynk-cloud.com:80            <<< this is the legacy server!
Invalid auth token

The “Invalid auth token message” is because there is no project on the legacy cloud servers with your Blynk 2.0 auth token, that only exists on the Blynk 2.0 servers.

Why does the sketch try to connect to the legacy servers?

The Blynk 2.0 library (Blynk library version 1.0.0 or higher) will try to connect to the new servers if it sees #define BLYNK_TEMPLATE_ID at the top of the code, but will try to connect to the legacy servers if not.

If you structure your code like this, it will work correctly…

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_DEVICE_NAME "REDACTED"

#define BLYNK_PRINT Serial

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

but if you structure it like this, it will try to connect to the old Blynk servers, because the #define BLYNK_TEMPLATE_ID command is too far down the sketch…

#define BLYNK_PRINT Serial

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

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_DEVICE_NAME "REDACTED"

Pete.

3 Likes