Blynk.connect(timeout) questions

Dear Sirs,
I need some clarification regarding the Blynk.connect() command:

  1. Is it a blocking function? The default 30 seconds means that the execution of the sketch is remains in this function till timeout ( 30 seconds ) ?
  2. in the call Blynk.connect(timeout) what should be the value of (timeout) if we need timeout 15 seconds?

Thanks and Best Regards,
Mike Kranidis

  1. I think it is a blocking command, until the timeout or connection is made, whichever comes first… so the quicker the timeout, the quicker the rest of your program runs if there is no initial connection.

  2. Probably Blynk.connect(15) as I don’t think it counts in ms

Thanks a lot dear @Gunner.

Please Mr. @vshymanskyy answer me the questions both if the Blynk.connect() is a blocking type function ( as it seems ) and in case of Blynk.connect(timeout) what number should be the timeout value for let say timeout of 15 seconds.

a kind reminder

I’d say ms BlynkProtocol.h #L48

1 Like

Well, surely I’m just another user,but simply because Blynk lib is open source (happily!!) there is one, very simple way to verify all doubts. Here is excerpt from Blynk library:

in BlynkApi.h:

     * Connects to the server.
     * Blocks until connected or timeout happens.
     * May take less or more then timeout value.
     * @param timeout    Connection timeout
     * @returns          True if connected to the server
    bool connect(unsigned long timeout = BLYNK_TIMEOUT_MS*3);

and in BlynkProtocol.h:

bool connect(uint32_t timeout = BLYNK_TIMEOUT_MS*3) {
        state = CONNECTING;
        millis_time_t started = BlynkMillis();
        while ((state != CONNECTED) &&
               (BlynkMillis() - started < timeout))
        return state == CONNECTED;

Now, a quick look will bring an answer to both your questions @mikekgr:

  • yes, it is a blocking function (until it timeouts or connects)
  • it’s timeout should be passed in milliseconds

moreover, there is this in BlynkConfig.h:

// Network timeout in milliseconds.
#define BLYNK_TIMEOUT_MS     2000UL

Now, I believe the default timeout for connect() is 2000*3 =6000ms, unless defined otherwise (for example for GSM boards)


Yep, wrong again, due to lack of research :blush:

However either the Docs are wrong :scream: (I know… never happens…) about the default 30 seconds… or there is something goofy in the calculations.

Either way, too tired to look into it any further :tired_face:

1 Like

It is all clear now, thanks a lot guys!

I know about that, I was bit surprised too! :thinking:

The default is 3x the timeout value. In milliseconds.

Anyway, this is minimum timeout value, you cannot expect this function to return exactly at that time