How to not error out of Client while waiting for Local Server to Startup

My blynk client app crashes because the local server does not come up fast enough.

Any idea on how to insert a “wait” till server is up?

You have not clarified what you meen by “Client App”, but if referring to the Blynk App on your phone, simply don’t click on the App icon until you know the server is up :stuck_out_tongue: The Server IS the master of the App, so the App knows nothing, can do nothing, is nothing, without the Server to log into.

But if you are referring to a Blynk Client (AKA some form of code running on an MCU of some sort), then you can code it in such a way as to run without the server if needed…

1 Like

Thanks for replying. I was referring to “Blynk Client” (sorry still getting use to the terminology).

I tried using blynk.connect() with no luck. Here is the JS code:

var Blynk = require('/home/pi/node_modules/blynk-library');
var AUTH = '[MyAuthCode]';
var blynk = new Blynk.Blynk(AUTH, options = {
  connector : new Blynk.TcpClient( options = { addr:"[MyIPAddress]", port:8080 } )
});
while (!Blynk.connect()) {
}
blynk.on('connect', function() { console.log("Blynk ready."); });
blynk.on('disconnect', function() { console.log("DISCONNECT"); });

Any ideas?

Since you are dealing with Blynk’s NodeJS Client library, all I can suggest is the same direct connect example that you are using. But I have never worked with it myself, my server is always running.

PS, I properly formatted your posted code…

Blynk%20-%20FTFC

Just a guess… but if you are at least getting the DISCONNECT message, then perhaps you need somthing else running in the code, so it has somthing to do and not time out?

Problem solved… added the following line of code to handle the “error” of client not having a server to connect to …

blynk.on(‘error’,function() {console.log(“Connection error.”) });

1 Like