I integrated Blynk in an existing project. The project does some pool managment, is on a mega2560 with ethernet shield, also has its webpage for remote control and sends some data to internet server database and also to local wifi connected displays. all works well until the internet connection fails. Then blynk tries to connect to server and blocks ALL up to 32 seconds. This is a 100% nogo for my application.
And Internet fails often in the last month. The provider has no solution.
I know that posting the code is always good idea, but in this case the code is hundreds of lines and has nothing to do with the malfunction. I thought someone else had the same problem and is already solved by adding some code lines to check if there is Internet connection or to change a timeout parameter or so.
Maybe later I can write a small sketch that shows exactly what I mean.
isConnected() refers to the wifi connection of an ESP8266, or doesn’t?
My Mega is with Ethernet shield ALWAYS conected to the LAN with cable. It’s the internet connection (Router), that fails.
And if I don’t execute Blynk.run(); with whatever workaround, it will no more connect when Router gets internet.
Or I have to make routine to ping google.com and activate then the execution of Blynk.run()
Possible but sure not state of the art.
@ElEspanol I was overlooking the fact you were using an Arduino and Ethernet.
However AFAIK isConnected() relates to being connected to Blynk so it isn’t specific to ESP’s so you should still be able to use it.
Maybe if you describe in more detail what the ‘internet failures’ are we can advise further.
Do you need a fix for when there is no internet when you first connect, your internet connection goes down after the first connection or both?
Obviously there is only so much you can do if the internet is down but there are normally ways available to ensure your system still performs the basics even if it is unable to send data out to the internet.
The Arduino is always in use and should work in local network. The internet connection can be good for days, and then could be down for hours or minutes. If it is down, the Arduino should do his work as foreseen. Of course without internet also can’t send data to thingspeak, but this is coded nonblocking. and not storing the data in this time is bad, but it is as it is. The problem is while no internet is available, the sketch hangs about 32 sec., then makes one loop and hangs again 32 sec.
In this 32 sec, does not recognize a button pressed, absolutly nothing. When internet comes back, all runs again normally.
What I need is that there is no 32 sec. pause if internet is down. Maybe we can change the timeout?
Or I check if loop is more than 10 seconds and if so, not run blink.run() for the next ten minutes?
Or both?
Or the developer of the lib has any idea o can change to non blocking code?
@ElEspanol couple of extracts for you to consider:
void setup(){
// pinMode and other stuff
Blynk.config(blynk_token);
Blynk.connect(3333); // equals 10s timeout as Blynk connect works on 3ms units
unsigned long timeout = (millis());
while (Blynk.connect() == false) {
// wait
}
}
void checkBlynk(){ // called with SimpleTimer
bool isconnected = Blynk.connected();
if (isconnected == false){
Blynk.connect(); // try to reconnect but will try in loop() anyway
}
}
Blynk.config() looks like that it brings more or less the solution
instead of
Blynk.begin(auth, “blynk-cloud.com”, 8442, ips, dnstest, gateway, subnet, mac);
I have now:
Blynk.config(auth);
bool result = Blynk.connect(300);
When I disconnect now the ethernet cable, I have max 2 sec. delay and a lot of loops between these delays.
And a “Trouble detected: http://docs.blynk.cc/#troubleshooting-flood-error” makes no delay.
I am trying to achieve the same result as you. I would like my sketch to continue looping with minimal disruption when connection to the Blynk server is not available. I have the same hardware that you do. Arduino mega with ethernet W5100 sheild.
Can you clarify how you are managing your connection? I am having trouble replicating your results. Do you have this in the setup loop? What do you do with the bool value called ‘result’?
Blynk.config(auth);
bool result = Blynk.connect(300);
The result var returns either 0 or 1 (fail or succes connecting) and you can use that to handle your connection management using blynk.run(), that would be my guess…
In the meantime I learned that this wasn’t the solution. After some changes in the sketch (had nothing to do with the blynk stuff) I had the same problem again.
At the moment the Internet provider there is more stable and I didn’t spend more time on this problem.