`Invalid Auth Token` or `Connecting to blynk-cloud.com:` 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"

Update January 2023

Now that the Blynk Legacy cloud servers have been turned-off, you will no longer see the “Invalid Auth Token” message. This message appeared when your device connected to the Legacy cloud servers and attempted to pass a Blynk IoT auth token to the old Legacy system. These Auth tokens were not recognised, hence the error message.
Now you will simply see Connecting to blynk-cloud.com: followed by a port number (80, 8080 or 443). This message means that the device is trying to connect to the legacy servers, and that can’t be found.

The solution is the same as described above - to ensure that the lines of code beginning with #define BLYNK_TEMPLATE_ID that have been copied from the Firmware Configuration screen in the web console are at the very top of your sketch.

Pete.

4 Likes