diff --git a/esphome/components/mqtt/mqtt_backend_esp8266.cpp b/esphome/components/mqtt/mqtt_backend_esp8266.cpp index ce5efbdff8..0604cd292f 100644 --- a/esphome/components/mqtt/mqtt_backend_esp8266.cpp +++ b/esphome/components/mqtt/mqtt_backend_esp8266.cpp @@ -13,14 +13,14 @@ namespace mqtt { static const char *const TAG = "mqtt-backend-esp8266"; void MQTTBackendESP8266::on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length) { - static_cast(client->ref)->on_mqtt_message(client, topic, bytes, length); + static_cast(client->ref)->on_mqtt_message_(client, topic, bytes, length); } -void MQTTBackendESP8266::on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length) { +void MQTTBackendESP8266::on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length) { this->on_message_.call(topic, bytes, length, 0, length); } -void MQTTBackendESP8266::initialize() { +void MQTTBackendESP8266::initialize_() { #ifdef USE_MQTT_SECURE_CLIENT if (this->ca_certificate_str_.has_value()) { this->ca_certificate_.append(this->ca_certificate_str_.value().c_str()); @@ -35,21 +35,23 @@ void MQTTBackendESP8266::initialize() { #endif this->mqtt_client_.ref = this; - mqtt_client_.onMessageAdvanced(MQTTBackendESP8266::on_mqtt_message_wrapper_); + mqtt_client_.onMessageAdvanced(MQTTBackendESP8266::on_mqtt_message_wrapper); this->is_initalized_ = true; } -void MQTTBackendESP8266::handleErrors() { +void MQTTBackendESP8266::handle_errors_() { lwmqtt_err_t error = this->mqtt_client_.lastError(); lwmqtt_return_code_t return_code = this->mqtt_client_.returnCode(); if (error != LWMQTT_SUCCESS) { ESP_LOGD(TAG, "Error: %d, returnCode: %d", error, return_code); + /* char buffer[128]; int code = this->wifi_client_.getLastSSLError(buffer, sizeof(buffer)); if (code != 0) { ESP_LOGD(TAG, "SSL error code %d: %s", code, buffer); } + */ MQTTClientDisconnectReason reason = MQTTClientDisconnectReason::TCP_DISCONNECTED; @@ -84,11 +86,11 @@ void MQTTBackendESP8266::handleErrors() { void MQTTBackendESP8266::connect() { if (!this->is_initalized_) { - this->initialize(); + this->initialize_(); } this->mqtt_client_.begin(this->host_.c_str(), this->port_, this->wifi_client_); this->mqtt_client_.connect(this->client_id_.c_str(), this->username_.c_str(), this->password_.c_str()); - this->handleErrors(); + this->handle_errors_(); } void MQTTBackendESP8266::loop() { diff --git a/esphome/components/mqtt/mqtt_backend_esp8266.h b/esphome/components/mqtt/mqtt_backend_esp8266.h index d3386d7cfb..93cb4a76e4 100644 --- a/esphome/components/mqtt/mqtt_backend_esp8266.h +++ b/esphome/components/mqtt/mqtt_backend_esp8266.h @@ -94,10 +94,10 @@ class MQTTBackendESP8266 final : public MQTTBackend { void set_ssl_fingerprint(const std::array &fingerprint) { this->ssl_fingerprint_ = fingerprint; }; protected: - void initialize(); - void handleErrors(); + void initialize_(); + void handle_errors_(); static void on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length); - void on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length); + void on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length); #ifdef USE_MQTT_SECURE_CLIENT WiFiClientSecure wifi_client_; diff --git a/esphome/components/mqtt/mqtt_backend_libretiny.cpp b/esphome/components/mqtt/mqtt_backend_libretiny.cpp index 4aa3a739d0..23a144fec5 100644 --- a/esphome/components/mqtt/mqtt_backend_libretiny.cpp +++ b/esphome/components/mqtt/mqtt_backend_libretiny.cpp @@ -13,20 +13,20 @@ namespace mqtt { static const char *const TAG = "mqtt-backend-libretiny"; void MQTTBackendLibreTiny::on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length) { - static_cast(client->ref)->on_mqtt_message(client, topic, bytes, length); + static_cast(client->ref)->on_mqtt_message_(client, topic, bytes, length); } -void MQTTBackendLibreTiny::on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length) { +void MQTTBackendLibreTiny::on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length) { this->on_message_.call(topic, bytes, length, 0, length); } -void MQTTBackendLibreTiny::initialize() { +void MQTTBackendLibreTiny::initialize_() { this->mqtt_client_.ref = this; - mqtt_client_.onMessageAdvanced(MQTTBackendLibreTiny::on_mqtt_message_wrapper_); + mqtt_client_.onMessageAdvanced(MQTTBackendLibreTiny::on_mqtt_message_wrapper); this->is_initalized_ = true; } -void MQTTBackendLibreTiny::handleErrors() { +void MQTTBackendLibreTiny::handleErrors_() { lwmqtt_err_t error = this->mqtt_client_.lastError(); lwmqtt_return_code_t return_code = this->mqtt_client_.returnCode(); if (error != LWMQTT_SUCCESS) { @@ -65,11 +65,11 @@ void MQTTBackendLibreTiny::handleErrors() { void MQTTBackendLibreTiny::connect() { if (!this->is_initalized_) { - this->initialize(); + this->initialize_(); } this->mqtt_client_.begin(this->host_.c_str(), this->port_, this->wifi_client_); this->mqtt_client_.connect(this->client_id_.c_str(), this->username_.c_str(), this->password_.c_str()); - this->handleErrors(); + this->handleErrors_(); } void MQTTBackendLibreTiny::loop() { diff --git a/esphome/components/mqtt/mqtt_backend_libretiny.h b/esphome/components/mqtt/mqtt_backend_libretiny.h index 7f2c8d7ea7..3b6edbae0f 100644 --- a/esphome/components/mqtt/mqtt_backend_libretiny.h +++ b/esphome/components/mqtt/mqtt_backend_libretiny.h @@ -93,10 +93,10 @@ class MQTTBackendLibreTiny final : public MQTTBackend { void set_ssl_fingerprint(const std::array &fingerprint) { this->ssl_fingerprint_ = fingerprint; }; protected: - void initialize(); - void handleErrors(); + void initialize_(); + void handleErrors_(); static void on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length); - void on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length); + void on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length); WiFiClient wifi_client_; MQTTClient mqtt_client_; diff --git a/platformio.ini b/platformio.ini index ee18068a29..db846f39ba 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,7 +59,7 @@ lib_deps = ${common.lib_deps} SPI ; spi (Arduino built-in) Wire ; i2c (Arduino built-int) - heman/AsyncMqttClient-esphome@1.0.0 ; mqtt + 256dpi/MQTT@2.5.2 ; mqtt esphome/ESPAsyncWebServer-esphome@3.2.2 ; web_server_base fastled/FastLED@3.3.2 ; fastled_base mikalhart/TinyGPSPlus@1.0.2 ; gps