Connection Management
There are several functions to help with connection management:

Blynk.connect()

This functions will continue trying to connect to Blynk server. Returns true when connected, false if timeout has been reached. Default timeout is 30 seconds.
1
bool result = Blynk.connect();
2
bool result = Blynk.connect(timeout);
Copied!

Blynk.disconnect()

Disconnects hardware from Blynk server:
1
Blynk.disconnect();
Copied!

Blynk.connected()

Returns true when hardware is connected to Blynk Server, false if there is no active connection to Blynk server.
1
bool result = Blynk.connected();
Copied!

Blynk.run()

This function should be called frequently to process incoming commands and perform housekeeping of Blynk connection. It is usually called in void loop() {}.
This command can be initiated it in other places of your code unless you run out of heap memory (in the cascaded functions with local memory).
For example, it is not recommended to call Blynk.run() inside BLYNK_WRITE functions on low-RAM devices.

BLYNK_CONNECTED()

Use this function when you need to run certain routine when hardware connects to Blynk Cloud or private server. It's common to call sync functions inside of this function.
1
BLYNK_CONNECTED() {
2
// Your code here
3
}
Copied!

BLYNK_APP_CONNECTED()

This function is called every time Blynk app client connects to Blynk server.
1
BLYNK_APP_CONNECTED() {
2
// Your code goes here
3
}
Copied!
Example

BLYNK_APP_DISCONNECTED()

This function is called every time the Blynk app disconnects from Blynk Cloud or private server.
1
BLYNK_APP_DISCONNECTED() {
2
// Your code here
3
}
Copied!
Example
Last modified 4mo ago