> For the complete documentation index, see [llms.txt](https://docs.blynk.io/en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blynk.io/en/blynk-library-firmware-api/connection-management.md).

# 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.

```cpp
bool result = Blynk.connect();
bool result = Blynk.connect(timeout);
```

## Blynk.disconnect()

Disconnects hardware from Blynk server:

```cpp
Blynk.disconnect();
```

## Blynk.connected()

Returns `true` when hardware is connected to Blynk Server, `false` if there is no active connection to Blynk server.

```cpp
bool result = Blynk.connected();
```

## 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.

```cpp
BLYNK_CONNECTED() {
// Your code here
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.blynk.io/en/blynk-library-firmware-api/connection-management.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
