ESPHome 2026.1.4
Loading...
Searching...
No Matches
esphome::async_tcp::AsyncClient Class Reference

AsyncClient API for platforms using sockets (ESP-IDF, host, etc.) NOTE: This class is NOT thread-safe. More...

#include <async_tcp_socket.h>

Public Types

using AcConnectHandler = std::function<void(void *, AsyncClient *)>
 
using AcDataHandler = std::function<void(void *, AsyncClient *, void *data, size_t len)>
 
using AcErrorHandler = std::function<void(void *, AsyncClient *, int8_t error)>
 

Public Member Functions

 AsyncClient ()=default
 
 ~AsyncClient ()=default
 
bool connect (const char *host, uint16_t port)
 
void close ()
 
bool connected () const
 
size_t write (const char *data, size_t len)
 
void onConnect (AcConnectHandler cb, void *arg=nullptr)
 
void onDisconnect (AcConnectHandler cb, void *arg=nullptr)
 
void onData (AcDataHandler cb, void *arg=nullptr)
 Set data callback. NOTE: data pointer is only valid during callback execution.
 
void onError (AcErrorHandler cb, void *arg=nullptr)
 
void loop ()
 

Detailed Description

AsyncClient API for platforms using sockets (ESP-IDF, host, etc.) NOTE: This class is NOT thread-safe.

All methods must be called from the main loop.

Definition at line 18 of file async_tcp_socket.h.

Member Typedef Documentation

◆ AcConnectHandler

using esphome::async_tcp::AsyncClient::AcConnectHandler = std::function<void(void *, AsyncClient *)>

Definition at line 20 of file async_tcp_socket.h.

◆ AcDataHandler

using esphome::async_tcp::AsyncClient::AcDataHandler = std::function<void(void *, AsyncClient *, void *data, size_t len)>

Definition at line 21 of file async_tcp_socket.h.

◆ AcErrorHandler

using esphome::async_tcp::AsyncClient::AcErrorHandler = std::function<void(void *, AsyncClient *, int8_t error)>

Definition at line 22 of file async_tcp_socket.h.

Constructor & Destructor Documentation

◆ AsyncClient()

esphome::async_tcp::AsyncClient::AsyncClient ( )
default

◆ ~AsyncClient()

esphome::async_tcp::AsyncClient::~AsyncClient ( )
default

Member Function Documentation

◆ close()

void esphome::async_tcp::AsyncClient::close ( )

Definition at line 67 of file async_tcp_socket.cpp.

◆ connect()

bool esphome::async_tcp::AsyncClient::connect ( const char * host,
uint16_t port )
nodiscard

Definition at line 19 of file async_tcp_socket.cpp.

◆ connected()

bool esphome::async_tcp::AsyncClient::connected ( ) const
inlinenodiscard

Definition at line 29 of file async_tcp_socket.h.

◆ loop()

void esphome::async_tcp::AsyncClient::loop ( )

Definition at line 93 of file async_tcp_socket.cpp.

◆ onConnect()

void esphome::async_tcp::AsyncClient::onConnect ( AcConnectHandler cb,
void * arg = nullptr )
inline

Definition at line 32 of file async_tcp_socket.h.

◆ onData()

void esphome::async_tcp::AsyncClient::onData ( AcDataHandler cb,
void * arg = nullptr )
inline

Set data callback. NOTE: data pointer is only valid during callback execution.

Definition at line 41 of file async_tcp_socket.h.

◆ onDisconnect()

void esphome::async_tcp::AsyncClient::onDisconnect ( AcConnectHandler cb,
void * arg = nullptr )
inline

Definition at line 36 of file async_tcp_socket.h.

◆ onError()

void esphome::async_tcp::AsyncClient::onError ( AcErrorHandler cb,
void * arg = nullptr )
inline

Definition at line 45 of file async_tcp_socket.h.

◆ write()

size_t esphome::async_tcp::AsyncClient::write ( const char * data,
size_t len )

Definition at line 76 of file async_tcp_socket.cpp.


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