ESPHome 2025.8.0b2
Loading...
Searching...
No Matches
esphome::mqtt::MQTTBackendESP32 Class Referencefinal

#include <mqtt_backend_esp32.h>

Inheritance diagram for esphome::mqtt::MQTTBackendESP32:
esphome::mqtt::MQTTBackend

Data Structures

struct  MqttClientDeleter
 

Public Member Functions

void set_keep_alive (uint16_t keep_alive) final
 
void set_client_id (const char *client_id) final
 
void set_clean_session (bool clean_session) final
 
void set_credentials (const char *username, const char *password) final
 
void set_will (const char *topic, uint8_t qos, bool retain, const char *payload) final
 
void set_server (network::IPAddress ip, uint16_t port) final
 
void set_server (const char *host, uint16_t port) final
 
void set_on_connect (std::function< on_connect_callback_t > &&callback) final
 
void set_on_disconnect (std::function< on_disconnect_callback_t > &&callback) final
 
void set_on_subscribe (std::function< on_subscribe_callback_t > &&callback) final
 
void set_on_unsubscribe (std::function< on_unsubscribe_callback_t > &&callback) final
 
void set_on_message (std::function< on_message_callback_t > &&callback) final
 
void set_on_publish (std::function< on_publish_user_callback_t > &&callback) final
 
bool connected () const final
 
void connect () final
 
void disconnect () final
 
bool subscribe (const char *topic, uint8_t qos) final
 
bool unsubscribe (const char *topic) final
 
bool publish (const char *topic, const char *payload, size_t length, uint8_t qos, bool retain) final
 
void loop () final
 
void set_ca_certificate (const std::string &cert)
 
void set_cl_certificate (const std::string &cert)
 
void set_cl_key (const std::string &key)
 
void set_skip_cert_cn_check (bool skip_check)
 
virtual bool publish (const MQTTMessage &message)
 
- Public Member Functions inherited from esphome::mqtt::MQTTBackend

Static Public Attributes

static const size_t MQTT_BUFFER_SIZE = 4096
 
static const size_t TASK_STACK_SIZE = 3072
 
static const size_t TASK_STACK_SIZE_TLS = 4096
 
static const ssize_t TASK_PRIORITY = 5
 
static const uint8_t MQTT_QUEUE_LENGTH = 30
 

Protected Types

using ClientHandler_ = std::unique_ptr<esp_mqtt_client, MqttClientDeleter>
 

Protected Member Functions

bool initialize_ ()
 
void mqtt_event_handler_ (const Event &event)
 
bool enqueue_ (MqttQueueTypeT type, const char *topic, int qos=0, bool retain=false, const char *payload=NULL, size_t len=0)
 

Static Protected Member Functions

static void mqtt_event_handler (void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
 static - Dispatch event to instance method
 
static void esphome_mqtt_task (void *params)
 

Protected Attributes

ClientHandler_ handler_
 
bool is_connected_ {false}
 
bool is_initalized_ {false}
 
esp_mqtt_client_config_t mqtt_cfg_ {}
 
std::string host_
 
uint16_t port_
 
std::string username_
 
std::string password_
 
std::string lwt_topic_
 
std::string lwt_message_
 
uint8_t lwt_qos_
 
bool lwt_retain_
 
std::string client_id_
 
uint16_t keep_alive_
 
bool clean_session_
 
optional< std::string > ca_certificate_
 
optional< std::string > cl_certificate_
 
optional< std::string > cl_key_
 
bool skip_cert_cn_check_ {false}
 
EventPool< struct QueueElement, MQTT_QUEUE_LENGTHmqtt_event_pool_
 
NotifyingLockFreeQueue< struct QueueElement, MQTT_QUEUE_LENGTHmqtt_queue_
 
TaskHandle_t task_handle_ {nullptr}
 
CallbackManager< on_connect_callback_ton_connect_
 
CallbackManager< on_disconnect_callback_ton_disconnect_
 
CallbackManager< on_subscribe_callback_ton_subscribe_
 
CallbackManager< on_unsubscribe_callback_ton_unsubscribe_
 
CallbackManager< on_message_callback_ton_message_
 
CallbackManager< on_publish_user_callback_ton_publish_
 
std::queue< Eventmqtt_events_
 
uint32_t last_dropped_log_time_ {0}
 

Static Protected Attributes

static constexpr uint32_t DROP_LOG_INTERVAL_MS = 10000
 

Additional Inherited Members

- Public Types inherited from esphome::mqtt::MQTTBackend
using on_connect_callback_t = void(bool session_present)
 
using on_disconnect_callback_t = void(MQTTClientDisconnectReason reason)
 
using on_subscribe_callback_t = void(uint16_t packet_id, uint8_t qos)
 
using on_unsubscribe_callback_t = void(uint16_t packet_id)
 
using on_message_callback_t = void(const char *topic, const char *payload, size_t len, size_t index, size_t total)
 
using on_publish_user_callback_t = void(uint16_t packet_id)
 

Detailed Description

Definition at line 116 of file mqtt_backend_esp32.h.

Member Typedef Documentation

◆ ClientHandler_

using esphome::mqtt::MQTTBackendESP32::ClientHandler_ = std::unique_ptr<esp_mqtt_client, MqttClientDeleter>
protected

Definition at line 229 of file mqtt_backend_esp32.h.

Member Function Documentation

◆ connect()

void esphome::mqtt::MQTTBackendESP32::connect ( )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 170 of file mqtt_backend_esp32.h.

◆ connected()

bool esphome::mqtt::MQTTBackendESP32::connected ( ) const
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 168 of file mqtt_backend_esp32.h.

◆ disconnect()

void esphome::mqtt::MQTTBackendESP32::disconnect ( )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 177 of file mqtt_backend_esp32.h.

◆ enqueue_()

bool esphome::mqtt::MQTTBackendESP32::enqueue_ ( MqttQueueTypeT type,
const char * topic,
int qos = 0,
bool retain = false,
const char * payload = NULL,
size_t len = 0 )
protected

Definition at line 242 of file mqtt_backend_esp32.cpp.

◆ esphome_mqtt_task()

void esphome::mqtt::MQTTBackendESP32::esphome_mqtt_task ( void * params)
staticprotected

Definition at line 197 of file mqtt_backend_esp32.cpp.

◆ initialize_()

bool esphome::mqtt::MQTTBackendESP32::initialize_ ( )
protected

Definition at line 16 of file mqtt_backend_esp32.cpp.

◆ loop()

void esphome::mqtt::MQTTBackendESP32::loop ( )
finalvirtual

Reimplemented from esphome::mqtt::MQTTBackend.

Definition at line 83 of file mqtt_backend_esp32.cpp.

◆ mqtt_event_handler()

void esphome::mqtt::MQTTBackendESP32::mqtt_event_handler ( void * handler_args,
esp_event_base_t base,
int32_t event_id,
void * event_data )
staticprotected

static - Dispatch event to instance method

Definition at line 186 of file mqtt_backend_esp32.cpp.

◆ mqtt_event_handler_()

void esphome::mqtt::MQTTBackendESP32::mqtt_event_handler_ ( const Event & event)
protected

Definition at line 113 of file mqtt_backend_esp32.cpp.

◆ publish() [1/2]

bool esphome::mqtt::MQTTBackendESP32::publish ( const char * topic,
const char * payload,
size_t length,
uint8_t qos,
bool retain )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 197 of file mqtt_backend_esp32.h.

◆ publish() [2/2]

virtual bool esphome::mqtt::MQTTBackend::publish ( const MQTTMessage & message)
inlinevirtual

Reimplemented from esphome::mqtt::MQTTBackend.

Definition at line 61 of file mqtt_backend.h.

◆ set_ca_certificate()

void esphome::mqtt::MQTTBackendESP32::set_ca_certificate ( const std::string & cert)
inline

Definition at line 210 of file mqtt_backend_esp32.h.

◆ set_cl_certificate()

void esphome::mqtt::MQTTBackendESP32::set_cl_certificate ( const std::string & cert)
inline

Definition at line 211 of file mqtt_backend_esp32.h.

◆ set_cl_key()

void esphome::mqtt::MQTTBackendESP32::set_cl_key ( const std::string & key)
inline

Definition at line 212 of file mqtt_backend_esp32.h.

◆ set_clean_session()

void esphome::mqtt::MQTTBackendESP32::set_clean_session ( bool clean_session)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 126 of file mqtt_backend_esp32.h.

◆ set_client_id()

void esphome::mqtt::MQTTBackendESP32::set_client_id ( const char * client_id)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 125 of file mqtt_backend_esp32.h.

◆ set_credentials()

void esphome::mqtt::MQTTBackendESP32::set_credentials ( const char * username,
const char * password )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 128 of file mqtt_backend_esp32.h.

◆ set_keep_alive()

void esphome::mqtt::MQTTBackendESP32::set_keep_alive ( uint16_t keep_alive)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 124 of file mqtt_backend_esp32.h.

◆ set_on_connect()

void esphome::mqtt::MQTTBackendESP32::set_on_connect ( std::function< on_connect_callback_t > && callback)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 150 of file mqtt_backend_esp32.h.

◆ set_on_disconnect()

void esphome::mqtt::MQTTBackendESP32::set_on_disconnect ( std::function< on_disconnect_callback_t > && callback)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 153 of file mqtt_backend_esp32.h.

◆ set_on_message()

void esphome::mqtt::MQTTBackendESP32::set_on_message ( std::function< on_message_callback_t > && callback)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 162 of file mqtt_backend_esp32.h.

◆ set_on_publish()

void esphome::mqtt::MQTTBackendESP32::set_on_publish ( std::function< on_publish_user_callback_t > && callback)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 165 of file mqtt_backend_esp32.h.

◆ set_on_subscribe()

void esphome::mqtt::MQTTBackendESP32::set_on_subscribe ( std::function< on_subscribe_callback_t > && callback)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 156 of file mqtt_backend_esp32.h.

◆ set_on_unsubscribe()

void esphome::mqtt::MQTTBackendESP32::set_on_unsubscribe ( std::function< on_unsubscribe_callback_t > && callback)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 159 of file mqtt_backend_esp32.h.

◆ set_server() [1/2]

void esphome::mqtt::MQTTBackendESP32::set_server ( const char * host,
uint16_t port )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 146 of file mqtt_backend_esp32.h.

◆ set_server() [2/2]

void esphome::mqtt::MQTTBackendESP32::set_server ( network::IPAddress ip,
uint16_t port )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 142 of file mqtt_backend_esp32.h.

◆ set_skip_cert_cn_check()

void esphome::mqtt::MQTTBackendESP32::set_skip_cert_cn_check ( bool skip_check)
inline

Definition at line 213 of file mqtt_backend_esp32.h.

◆ set_will()

void esphome::mqtt::MQTTBackendESP32::set_will ( const char * topic,
uint8_t qos,
bool retain,
const char * payload )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 134 of file mqtt_backend_esp32.h.

◆ subscribe()

bool esphome::mqtt::MQTTBackendESP32::subscribe ( const char * topic,
uint8_t qos )
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 182 of file mqtt_backend_esp32.h.

◆ unsubscribe()

bool esphome::mqtt::MQTTBackendESP32::unsubscribe ( const char * topic)
inlinefinalvirtual

Implements esphome::mqtt::MQTTBackend.

Definition at line 189 of file mqtt_backend_esp32.h.

Field Documentation

◆ ca_certificate_

optional<std::string> esphome::mqtt::MQTTBackendESP32::ca_certificate_
protected

Definition at line 248 of file mqtt_backend_esp32.h.

◆ cl_certificate_

optional<std::string> esphome::mqtt::MQTTBackendESP32::cl_certificate_
protected

Definition at line 249 of file mqtt_backend_esp32.h.

◆ cl_key_

optional<std::string> esphome::mqtt::MQTTBackendESP32::cl_key_
protected

Definition at line 250 of file mqtt_backend_esp32.h.

◆ clean_session_

bool esphome::mqtt::MQTTBackendESP32::clean_session_
protected

Definition at line 247 of file mqtt_backend_esp32.h.

◆ client_id_

std::string esphome::mqtt::MQTTBackendESP32::client_id_
protected

Definition at line 245 of file mqtt_backend_esp32.h.

◆ DROP_LOG_INTERVAL_MS

uint32_t esphome::mqtt::MQTTBackendESP32::DROP_LOG_INTERVAL_MS = 10000
staticconstexprprotected

Definition at line 272 of file mqtt_backend_esp32.h.

◆ handler_

ClientHandler_ esphome::mqtt::MQTTBackendESP32::handler_
protected

Definition at line 230 of file mqtt_backend_esp32.h.

◆ host_

std::string esphome::mqtt::MQTTBackendESP32::host_
protected

Definition at line 237 of file mqtt_backend_esp32.h.

◆ is_connected_

bool esphome::mqtt::MQTTBackendESP32::is_connected_ {false}
protected

Definition at line 232 of file mqtt_backend_esp32.h.

◆ is_initalized_

bool esphome::mqtt::MQTTBackendESP32::is_initalized_ {false}
protected

Definition at line 233 of file mqtt_backend_esp32.h.

◆ keep_alive_

uint16_t esphome::mqtt::MQTTBackendESP32::keep_alive_
protected

Definition at line 246 of file mqtt_backend_esp32.h.

◆ last_dropped_log_time_

uint32_t esphome::mqtt::MQTTBackendESP32::last_dropped_log_time_ {0}
protected

Definition at line 271 of file mqtt_backend_esp32.h.

◆ lwt_message_

std::string esphome::mqtt::MQTTBackendESP32::lwt_message_
protected

Definition at line 242 of file mqtt_backend_esp32.h.

◆ lwt_qos_

uint8_t esphome::mqtt::MQTTBackendESP32::lwt_qos_
protected

Definition at line 243 of file mqtt_backend_esp32.h.

◆ lwt_retain_

bool esphome::mqtt::MQTTBackendESP32::lwt_retain_
protected

Definition at line 244 of file mqtt_backend_esp32.h.

◆ lwt_topic_

std::string esphome::mqtt::MQTTBackendESP32::lwt_topic_
protected

Definition at line 241 of file mqtt_backend_esp32.h.

◆ MQTT_BUFFER_SIZE

const size_t esphome::mqtt::MQTTBackendESP32::MQTT_BUFFER_SIZE = 4096
static

Definition at line 118 of file mqtt_backend_esp32.h.

◆ mqtt_cfg_

esp_mqtt_client_config_t esphome::mqtt::MQTTBackendESP32::mqtt_cfg_ {}
protected

Definition at line 235 of file mqtt_backend_esp32.h.

◆ mqtt_event_pool_

EventPool<struct QueueElement, MQTT_QUEUE_LENGTH> esphome::mqtt::MQTTBackendESP32::mqtt_event_pool_
protected

Definition at line 254 of file mqtt_backend_esp32.h.

◆ mqtt_events_

std::queue<Event> esphome::mqtt::MQTTBackendESP32::mqtt_events_
protected

Definition at line 268 of file mqtt_backend_esp32.h.

◆ mqtt_queue_

NotifyingLockFreeQueue<struct QueueElement, MQTT_QUEUE_LENGTH> esphome::mqtt::MQTTBackendESP32::mqtt_queue_
protected

Definition at line 255 of file mqtt_backend_esp32.h.

◆ MQTT_QUEUE_LENGTH

const uint8_t esphome::mqtt::MQTTBackendESP32::MQTT_QUEUE_LENGTH = 30
static

Definition at line 122 of file mqtt_backend_esp32.h.

◆ on_connect_

CallbackManager<on_connect_callback_t> esphome::mqtt::MQTTBackendESP32::on_connect_
protected

Definition at line 262 of file mqtt_backend_esp32.h.

◆ on_disconnect_

CallbackManager<on_disconnect_callback_t> esphome::mqtt::MQTTBackendESP32::on_disconnect_
protected

Definition at line 263 of file mqtt_backend_esp32.h.

◆ on_message_

CallbackManager<on_message_callback_t> esphome::mqtt::MQTTBackendESP32::on_message_
protected

Definition at line 266 of file mqtt_backend_esp32.h.

◆ on_publish_

CallbackManager<on_publish_user_callback_t> esphome::mqtt::MQTTBackendESP32::on_publish_
protected

Definition at line 267 of file mqtt_backend_esp32.h.

◆ on_subscribe_

CallbackManager<on_subscribe_callback_t> esphome::mqtt::MQTTBackendESP32::on_subscribe_
protected

Definition at line 264 of file mqtt_backend_esp32.h.

◆ on_unsubscribe_

CallbackManager<on_unsubscribe_callback_t> esphome::mqtt::MQTTBackendESP32::on_unsubscribe_
protected

Definition at line 265 of file mqtt_backend_esp32.h.

◆ password_

std::string esphome::mqtt::MQTTBackendESP32::password_
protected

Definition at line 240 of file mqtt_backend_esp32.h.

◆ port_

uint16_t esphome::mqtt::MQTTBackendESP32::port_
protected

Definition at line 238 of file mqtt_backend_esp32.h.

◆ skip_cert_cn_check_

bool esphome::mqtt::MQTTBackendESP32::skip_cert_cn_check_ {false}
protected

Definition at line 251 of file mqtt_backend_esp32.h.

◆ task_handle_

TaskHandle_t esphome::mqtt::MQTTBackendESP32::task_handle_ {nullptr}
protected

Definition at line 256 of file mqtt_backend_esp32.h.

◆ TASK_PRIORITY

const ssize_t esphome::mqtt::MQTTBackendESP32::TASK_PRIORITY = 5
static

Definition at line 121 of file mqtt_backend_esp32.h.

◆ TASK_STACK_SIZE

const size_t esphome::mqtt::MQTTBackendESP32::TASK_STACK_SIZE = 3072
static

Definition at line 119 of file mqtt_backend_esp32.h.

◆ TASK_STACK_SIZE_TLS

const size_t esphome::mqtt::MQTTBackendESP32::TASK_STACK_SIZE_TLS = 4096
static

Definition at line 120 of file mqtt_backend_esp32.h.

◆ username_

std::string esphome::mqtt::MQTTBackendESP32::username_
protected

Definition at line 239 of file mqtt_backend_esp32.h.


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