Code hang at Blynk.begin(auth, wifi, ssid, pass);

Does anyone have any idea what can cause the code to to hang at Blynk.begin(auth, wifi, ssid, pass)?

The code has been working before.

I changed back ssid to my old router (ASUS RT56U), which it used to work from and now it works again. The new router (ASUS AC68U) only connects 1 of out 20 times, and then the code hangs at the blynk.begin line.

Can someone explain that instead?

Sounds like you have a networking issue… Blynk.begin() is a blocking command… the code stops there until it connects. This is normal.

You can alternately use Blynk.config() and pre-setup of WiFi if you need your sketch to work even without Blynk Server connection.

All I can say, is that I do own DSL-AC68U, and never had any problem with Blynk or whatever other service on any firmware version, so I doubt it is a router issue. Yet still some network specific issue might exist… Or perhaps some IP conflict in local network?

According to silentbogo’s reply to this post (link below), the esp devices are badly engineered and has way too much TX power. My application with my arduino and esp device are less then a meter away from the router.

There is an AT command to adjust TX power. But it is possible to run AT commands before/after the blynk.begin? If so, how?

If you are running the ESP as a “shield” then yes, it is possible (although I have not a ready code solution “at hand”). But if it is the ESP alone, then AT comms naturally doesn’t work.

I don’t think a blocking command is good in my application. I want a 20 seconds timeout, and then powercycling the ESP-01. Do you think this code would do it correctly?

bool result=0;
byte timeout=20;

if (result == 0)
digitalWrite(module_power, HIGH);
Blynk.connectWiFi(ssid, pass);
result = Blynk.connect(timeout);
digitalWrite(module_power, LOW);