ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::api::OutgoingConnectionManager Class Reference

Dials out when no dial-back target client is connected. More...

#include <api_outgoing_connection.h>

Public Member Functions

void setup ()
 
void loop (APIServer *server)
 
void on_target_client (APIConnection *conn)
 A key-verified client declared itself a dial-back target; last one wins.
 
void on_client_removed (APIConnection *conn, bool was_authenticated)
 Clears the dialed-connection gate; dying unauthenticated escalates the backoff.
 
void on_shutdown ()
 
void dump_config () const
 

Protected Types

enum class  DialState : uint8_t { DIAL_STATE_IDLE , DIAL_STATE_WAITING , DIAL_STATE_CONNECTING }
 

Protected Member Functions

void try_dial_ (APIServer *server, uint32_t now)
 
void poll_connect_ (APIServer *server, uint32_t now)
 
void handoff_ (APIServer *server, uint32_t now)
 
void schedule_retry_ (uint32_t now)
 
void schedule_wait_ (uint32_t now, uint32_t wait)
 
socklen_t target_sockaddr_ (struct sockaddr_storage *addr) const
 Fill addr with the target and return its length, or 0 when there is none.
 
bool persist_target_ ()
 
void format_target_ (std::span< char, socket::SOCKADDR_STR_LEN > buf) const
 Format the remembered target for a log line; empty when there is none.
 

Protected Attributes

std::unique_ptr< socket::Socket > dial_socket_
 
APIConnection * dialed_conn_ {nullptr}
 
ESPPreferenceObject target_pref_
 
uint32_t backoff_ {BACKOFF_MIN_MS}
 
uint32_t wait_ {BOOT_WAIT_MS}
 
uint32_t state_ts_ {0}
 
uint32_t last_poll_ {0}
 
SavedOutgoingTarget saved_ {}
 
bool host_persisted_ {false}
 
DialState state_ {DialState::DIAL_STATE_WAITING}
 

Static Protected Attributes

static constexpr uint32_t BACKOFF_MIN_MS = 5000
 
static constexpr uint32_t BACKOFF_MAX_MS = 300000
 
static constexpr uint32_t CONNECT_TIMEOUT_MS = 10000
 
static constexpr uint32_t CONNECT_POLL_INTERVAL_MS = 250
 
static constexpr uint32_t NETWORK_RETRY_MS = 500
 
static constexpr uint32_t PRECONDITION_RETRY_MS = 5000
 
static constexpr uint32_t BOOT_WAIT_MS = 0
 
static constexpr uint32_t IDLE_WAIT_MS = BACKOFF_MIN_MS
 

Detailed Description

Dials out when no dial-back target client is connected.

Only the TCP direction flips: the device stays the Noise responder, so both sides still verify by key. Targets the YAML host or the last remembered client.

Definition at line 41 of file api_outgoing_connection.h.

Member Enumeration Documentation

◆ DialState

enum class esphome::api::OutgoingConnectionManager::DialState : uint8_t
strongprotected
Enumerator
DIAL_STATE_IDLE 
DIAL_STATE_WAITING 
DIAL_STATE_CONNECTING 

Definition at line 53 of file api_outgoing_connection.h.

Member Function Documentation

◆ dump_config()

void esphome::api::OutgoingConnectionManager::dump_config ( ) const

Definition at line 299 of file api_outgoing_connection.cpp.

◆ format_target_()

void esphome::api::OutgoingConnectionManager::format_target_ ( std::span< char, socket::SOCKADDR_STR_LEN > buf) const
protected

Format the remembered target for a log line; empty when there is none.

Definition at line 101 of file api_outgoing_connection.cpp.

◆ handoff_()

void esphome::api::OutgoingConnectionManager::handoff_ ( APIServer * server,
uint32_t now )
protected

Definition at line 227 of file api_outgoing_connection.cpp.

◆ loop()

void esphome::api::OutgoingConnectionManager::loop ( APIServer * server)

Definition at line 127 of file api_outgoing_connection.cpp.

◆ on_client_removed()

void esphome::api::OutgoingConnectionManager::on_client_removed ( APIConnection * conn,
bool was_authenticated )

Clears the dialed-connection gate; dying unauthenticated escalates the backoff.

Definition at line 253 of file api_outgoing_connection.cpp.

◆ on_shutdown()

void esphome::api::OutgoingConnectionManager::on_shutdown ( )
inline

Definition at line 49 of file api_outgoing_connection.h.

◆ on_target_client()

void esphome::api::OutgoingConnectionManager::on_target_client ( APIConnection * conn)

A key-verified client declared itself a dial-back target; last one wins.

Definition at line 267 of file api_outgoing_connection.cpp.

◆ persist_target_()

bool esphome::api::OutgoingConnectionManager::persist_target_ ( )
inlineprotected

Definition at line 87 of file api_outgoing_connection.h.

◆ poll_connect_()

void esphome::api::OutgoingConnectionManager::poll_connect_ ( APIServer * server,
uint32_t now )
protected

Definition at line 203 of file api_outgoing_connection.cpp.

◆ schedule_retry_()

void esphome::api::OutgoingConnectionManager::schedule_retry_ ( uint32_t now)
protected

Definition at line 246 of file api_outgoing_connection.cpp.

◆ schedule_wait_()

void esphome::api::OutgoingConnectionManager::schedule_wait_ ( uint32_t now,
uint32_t wait )
protected

Definition at line 239 of file api_outgoing_connection.cpp.

◆ setup()

void esphome::api::OutgoingConnectionManager::setup ( )

Definition at line 113 of file api_outgoing_connection.cpp.

◆ target_sockaddr_()

socklen_t esphome::api::OutgoingConnectionManager::target_sockaddr_ ( struct sockaddr_storage * addr) const
protected

Fill addr with the target and return its length, or 0 when there is none.

Definition at line 70 of file api_outgoing_connection.cpp.

◆ try_dial_()

void esphome::api::OutgoingConnectionManager::try_dial_ ( APIServer * server,
uint32_t now )
protected

Definition at line 153 of file api_outgoing_connection.cpp.

Field Documentation

◆ backoff_

uint32_t esphome::api::OutgoingConnectionManager::backoff_ {BACKOFF_MIN_MS}
protected

Definition at line 104 of file api_outgoing_connection.h.

◆ BACKOFF_MAX_MS

uint32_t esphome::api::OutgoingConnectionManager::BACKOFF_MAX_MS = 300000
staticconstexprprotected

Definition at line 60 of file api_outgoing_connection.h.

◆ BACKOFF_MIN_MS

uint32_t esphome::api::OutgoingConnectionManager::BACKOFF_MIN_MS = 5000
staticconstexprprotected

Definition at line 59 of file api_outgoing_connection.h.

◆ BOOT_WAIT_MS

static constexpr uint32_t esphome::api::OutgoingConnectionManager::BOOT_WAIT_MS = 0
staticconstexprprotected

Definition at line 68 of file api_outgoing_connection.h.

◆ CONNECT_POLL_INTERVAL_MS

uint32_t esphome::api::OutgoingConnectionManager::CONNECT_POLL_INTERVAL_MS = 250
staticconstexprprotected

Definition at line 62 of file api_outgoing_connection.h.

◆ CONNECT_TIMEOUT_MS

uint32_t esphome::api::OutgoingConnectionManager::CONNECT_TIMEOUT_MS = 10000
staticconstexprprotected

Definition at line 61 of file api_outgoing_connection.h.

◆ dial_socket_

std::unique_ptr<socket::Socket> esphome::api::OutgoingConnectionManager::dial_socket_
protected

Definition at line 96 of file api_outgoing_connection.h.

◆ dialed_conn_

APIConnection* esphome::api::OutgoingConnectionManager::dialed_conn_ {nullptr}
protected

Definition at line 98 of file api_outgoing_connection.h.

◆ host_persisted_

bool esphome::api::OutgoingConnectionManager::host_persisted_ {false}
protected

Definition at line 114 of file api_outgoing_connection.h.

◆ IDLE_WAIT_MS

static constexpr uint32_t esphome::api::OutgoingConnectionManager::IDLE_WAIT_MS = BACKOFF_MIN_MS
staticconstexprprotected

Definition at line 69 of file api_outgoing_connection.h.

◆ last_poll_

uint32_t esphome::api::OutgoingConnectionManager::last_poll_ {0}
protected

Definition at line 107 of file api_outgoing_connection.h.

◆ NETWORK_RETRY_MS

uint32_t esphome::api::OutgoingConnectionManager::NETWORK_RETRY_MS = 500
staticconstexprprotected

Definition at line 63 of file api_outgoing_connection.h.

◆ PRECONDITION_RETRY_MS

uint32_t esphome::api::OutgoingConnectionManager::PRECONDITION_RETRY_MS = 5000
staticconstexprprotected

Definition at line 64 of file api_outgoing_connection.h.

◆ saved_

SavedOutgoingTarget esphome::api::OutgoingConnectionManager::saved_ {}
protected

Definition at line 111 of file api_outgoing_connection.h.

◆ state_

DialState esphome::api::OutgoingConnectionManager::state_ {DialState::DIAL_STATE_WAITING}
protected

Definition at line 116 of file api_outgoing_connection.h.

◆ state_ts_

uint32_t esphome::api::OutgoingConnectionManager::state_ts_ {0}
protected

Definition at line 106 of file api_outgoing_connection.h.

◆ target_pref_

ESPPreferenceObject esphome::api::OutgoingConnectionManager::target_pref_
protected

Definition at line 100 of file api_outgoing_connection.h.

◆ wait_

uint32_t esphome::api::OutgoingConnectionManager::wait_ {BOOT_WAIT_MS}
protected

Definition at line 105 of file api_outgoing_connection.h.


The documentation for this class was generated from the following files: