I found a way to overcome this problem by sending a GET request to the blynk server:
http://blynk-cloud.com/TOKEN/project
If the response contains the word “name” then the token is valid. (I hope this function will help others or even help the blynk team to create a function to check the token)
(library used: #include <HTTPClient.h> )
int isBlynkTokenValid(String token)
{
//TODO
//RETURNS:
/// HTTP client errors
// #define HTTPC_ERROR_CONNECTION_REFUSED (-1)
// #define HTTPC_ERROR_SEND_HEADER_FAILED (-2)
// #define HTTPC_ERROR_SEND_PAYLOAD_FAILED (-3)
// #define HTTPC_ERROR_NOT_CONNECTED (-4)
// #define HTTPC_ERROR_CONNECTION_LOST (-5)
// #define HTTPC_ERROR_NO_STREAM (-6)
// #define HTTPC_ERROR_NO_HTTP_SERVER (-7)
// #define HTTPC_ERROR_TOO_LESS_RAM (-8)
// #define HTTPC_ERROR_ENCODING (-9)
// #define HTTPC_ERROR_STREAM_WRITE (-10)
// #define HTTPC_ERROR_READ_TIMEOUT (-11)
//(-100) --> No Wifi
//(-99) --> token checked but is not valid
//(1) --> OK
//the function validates a blynk token and returns 1 if token is valid and negative if token is not valid
//http://blynk-cloud.com/TOKEN/project <-- this will return "Invalid token" if the token is not valid (if its valid it will return a json file containing all project details
if(WiFi.status() != WL_CONNECTED) WiFi.begin();
int timeOutCounter = 0;
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
timeOutCounter++;
if(timeOutCounter > 10) break;
}
if(WiFi.status() == WL_CONNECTED)
{
http.begin("http://blynk-cloud.com/" + token + "/project");
int httpCode = http.GET();
if (httpCode > 0 )
{
String payload = http.getString();
if(payload.indexOf("name") >= 0)
{
http.end();
return 1;
}
else
{
http.end();
return -99;
}
}
else
{
http.end();
return httpCode;
}
}
else
{
return -100;
}
}