diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index ca615a6d98..bfc7f14891 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -118,7 +118,7 @@ void APIConnection::loop() { // when network is disconnected force disconnect immediately // don't wait for timeout this->on_fatal_error(); - ESP_LOGW(TAG, "%s: Network unavailable, disconnecting", this->client_combined_info_.c_str()); + ESP_LOGW(TAG, "%s: Network unavailable; disconnecting", this->client_combined_info_.c_str()); return; } if (this->next_close_) { @@ -182,24 +182,23 @@ void APIConnection::loop() { // Disconnect if not responded within 2.5*keepalive if (now - this->last_traffic_ > (KEEPALIVE_TIMEOUT_MS * 5) / 2) { on_fatal_error(); - ESP_LOGW(TAG, "%s didn't respond to ping request in time. Disconnecting...", this->client_combined_info_.c_str()); + ESP_LOGW(TAG, "%s is unresponsive; disconnecting", this->client_combined_info_.c_str()); } } else if (now - this->last_traffic_ > KEEPALIVE_TIMEOUT_MS && now > this->next_ping_retry_) { - ESP_LOGVV(TAG, "Sending keepalive PING..."); + ESP_LOGVV(TAG, "Sending keepalive PING"); this->sent_ping_ = this->send_ping_request(PingRequest()); if (!this->sent_ping_) { + char warn_str[38]; this->next_ping_retry_ = now + ping_retry_interval; this->ping_retries_++; + sprintf(warn_str, "Sending keepalive failed %u time(s); ", this->ping_retries_); if (this->ping_retries_ >= max_ping_retries) { on_fatal_error(); - ESP_LOGE(TAG, "%s: Sending keepalive failed %d time(s). Disconnecting...", this->client_combined_info_.c_str(), - this->ping_retries_); + ESP_LOGE(TAG, "%s: %sdisconnecting", this->client_combined_info_.c_str(), warn_str); } else if (this->ping_retries_ >= 10) { - ESP_LOGW(TAG, "%s: Sending keepalive failed %d time(s), will retry in %d ms", - this->client_combined_info_.c_str(), this->ping_retries_, ping_retry_interval); + ESP_LOGW(TAG, "%s: %sretrying in %u ms", this->client_combined_info_.c_str(), warn_str, ping_retry_interval); } else { - ESP_LOGD(TAG, "%s: Sending keepalive failed %d time(s), will retry in %d ms", - this->client_combined_info_.c_str(), this->ping_retries_, ping_retry_interval); + ESP_LOGD(TAG, "%s: %sretrying in %u ms", this->client_combined_info_.c_str(), warn_str, ping_retry_interval); } } } @@ -270,7 +269,7 @@ DisconnectResponse APIConnection::disconnect(const DisconnectRequest &msg) { // remote initiated disconnect_client // don't close yet, we still need to send the disconnect response // close will happen on next loop - ESP_LOGD(TAG, "%s requested disconnected", this->client_combined_info_.c_str()); + ESP_LOGD(TAG, "%s disconnected", this->client_combined_info_.c_str()); this->next_close_ = true; DisconnectResponse resp; return resp; @@ -1472,7 +1471,7 @@ void APIConnection::update_command(const UpdateCommandRequest &msg) { update->check(); break; case enums::UPDATE_COMMAND_NONE: - ESP_LOGE(TAG, "UPDATE_COMMAND_NONE not handled. Check client is sending the correct command"); + ESP_LOGE(TAG, "UPDATE_COMMAND_NONE not handled; confirm command is correct"); break; default: ESP_LOGW(TAG, "Unknown update command: %" PRIu32, msg.command); @@ -1534,7 +1533,7 @@ ConnectResponse APIConnection::connect(const ConnectRequest &msg) { // bool invalid_password = 1; resp.invalid_password = !correct; if (correct) { - ESP_LOGD(TAG, "%s: Connected successfully", this->client_combined_info_.c_str()); + ESP_LOGD(TAG, "%s connected", this->client_combined_info_.c_str()); this->connection_state_ = ConnectionState::AUTHENTICATED; this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_); #ifdef USE_HOMEASSISTANT_TIME @@ -1605,7 +1604,7 @@ void APIConnection::execute_service(const ExecuteServiceRequest &msg) { } } if (!found) { - ESP_LOGV(TAG, "Could not find matching service!"); + ESP_LOGV(TAG, "Could not find service"); } } #ifdef USE_API_NOISE @@ -1674,11 +1673,11 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) } void APIConnection::on_unauthenticated_access() { this->on_fatal_error(); - ESP_LOGD(TAG, "%s: tried to access without authentication.", this->client_combined_info_.c_str()); + ESP_LOGD(TAG, "%s requested access without authentication", this->client_combined_info_.c_str()); } void APIConnection::on_no_setup_connection() { this->on_fatal_error(); - ESP_LOGD(TAG, "%s: tried to access without full connection.", this->client_combined_info_.c_str()); + ESP_LOGD(TAG, "%s requested access without full connection", this->client_combined_info_.c_str()); } void APIConnection::on_fatal_error() { this->helper_->close(); diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 19263f2f2c..54b80a0852 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -780,7 +780,7 @@ extern "C" { // declare how noise generates random bytes (here with a good HWRNG based on the RF system) void noise_rand_bytes(void *output, size_t len) { if (!esphome::random_bytes(reinterpret_cast(output), len)) { - ESP_LOGE(TAG, "Failed to acquire random bytes, rebooting!"); + ESP_LOGE(TAG, "Acquiring random bytes failed; rebooting"); arch_restart(); } }