Blynk connection management

In the sketch I’m using, I’ve connection management for wifi and Blynk. Blynk connection can fail if the token value is wrong (as per the server). The serial monitor output shows “invalid token” error msg and says “Reconnecting to Blynk Server”.

I would like to take action in the connection based on the error e.g Invalid token, Cannot reach Blynk(if there are some name resolution issues and we reach a non-Blynk server etc). Is there a variable (or a call that returns the error code) that has the error code that one can use?

If the token id is invalid, I will want to take the device to the AP mode, display the wifiManager config screen to acquire the token id from the user.

In general, Blynk libraries are open-source. You can open the code, find the place with this message and add the logic you need.

It should not be that complicated.

How often do you deal with “invalid token” ? I think I got it just a few times throughout all the years of using Blynk

Invalid token should not happen if all works well. In my case, using WiFiManager, I ended up putting in a token with an extra character. After it is saved, the device tries to connect to Blynk and fails. In such a situation, only a fresh flash works.

If this were a deployed device, this could happen if the provisioning is not done properly. Thus, this need/question. I’m a newbie coder and Blynker. Will take me a while to look at the libraries and modify them. Will try anyway.

For commercial use this scenario is covered by Blynk.Inject workflow.

Also, wrong WiFi credentials should not cause “Invalid Token” message

OP is using WIFi Manager to enter the token.

That’s not correct. Turn the router off and you enter all the credentials including token again.

Yes, can be done. I’ve a single network at home and the router is not easy to turn off.

If turning a router off for 60s is a problem you have 4 more options:

  1. Piggyback another router from the main router and connect to this one with WiFi Manager. If you enter the wrong auth turn off this one to reset auth.

  2. Use your phone as an AP and disable to reset credentials.

  3. Wire up a physical button to clear credentials.

  4. Code up a software reset that clears credentials if not connected after x seconds.

To prevent problems in the first place, email the token to your phone and cut and paste into WiFi Manager.

1 Like