Does blynk library internally work as web server mode or web client mode?

Hello All,
This is my first time experience with blynk libraries.
I wanted to understand how does blynk libraries work internally when used with our esp chips? Eg say methods like blynk.run() when used in our programs connect to blynk servers if connected to wifi…But at that time is information from blynk processed as esp being the client…or esp being the server? Knowing this will help me better take decisions with my architecture of my projects with blynk.

Please note that I am not asking if we can make esps connect to WiFi network in client/ server mode or not…
Hope i had explained the question well.

Regards,
Shariq

The Blynk client library that runs on the ESP is just that - a client.

The Blynk server can be run locally, on a Java capable device (i.e not on an ESP) or you can use the Blynk cloud servers.

The App talks to the server and the ESP talks to the server. The App and ESP never talk directly to each other when using WiFi.

Each time Blynk.run is executed, the ESP asks the server it it has any new data for it, and it also updates the server with any new data that it has.
In an ideal situation, Blynk.run should be executed hundreds of times per second. This allows the ESP to respond quickly to any commands that come from the App, via the server.

If the server doesn’t hear from the ESP for a long time (10 seconds by default) then the open TCP connection will be dropped, and the ESP will be listed as offline. If the ESP wants to re-connect with the server then an re-authentication and negotiation process needs to happen so a new open TCP connection can be established.

More info, including details of the protocol used, is here:

Pete.

1 Like

Thank you Pete… This is really insightful.

Btw, as you mentioned
“If the ESP wants to re-connect with the server then an re-authentication and negotiation process needs to happen so a new open TCP connection can be established”

In those conditions do we have to do blynk.connect everytime or just blynk.run is sufficient inside the loop?

If you’re using Blynk.config and Blynk.connect then the connect command is optional, as Blynk.run will attempt to establish a connection if none already exists.

Pete.

Thank you that really helps!!