Blynk.run() internals

Since we can only view the headers, do the internal workings of Blynk.run() do a connection check at all?

It seems too…

http://docs.blynk.cc/#blynk-firmware-configuration-blynkconfig

image

I’m trying to avoid things like this if it’s redundant:

    // Main processing loop.
    void loop()
    {
        blynkTimer.run();
     
        // only attempt Blynk-related functions when connected to Blynk
        if (Blynk.connected())
        {
            Blynk.run();
        }
        
    }

I believe that some sketches will still run without that elimination… but at a reduced rate as the library tries to unsuccessfully connect at each and every processor loop.

So the purpose of isolating the Blynk.run() command via an if() function is not to determine connection so much as not waste time trying to do Blynk library background tasks when NOT connected.

That is not true. All of the source code is available. You can even contribute :wink:

Where can I see the corresponding .cpp files? Is there another location?

Yes, the directory just one level up: https://github.com/blynkkk/blynk-library/tree/3f4c883003162570b6e1472aa0b16c6dd73ace58/src
It contains all the source code. Not all the .h files need to have a corresponding .cpp, by the way,

Thank you for taking the time to read and reply @vshymanskyy. I’ve been looking in this area for a while (maybe I have just overlooked it), would you be able to point me at the specific file containing the Blynk.run() source?

No, just use githib’s search function

Thanks @vshymanskyy

For anyone else interested, it’s over here.

TL;DR: not necessary to check Blynk.connected() in loop()

I am not super versed on programming… but…

Since you didn’t clarify… I am thinking you are referring to this command in the library

if (state == DISCONNECTED) {
        return false;
    }

However, since it is possible to run a disconnect command (and subsequent connect command) perhaps this is not quite what you think it is… thus there may still be a delay in processing the Blynk.run() if Blynk thinks it is still supposed to be connected but is in fact not, due external issues.

@Gunner As the code example I gave earlier was the use case, I do not need to check if Blynk.connected() prior to bothering with Blynk.run() in sketch’s loop() - it handled that concern already and will return prior to doing anything related to network connectivity if it’s not connected.

If people are managing that connect and disconnect command separately - it’s outside the scope of my concern :slight_smile:

Thanks for your input!

Correct… as I stated before. But for some, it has been found to be beneficial or even necessary.

Not a problem with me what you do or don’t concern about :wink: Every question opens up something new to learn. This forum and the topics herein are for the benefit and edification of all who read them, not just to resolve the OP issue.

1 Like