From b1a4fd15179c1996ee846af1a83547adfdf06bde Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Thu, 9 Jul 2026 17:02:56 +0300 Subject: [PATCH 01/12] Fixing zero packet send. --- aether/client_messages/p2p_message_stream.cpp | 12 +++++ .../cloud_server_connections.cpp | 6 +++ .../client_server_connection.cpp | 9 ++++ .../server_connections/server_connection.cpp | 5 ++ aether/transport/system_sockets/udp/udp.h | 2 + aether/wifi/esp_wifi_driver.cpp | 13 +++-- aether/write_action/buffer_write.h | 51 ++++++++++++++++++- 7 files changed, 93 insertions(+), 5 deletions(-) diff --git a/aether/client_messages/p2p_message_stream.cpp b/aether/client_messages/p2p_message_stream.cpp index c202645f..a6e73325 100644 --- a/aether/client_messages/p2p_message_stream.cpp +++ b/aether/client_messages/p2p_message_stream.cpp @@ -42,8 +42,15 @@ class MessageSendStream final : public IStream { } WriteAction& Write(AeMessage&& message) override { + AE_TELED_ERROR("[CALL-CHAIN] MessageSendStream::Write data_size={} " + "cloud_connections={}", + message.data.size(), cloud_connection_->count_connections()); return cloud_connection_->CallApi( ApiCall{[&message](ApiContext& auth_api, auto*) { + AE_TELED_ERROR( + "[CALL-CHAIN] MessageSendStream::ApiCall send_message " + "data_size={}", + message.data.size()); auth_api->send_message(std::move(message)); }}, request_policy_); @@ -165,9 +172,12 @@ P2pStream::P2pStream(AeContext const& ae_context, Ptr const& client, P2pStream::~P2pStream() = default; WriteAction& P2pStream::Write(DataBuffer&& data) { + AE_TELED_ERROR("[CALL-CHAIN] P2pStream::Write input_size={}", data.size()); AE_TELED_DEBUG("Write message for uid {} size:{} data:{}", destination_, data.size(), data); AeMessage message_data{destination_, std::move(data)}; + AE_TELED_ERROR("[CALL-CHAIN] P2pStream::Write message_data_size={}", + message_data.data.size()); return buffer_write_.Write(std::move(message_data)); } @@ -245,6 +255,8 @@ std::unique_ptr P2pStream::MakeDestinationCloudConn( } WriteAction* P2pStream::OnWrite(AeMessage&& message) { + AE_TELED_ERROR("[CALL-CHAIN] P2pStream::OnWrite data_size={} connected={}", + message.data.size(), message_send_stream_ != nullptr); if (!message_send_stream_) { return {}; } diff --git a/aether/cloud_connections/cloud_server_connections.cpp b/aether/cloud_connections/cloud_server_connections.cpp index 576b97d8..0d246f21 100644 --- a/aether/cloud_connections/cloud_server_connections.cpp +++ b/aether/cloud_connections/cloud_server_connections.cpp @@ -275,15 +275,21 @@ std::vector CloudServerConnections::ServerCandidates() { WriteAction& CloudServerConnections::CallApi(ApiCall const& api_caller, RequestPolicy::Variant policy) { + AE_TELED_ERROR("[CALL-CHAIN] CloudServerConnections::CallApi selected={}", + selected_servers_.size()); std::vector swas; ForServers( [&](CloudServerConnection* sc) { auto* conn = sc->client_connection(); assert((conn != nullptr) && "Client connection is null"); + AE_TELED_ERROR("[CALL-CHAIN] CloudServerConnections::CallApi server={}", + sc->server()->server_id); swas.emplace_back(&conn->AuthorizedApiCall( SubApi{[&](auto& api) { api_caller(api, sc); }})); }, policy); + AE_TELED_ERROR("[CALL-CHAIN] CloudServerConnections::CallApi writes={}", + swas.size()); if (swas.empty()) { return EmptyWriteAction(); diff --git a/aether/server_connections/client_server_connection.cpp b/aether/server_connections/client_server_connection.cpp index 66d29b46..9df34ea8 100644 --- a/aether/server_connections/client_server_connection.cpp +++ b/aether/server_connections/client_server_connection.cpp @@ -95,6 +95,11 @@ BufferedServerConnection::BufferedServerConnection(AeContext const& ae_context, Ptr const& server) : buffer_write{ae_context, [&](DataBuffer&& in_data) -> WriteAction* { + AE_TELED_ERROR( + "[CALL-CHAIN] BufferedServerConnection::direct " + "data_size={} writable={}", + in_data.size(), + server_connection.stream_info().is_writable); if (server_connection.stream_info().is_writable) { return &server_connection.Write(std::move(in_data)); } @@ -118,6 +123,8 @@ BufferedServerConnection::BufferedServerConnection(AeContext const& ae_context, } WriteAction& BufferedServerConnection::Write(DataBuffer&& in_data) { + AE_TELED_ERROR("[CALL-CHAIN] BufferedServerConnection::Write data_size={}", + in_data.size()); return buffer_write.Write(std::move(in_data)); } @@ -182,8 +189,10 @@ WriteAction& ClientServerConnection::LoginApiCall(SubApi login_api) { WriteAction& ClientServerConnection::AuthorizedApiCall( SubApi auth_api) { + AE_TELED_ERROR("[CALL-CHAIN] ClientServerConnection::AuthorizedApiCall begin"); auto api_call = ApiCallAdapter{ApiContext{login_api_}, server_connection_}; api_call->login_by_alias(ephemeral_uid_, std::move(auth_api)); + AE_TELED_ERROR("[CALL-CHAIN] ClientServerConnection::AuthorizedApiCall flush"); // cppcheck reports false positive // cppcheck-suppress returnReference return api_call.Flush(); diff --git a/aether/server_connections/server_connection.cpp b/aether/server_connections/server_connection.cpp index cd0100df..e871992f 100644 --- a/aether/server_connections/server_connection.cpp +++ b/aether/server_connections/server_connection.cpp @@ -34,9 +34,14 @@ ServerConnection::ServerConnection(AeContext const& ae_context, } WriteAction& ServerConnection::Write(DataBuffer&& in_data) { + AE_TELED_ERROR("[CALL-CHAIN] ServerConnection::Write data_size={} " + "top_channel={}", + in_data.size(), top_channel_ != nullptr); assert((top_channel_ != nullptr) && "channel connection is not available"); auto* stream = top_channel_->connection.stream(); + AE_TELED_ERROR("[CALL-CHAIN] ServerConnection::Write stream={}", + stream != nullptr); assert((stream != nullptr) && "channel stream is not available"); return stream->Write(std::move(in_data)); diff --git a/aether/transport/system_sockets/udp/udp.h b/aether/transport/system_sockets/udp/udp.h index 9e574c9b..85d6bd31 100644 --- a/aether/transport/system_sockets/udp/udp.h +++ b/aether/transport/system_sockets/udp/udp.h @@ -157,6 +157,8 @@ class UdpTransport final : public upd_internal::UdpBase { } WriteAction& Write(DataBuffer&& in_data) override { + AE_TELED_ERROR("[CALL-CHAIN] UdpTransport::Write endpoint={} data_size={}", + endpoint_, in_data.size()); assert(in_data.size() != 0); AE_TELE_DEBUG(kUdpTransportSend, "Socket {} send data size:{}", endpoint_, in_data.size()); diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index 50d451ac..439ec72a 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -79,7 +79,7 @@ void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, } } -void SetupBssid(wifi_config_t& wifi_config, +esp_err_t SetupBssid(wifi_config_t& wifi_config, WiFiBaseStation const& base_station) { std::array debug_bssid; memcpy(debug_bssid.data(), base_station.target_bssid, @@ -93,8 +93,9 @@ void SetupBssid(wifi_config_t& wifi_config, // Copy the BSSID to the configuration memcpy(wifi_config.sta.bssid, base_station.target_bssid, sizeof(base_station.target_bssid)); - ESP_ERROR_CHECK( - esp_wifi_set_channel(base_station.target_channel, WIFI_SECOND_CHAN_NONE)); + auto err = esp_wifi_set_channel(base_station.target_channel, WIFI_SECOND_CHAN_NONE); + + return err; } void SetupCredentials(wifi_config_t& wifi_config, WifiCreds const& creds) { @@ -210,7 +211,11 @@ void StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, wifi_config_t wifi_config{}; if (base_station) { // Restore saved Base Station - esp_wifi_driver_internal::SetupBssid(wifi_config, *base_station); + auto err = esp_wifi_driver_internal::SetupBssid(wifi_config, *base_station); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set BSSID"); + // If an error occurs, exit + } } wifi_scan_threshold_t wifi_threshold{}; diff --git a/aether/write_action/buffer_write.h b/aether/write_action/buffer_write.h index 3a18370e..be1909fa 100644 --- a/aether/write_action/buffer_write.h +++ b/aether/write_action/buffer_write.h @@ -68,8 +68,20 @@ class BufferWrite { struct BufferEntry { BufferedWriteAction wa; T data; + bool sent = false; }; + template + static std::size_t DebugPayloadSize(TValue const& value) { + if constexpr (requires { value.size(); }) { + return value.size(); + } else if constexpr (requires { value.data.size(); }) { + return value.data.size(); + } else { + return 0; + } + } + public: using DirectWriteFunc = SmallFunction; @@ -82,8 +94,14 @@ class BufferWrite { /** * \brief Control buffering. */ - void buffer_on() { buffer_on_ = true; } + void buffer_on() { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::buffer_on buffered={}", + buffer_.size()); + buffer_on_ = true; + } void buffer_off() { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::buffer_off buffered={}", + buffer_.size()); buffer_on_ = false; DrainBuffer(); } @@ -93,6 +111,9 @@ class BufferWrite { * \brief Write data to or through buffer. */ WriteAction& Write(T&& data) { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::Write payload_size={} " + "buffer_on={} buffered={}", + DebugPayloadSize(data), buffer_on_, buffer_.size()); auto should_be_buffered = buffer_on_ || !buffer_.empty(); if (should_be_buffered) { return WriteToBuffer(std::move(data)); @@ -114,6 +135,9 @@ class BufferWrite { private: WriteAction& WriteToBuffer(T&& data) { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::WriteToBuffer payload_size={} " + "buffer_on={} buffered={}", + DebugPayloadSize(data), buffer_on_, buffer_.size()); if (buffer_.full()) { BW_LOG_WARNING("Buffer is full"); return FailedWrite(); @@ -135,8 +159,13 @@ class BufferWrite { } WriteAction& DirectWrite(T&& data) { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DirectWrite payload_size={} " + "buffered={}", + DebugPayloadSize(data), buffer_.size()); BW_LOG_DEBUG("BufferWrite: direct write"); auto* write_action = direct_write_(std::move(data)); + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DirectWrite result={}", + write_action != nullptr); if (write_action == nullptr) { return FailedWrite(); } @@ -147,24 +176,44 @@ class BufferWrite { * Write all buffered data in FIFO order. */ void DrainBuffer() { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer begin buffer_on={} " + "buffered={}", + buffer_on_, buffer_.size()); BW_LOG_DEBUG("BufferWrite: drain the buffer, size {}", buffer_.size()); // try send as many as possible for (auto& be : buffer_) { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer entry finished={} " + "sent={} payload_size={}", + be.wa.is_finished(), be.sent, DebugPayloadSize(be.data)); if (be.wa.is_finished()) { // notice! circular buffer pop is just incrementing the out pointer it // does not invalidate the iterators buffer_.pop(); continue; } + if (be.sent) { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer skip in-flight " + "payload_size={}", + DebugPayloadSize(be.data)); + continue; + } // buffer state might change during direct write if (buffer_on_) { + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer stop buffer_on"); break; } + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer direct before_move " + "payload_size={}", + DebugPayloadSize(be.data)); auto* dwa = direct_write_(std::move(be.data)); + BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer direct result={} " + "after_move_payload_size={}", + dwa != nullptr, DebugPayloadSize(be.data)); // empty write action means no data has been written if (dwa == nullptr) { break; } + be.sent = true; be.wa.Sent(*dwa); } } From c3838528916bb4f15872adea714406b29f114a01 Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Fri, 10 Jul 2026 16:23:43 +0300 Subject: [PATCH 02/12] Removing debug messages. --- aether/client_messages/p2p_message_stream.cpp | 13 +------- .../cloud_server_connections.cpp | 10 ++---- .../client_server_connection.cpp | 9 ------ .../server_connections/server_connection.cpp | 5 --- aether/transport/system_sockets/udp/udp.h | 2 -- aether/write_action/buffer_write.h | 31 ------------------- 6 files changed, 3 insertions(+), 67 deletions(-) diff --git a/aether/client_messages/p2p_message_stream.cpp b/aether/client_messages/p2p_message_stream.cpp index a6e73325..d64f5fdc 100644 --- a/aether/client_messages/p2p_message_stream.cpp +++ b/aether/client_messages/p2p_message_stream.cpp @@ -42,15 +42,8 @@ class MessageSendStream final : public IStream { } WriteAction& Write(AeMessage&& message) override { - AE_TELED_ERROR("[CALL-CHAIN] MessageSendStream::Write data_size={} " - "cloud_connections={}", - message.data.size(), cloud_connection_->count_connections()); return cloud_connection_->CallApi( ApiCall{[&message](ApiContext& auth_api, auto*) { - AE_TELED_ERROR( - "[CALL-CHAIN] MessageSendStream::ApiCall send_message " - "data_size={}", - message.data.size()); auth_api->send_message(std::move(message)); }}, request_policy_); @@ -172,12 +165,10 @@ P2pStream::P2pStream(AeContext const& ae_context, Ptr const& client, P2pStream::~P2pStream() = default; WriteAction& P2pStream::Write(DataBuffer&& data) { - AE_TELED_ERROR("[CALL-CHAIN] P2pStream::Write input_size={}", data.size()); AE_TELED_DEBUG("Write message for uid {} size:{} data:{}", destination_, data.size(), data); AeMessage message_data{destination_, std::move(data)}; - AE_TELED_ERROR("[CALL-CHAIN] P2pStream::Write message_data_size={}", - message_data.data.size()); + return buffer_write_.Write(std::move(message_data)); } @@ -255,8 +246,6 @@ std::unique_ptr P2pStream::MakeDestinationCloudConn( } WriteAction* P2pStream::OnWrite(AeMessage&& message) { - AE_TELED_ERROR("[CALL-CHAIN] P2pStream::OnWrite data_size={} connected={}", - message.data.size(), message_send_stream_ != nullptr); if (!message_send_stream_) { return {}; } diff --git a/aether/cloud_connections/cloud_server_connections.cpp b/aether/cloud_connections/cloud_server_connections.cpp index 0d246f21..5329038f 100644 --- a/aether/cloud_connections/cloud_server_connections.cpp +++ b/aether/cloud_connections/cloud_server_connections.cpp @@ -80,8 +80,8 @@ CloudServerConnections::servers_update_event() { return servers_update_event_; } -std::vector const& CloudServerConnections::selected_servers() - const { +std::vector const& +CloudServerConnections::selected_servers() const { return selected_servers_; } @@ -275,21 +275,15 @@ std::vector CloudServerConnections::ServerCandidates() { WriteAction& CloudServerConnections::CallApi(ApiCall const& api_caller, RequestPolicy::Variant policy) { - AE_TELED_ERROR("[CALL-CHAIN] CloudServerConnections::CallApi selected={}", - selected_servers_.size()); std::vector swas; ForServers( [&](CloudServerConnection* sc) { auto* conn = sc->client_connection(); assert((conn != nullptr) && "Client connection is null"); - AE_TELED_ERROR("[CALL-CHAIN] CloudServerConnections::CallApi server={}", - sc->server()->server_id); swas.emplace_back(&conn->AuthorizedApiCall( SubApi{[&](auto& api) { api_caller(api, sc); }})); }, policy); - AE_TELED_ERROR("[CALL-CHAIN] CloudServerConnections::CallApi writes={}", - swas.size()); if (swas.empty()) { return EmptyWriteAction(); diff --git a/aether/server_connections/client_server_connection.cpp b/aether/server_connections/client_server_connection.cpp index 9df34ea8..66d29b46 100644 --- a/aether/server_connections/client_server_connection.cpp +++ b/aether/server_connections/client_server_connection.cpp @@ -95,11 +95,6 @@ BufferedServerConnection::BufferedServerConnection(AeContext const& ae_context, Ptr const& server) : buffer_write{ae_context, [&](DataBuffer&& in_data) -> WriteAction* { - AE_TELED_ERROR( - "[CALL-CHAIN] BufferedServerConnection::direct " - "data_size={} writable={}", - in_data.size(), - server_connection.stream_info().is_writable); if (server_connection.stream_info().is_writable) { return &server_connection.Write(std::move(in_data)); } @@ -123,8 +118,6 @@ BufferedServerConnection::BufferedServerConnection(AeContext const& ae_context, } WriteAction& BufferedServerConnection::Write(DataBuffer&& in_data) { - AE_TELED_ERROR("[CALL-CHAIN] BufferedServerConnection::Write data_size={}", - in_data.size()); return buffer_write.Write(std::move(in_data)); } @@ -189,10 +182,8 @@ WriteAction& ClientServerConnection::LoginApiCall(SubApi login_api) { WriteAction& ClientServerConnection::AuthorizedApiCall( SubApi auth_api) { - AE_TELED_ERROR("[CALL-CHAIN] ClientServerConnection::AuthorizedApiCall begin"); auto api_call = ApiCallAdapter{ApiContext{login_api_}, server_connection_}; api_call->login_by_alias(ephemeral_uid_, std::move(auth_api)); - AE_TELED_ERROR("[CALL-CHAIN] ClientServerConnection::AuthorizedApiCall flush"); // cppcheck reports false positive // cppcheck-suppress returnReference return api_call.Flush(); diff --git a/aether/server_connections/server_connection.cpp b/aether/server_connections/server_connection.cpp index e871992f..cd0100df 100644 --- a/aether/server_connections/server_connection.cpp +++ b/aether/server_connections/server_connection.cpp @@ -34,14 +34,9 @@ ServerConnection::ServerConnection(AeContext const& ae_context, } WriteAction& ServerConnection::Write(DataBuffer&& in_data) { - AE_TELED_ERROR("[CALL-CHAIN] ServerConnection::Write data_size={} " - "top_channel={}", - in_data.size(), top_channel_ != nullptr); assert((top_channel_ != nullptr) && "channel connection is not available"); auto* stream = top_channel_->connection.stream(); - AE_TELED_ERROR("[CALL-CHAIN] ServerConnection::Write stream={}", - stream != nullptr); assert((stream != nullptr) && "channel stream is not available"); return stream->Write(std::move(in_data)); diff --git a/aether/transport/system_sockets/udp/udp.h b/aether/transport/system_sockets/udp/udp.h index 85d6bd31..9e574c9b 100644 --- a/aether/transport/system_sockets/udp/udp.h +++ b/aether/transport/system_sockets/udp/udp.h @@ -157,8 +157,6 @@ class UdpTransport final : public upd_internal::UdpBase { } WriteAction& Write(DataBuffer&& in_data) override { - AE_TELED_ERROR("[CALL-CHAIN] UdpTransport::Write endpoint={} data_size={}", - endpoint_, in_data.size()); assert(in_data.size() != 0); AE_TELE_DEBUG(kUdpTransportSend, "Socket {} send data size:{}", endpoint_, in_data.size()); diff --git a/aether/write_action/buffer_write.h b/aether/write_action/buffer_write.h index be1909fa..08a4109a 100644 --- a/aether/write_action/buffer_write.h +++ b/aether/write_action/buffer_write.h @@ -95,13 +95,9 @@ class BufferWrite { * \brief Control buffering. */ void buffer_on() { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::buffer_on buffered={}", - buffer_.size()); buffer_on_ = true; } void buffer_off() { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::buffer_off buffered={}", - buffer_.size()); buffer_on_ = false; DrainBuffer(); } @@ -111,9 +107,6 @@ class BufferWrite { * \brief Write data to or through buffer. */ WriteAction& Write(T&& data) { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::Write payload_size={} " - "buffer_on={} buffered={}", - DebugPayloadSize(data), buffer_on_, buffer_.size()); auto should_be_buffered = buffer_on_ || !buffer_.empty(); if (should_be_buffered) { return WriteToBuffer(std::move(data)); @@ -135,9 +128,6 @@ class BufferWrite { private: WriteAction& WriteToBuffer(T&& data) { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::WriteToBuffer payload_size={} " - "buffer_on={} buffered={}", - DebugPayloadSize(data), buffer_on_, buffer_.size()); if (buffer_.full()) { BW_LOG_WARNING("Buffer is full"); return FailedWrite(); @@ -159,13 +149,8 @@ class BufferWrite { } WriteAction& DirectWrite(T&& data) { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DirectWrite payload_size={} " - "buffered={}", - DebugPayloadSize(data), buffer_.size()); BW_LOG_DEBUG("BufferWrite: direct write"); auto* write_action = direct_write_(std::move(data)); - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DirectWrite result={}", - write_action != nullptr); if (write_action == nullptr) { return FailedWrite(); } @@ -176,15 +161,9 @@ class BufferWrite { * Write all buffered data in FIFO order. */ void DrainBuffer() { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer begin buffer_on={} " - "buffered={}", - buffer_on_, buffer_.size()); BW_LOG_DEBUG("BufferWrite: drain the buffer, size {}", buffer_.size()); // try send as many as possible for (auto& be : buffer_) { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer entry finished={} " - "sent={} payload_size={}", - be.wa.is_finished(), be.sent, DebugPayloadSize(be.data)); if (be.wa.is_finished()) { // notice! circular buffer pop is just incrementing the out pointer it // does not invalidate the iterators @@ -192,23 +171,13 @@ class BufferWrite { continue; } if (be.sent) { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer skip in-flight " - "payload_size={}", - DebugPayloadSize(be.data)); continue; } // buffer state might change during direct write if (buffer_on_) { - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer stop buffer_on"); break; } - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer direct before_move " - "payload_size={}", - DebugPayloadSize(be.data)); auto* dwa = direct_write_(std::move(be.data)); - BW_LOG_WARNING("[CALL-CHAIN] BufferWrite::DrainBuffer direct result={} " - "after_move_payload_size={}", - dwa != nullptr, DebugPayloadSize(be.data)); // empty write action means no data has been written if (dwa == nullptr) { break; From 84cf1c9804ad961b7652c55a496ab11e313a7f04 Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Fri, 10 Jul 2026 16:28:24 +0300 Subject: [PATCH 03/12] Removing DebugPayloadSize. --- aether/client_messages/p2p_message_stream.cpp | 1 - aether/write_action/buffer_write.h | 15 +-------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/aether/client_messages/p2p_message_stream.cpp b/aether/client_messages/p2p_message_stream.cpp index d64f5fdc..c202645f 100644 --- a/aether/client_messages/p2p_message_stream.cpp +++ b/aether/client_messages/p2p_message_stream.cpp @@ -168,7 +168,6 @@ WriteAction& P2pStream::Write(DataBuffer&& data) { AE_TELED_DEBUG("Write message for uid {} size:{} data:{}", destination_, data.size(), data); AeMessage message_data{destination_, std::move(data)}; - return buffer_write_.Write(std::move(message_data)); } diff --git a/aether/write_action/buffer_write.h b/aether/write_action/buffer_write.h index 08a4109a..ab15c918 100644 --- a/aether/write_action/buffer_write.h +++ b/aether/write_action/buffer_write.h @@ -71,17 +71,6 @@ class BufferWrite { bool sent = false; }; - template - static std::size_t DebugPayloadSize(TValue const& value) { - if constexpr (requires { value.size(); }) { - return value.size(); - } else if constexpr (requires { value.data.size(); }) { - return value.data.size(); - } else { - return 0; - } - } - public: using DirectWriteFunc = SmallFunction; @@ -94,9 +83,7 @@ class BufferWrite { /** * \brief Control buffering. */ - void buffer_on() { - buffer_on_ = true; - } + void buffer_on() { buffer_on_ = true; } void buffer_off() { buffer_on_ = false; DrainBuffer(); From 6a4120f7dd9a6688d9d2518493775af01b2ab60b Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Mon, 13 Jul 2026 16:39:26 +0300 Subject: [PATCH 04/12] Removing ESP_ERROR_CHECK. --- aether/wifi/esp_wifi_driver.cpp | 105 +++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 22 deletions(-) diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index 439ec72a..a531fff0 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -205,16 +205,19 @@ esp_err_t SetStaticIp(esp_netif_t* netif, WiFiIP const& config) { return ESP_OK; } -void StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, +esp_err_t StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, std::optional const& psp, std::optional const& base_station) { + esp_err_t err = ESP_OK; + wifi_config_t wifi_config{}; if (base_station) { // Restore saved Base Station auto err = esp_wifi_driver_internal::SetupBssid(wifi_config, *base_station); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set BSSID"); + AE_TELED_ERROR("Failed to set BSSID."); // If an error occurs, exit + return err; } } @@ -231,32 +234,70 @@ void StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, // Setting up a static IP, if required if (wifi_ap.static_ip.has_value()) { - auto err = esp_wifi_driver_internal::SetStaticIp(espt_init_sta, + err = esp_wifi_driver_internal::SetStaticIp(espt_init_sta, wifi_ap.static_ip.value()); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set static IP, falling back to DHCP"); + AE_TELED_ERROR("Failed to set static IP, falling back to DHCP."); // If an error occurs, switch to DHCP + return err; } } else { AE_TELED_DEBUG("Using DHCP for IP configuration"); } - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); - ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); + err = esp_wifi_set_mode(WIFI_MODE_STA); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set mode."); + // If an error occurs, exit + return err; + } + err = esp_wifi_set_config(WIFI_IF_STA, &wifi_config); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set config."); + // If an error occurs, exit + return err; + } if (psp) { - ESP_ERROR_CHECK( - esp_wifi_set_ps(static_cast(psp->wifi_ps_type))); - ESP_ERROR_CHECK(esp_wifi_set_protocol(WIFI_IF_STA, psp->protocol_bitmap)); + err = esp_wifi_set_ps(static_cast(psp->wifi_ps_type))); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set ps."); + // If an error occurs, exit + return err; + } + err = esp_wifi_set_protocol(WIFI_IF_STA, psp->protocol_bitmap); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set protocol."); + // If an error occurs, exit + return err; + } } - ESP_ERROR_CHECK(esp_wifi_start()); + err = esp_wifi_start(); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to start WiFi!"); + // If an error occurs, exit + return err; + } if (psp) { - ESP_ERROR_CHECK(esp_wifi_internal_set_fix_rate( - WIFI_IF_STA, true, static_cast(psp->fix_rate))); - ESP_ERROR_CHECK( - esp_wifi_internal_set_retry_counter(psp->short_retry, psp->long_retry)); - ESP_ERROR_CHECK(esp_wifi_set_max_tx_power(psp->power)); + err = esp_wifi_internal_set_fix_rate(WIFI_IF_STA, true, static_cast(psp->fix_rate)); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set fix rate."); + // If an error occurs, exit + return err; + } + err = esp_wifi_internal_set_retry_counter(psp->short_retry, psp->long_retry); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set retry counter."); + // If an error occurs, exit + return err; + } + err = esp_wifi_set_max_tx_power(psp->power); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to set tx power."); + // If an error occurs, exit + return err; + } } AE_TELED_DEBUG("WifiInitSta finished."); @@ -287,9 +328,13 @@ void EspWifiDriver::Connect( connection_state_ = {}; connection_state_.state = State::kConnecting; - esp_wifi_driver_internal::StartWifiConnection( + auto err = esp_wifi_driver_internal::StartWifiConnection( static_cast(espt_init_sta_), wifi_ap, psp, base_station); // the connection result will be handled in ConnectingEventHandler + if(err != ESP_OK){ + // Emitting the error, 2 for example. + connect_res_event_.Emit(Error(2)); + } } EspWifiDriver::ConnectResEvent::Subscriber EspWifiDriver::connect_res_event() { @@ -301,10 +346,22 @@ std::optional EspWifiDriver::connected_to() const { } void EspWifiDriver::Init() { + esp_err_t err = ESP_OK; + InitNvs(); - ESP_ERROR_CHECK(esp_netif_init()); - ESP_ERROR_CHECK(esp_event_loop_create_default()); + err = esp_netif_init(); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to netif init."); + // If an error occurs, exit + return; + } + err = esp_event_loop_create_default(); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to create event loop."); + // If an error occurs, exit + return; + } espt_init_sta_ = esp_netif_create_default_wifi_sta(); @@ -313,7 +370,12 @@ void EspWifiDriver::Init() { wifi_init_config.ampdu_rx_enable = 0; wifi_init_config.ampdu_tx_enable = 0; - ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config)); + err = esp_wifi_init(&wifi_init_config); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to wifi init."); + // If an error occurs, exit + return; + } esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, esp_wifi_driver_internal::EventHandler, this); @@ -327,10 +389,9 @@ void EspWifiDriver::InitNvs() { esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); + nvs_flash_erase(); + nvs_flash_init(); } - ESP_ERROR_CHECK(ret); } void EspWifiDriver::Deinit() { From 0e3f093aa22f63e71f4ca0e5580617fc7a736cff Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Mon, 13 Jul 2026 16:45:42 +0300 Subject: [PATCH 05/12] Formatting. --- aether/wifi/esp_wifi_driver.cpp | 78 +++++++++++++++++---------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index a531fff0..b84bdcb4 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -80,7 +80,7 @@ void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, } esp_err_t SetupBssid(wifi_config_t& wifi_config, - WiFiBaseStation const& base_station) { + WiFiBaseStation const& base_station) { std::array debug_bssid; memcpy(debug_bssid.data(), base_station.target_bssid, sizeof(base_station.target_bssid)); @@ -93,8 +93,9 @@ esp_err_t SetupBssid(wifi_config_t& wifi_config, // Copy the BSSID to the configuration memcpy(wifi_config.sta.bssid, base_station.target_bssid, sizeof(base_station.target_bssid)); - auto err = esp_wifi_set_channel(base_station.target_channel, WIFI_SECOND_CHAN_NONE); - + auto err = + esp_wifi_set_channel(base_station.target_channel, WIFI_SECOND_CHAN_NONE); + return err; } @@ -205,11 +206,12 @@ esp_err_t SetStaticIp(esp_netif_t* netif, WiFiIP const& config) { return ESP_OK; } -esp_err_t StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, - std::optional const& psp, - std::optional const& base_station) { +esp_err_t StartWifiConnection( + esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, + std::optional const& psp, + std::optional const& base_station) { esp_err_t err = ESP_OK; - + wifi_config_t wifi_config{}; if (base_station) { // Restore saved Base Station @@ -235,7 +237,7 @@ esp_err_t StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, // Setting up a static IP, if required if (wifi_ap.static_ip.has_value()) { err = esp_wifi_driver_internal::SetStaticIp(espt_init_sta, - wifi_ap.static_ip.value()); + wifi_ap.static_ip.value()); if (err != ESP_OK) { AE_TELED_ERROR("Failed to set static IP, falling back to DHCP."); // If an error occurs, switch to DHCP @@ -247,16 +249,16 @@ esp_err_t StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, err = esp_wifi_set_mode(WIFI_MODE_STA); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set mode."); - // If an error occurs, exit - return err; - } + AE_TELED_ERROR("Failed to set mode."); + // If an error occurs, exit + return err; + } err = esp_wifi_set_config(WIFI_IF_STA, &wifi_config); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set config."); - // If an error occurs, exit - return err; - } + AE_TELED_ERROR("Failed to set config."); + // If an error occurs, exit + return err; + } if (psp) { err = esp_wifi_set_ps(static_cast(psp->wifi_ps_type))); if (err != ESP_OK) { @@ -274,19 +276,21 @@ esp_err_t StartWifiConnection(esp_netif_t* espt_init_sta, WiFiAp const& wifi_ap, err = esp_wifi_start(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to start WiFi!"); - // If an error occurs, exit - return err; - } + AE_TELED_ERROR("Failed to start WiFi!"); + // If an error occurs, exit + return err; + } if (psp) { - err = esp_wifi_internal_set_fix_rate(WIFI_IF_STA, true, static_cast(psp->fix_rate)); + err = esp_wifi_internal_set_fix_rate( + WIFI_IF_STA, true, static_cast(psp->fix_rate)); if (err != ESP_OK) { AE_TELED_ERROR("Failed to set fix rate."); // If an error occurs, exit return err; } - err = esp_wifi_internal_set_retry_counter(psp->short_retry, psp->long_retry); + err = + esp_wifi_internal_set_retry_counter(psp->short_retry, psp->long_retry); if (err != ESP_OK) { AE_TELED_ERROR("Failed to set retry counter."); // If an error occurs, exit @@ -331,9 +335,9 @@ void EspWifiDriver::Connect( auto err = esp_wifi_driver_internal::StartWifiConnection( static_cast(espt_init_sta_), wifi_ap, psp, base_station); // the connection result will be handled in ConnectingEventHandler - if(err != ESP_OK){ + if (err != ESP_OK) { // Emitting the error, 2 for example. - connect_res_event_.Emit(Error(2)); + connect_res_event_.Emit(Error(2)); } } @@ -347,21 +351,21 @@ std::optional EspWifiDriver::connected_to() const { void EspWifiDriver::Init() { esp_err_t err = ESP_OK; - + InitNvs(); err = esp_netif_init(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to netif init."); - // If an error occurs, exit - return; - } + AE_TELED_ERROR("Failed to netif init."); + // If an error occurs, exit + return; + } err = esp_event_loop_create_default(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to create event loop."); - // If an error occurs, exit - return; - } + AE_TELED_ERROR("Failed to create event loop."); + // If an error occurs, exit + return; + } espt_init_sta_ = esp_netif_create_default_wifi_sta(); @@ -372,10 +376,10 @@ void EspWifiDriver::Init() { err = esp_wifi_init(&wifi_init_config); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to wifi init."); - // If an error occurs, exit - return; - } + AE_TELED_ERROR("Failed to wifi init."); + // If an error occurs, exit + return; + } esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, esp_wifi_driver_internal::EventHandler, this); From a51447b269e5edb016b236cfe91a27aecef740eb Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Mon, 13 Jul 2026 17:19:48 +0300 Subject: [PATCH 06/12] Removing ')'. --- aether/wifi/esp_wifi_driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index b84bdcb4..8160f977 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -260,7 +260,7 @@ esp_err_t StartWifiConnection( return err; } if (psp) { - err = esp_wifi_set_ps(static_cast(psp->wifi_ps_type))); + err = esp_wifi_set_ps(static_cast(psp->wifi_ps_type)); if (err != ESP_OK) { AE_TELED_ERROR("Failed to set ps."); // If an error occurs, exit From 09ba10513f1f66ab811fcb28b21d213ea7782f39 Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Mon, 13 Jul 2026 18:29:37 +0300 Subject: [PATCH 07/12] Fixing return from StartWifiConnection. --- aether/wifi/esp_wifi_driver.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index 8160f977..2786804c 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -305,6 +305,8 @@ esp_err_t StartWifiConnection( } AE_TELED_DEBUG("WifiInitSta finished."); + + return err; } } // namespace esp_wifi_driver_internal From 7ea266d2abdec416701fe6449895f9df82cd1880 Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Tue, 14 Jul 2026 10:56:43 +0300 Subject: [PATCH 08/12] Fixing "Data has been written size" message. --- aether/transport/system_sockets/udp/udp.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aether/transport/system_sockets/udp/udp.h b/aether/transport/system_sockets/udp/udp.h index 9e574c9b..06610366 100644 --- a/aether/transport/system_sockets/udp/udp.h +++ b/aether/transport/system_sockets/udp/udp.h @@ -60,8 +60,6 @@ class SendAction final : public PacketSendAction { SetStatus(WriteAction::Status::kFail); return; } - AE_TELED_DEBUG("Data has been written size {}", data_.size()); - if (*res == 0) { reenqueue_ = true; // Not sent yet @@ -72,6 +70,7 @@ class SendAction final : public PacketSendAction { SetStatus(WriteAction::Status::kFail); return; } + AE_TELED_DEBUG("Data has been written size {}", *res); SetStatus(WriteAction::Status::kSuccess); } From 1265b16f2ac6f42a8d8d81d6a2e98c0473c4defb Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Tue, 14 Jul 2026 11:00:14 +0300 Subject: [PATCH 09/12] Adding an error check. --- aether/wifi/esp_wifi_driver.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index 2786804c..e8f037d2 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -392,11 +392,19 @@ void EspWifiDriver::Init() { } void EspWifiDriver::InitNvs() { - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || - ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - nvs_flash_erase(); - nvs_flash_init(); + esp_err_t err = nvs_flash_init(); + if (err == ESP_ERR_NVS_NO_FREE_PAGES || + err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + err = nvs_flash_erase(); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to flash erase."); + return; + } + err = nvs_flash_init(); + if (err != ESP_OK) { + AE_TELED_ERROR("Failed to flash init."); + return; + } } } From 74fc4255e207b60718816f071cd8e8724743975d Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Wed, 15 Jul 2026 12:13:55 +0300 Subject: [PATCH 10/12] Change AE_TELE_x to ESP_LOGx. --- aether/wifi/esp_wifi_driver.cpp | 114 ++++++++++-------- .../aether-client-cpp/sdkconfig.defaults | 7 ++ 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/aether/wifi/esp_wifi_driver.cpp b/aether/wifi/esp_wifi_driver.cpp index e8f037d2..283df346 100644 --- a/aether/wifi/esp_wifi_driver.cpp +++ b/aether/wifi/esp_wifi_driver.cpp @@ -23,6 +23,7 @@ # include "nvs_flash.h" # include "esp_log.h" +# include "esp_mac.h" # include "esp_wifi.h" # include "esp_event.h" # include "esp_system.h" @@ -33,8 +34,6 @@ # include "lwip/ip4_addr.h" # include "lwip/ip6_addr.h" -# include "aether/tele/tele.h" - extern "C" esp_err_t esp_wifi_internal_set_retry_counter(uint8_t short_retry, uint8_t long_retry); extern "C" esp_err_t esp_wifi_internal_get_fix_rate(wifi_interface_t ifx, @@ -46,7 +45,9 @@ namespace ae { # define WIFI_FAIL_BIT BIT1 namespace esp_wifi_driver_internal { +static constexpr char kTag[] = "EspWifiDriver"; static constexpr int kMaxRetry = 10; + void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, [[maybe_unused]] void* event_data) { auto base_type = [](esp_event_base_t event_base) { @@ -59,7 +60,7 @@ void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, return "UNKNOWN_EVENT"; }; - ESP_LOGI("EspWiFiEventHandler", "Event handler event_base %s event_id %d", + ESP_LOGI(kTag, "Event handler event_base %s event_id %d", base_type(event_base), event_id); auto* driver = static_cast(arg); @@ -81,11 +82,9 @@ void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, esp_err_t SetupBssid(wifi_config_t& wifi_config, WiFiBaseStation const& base_station) { - std::array debug_bssid; - memcpy(debug_bssid.data(), base_station.target_bssid, - sizeof(base_station.target_bssid)); - AE_TELED_DEBUG("Restored from cash BSSID:{} CHN:{}", debug_bssid, - static_cast(base_station.target_channel)); + ESP_LOGD(kTag, "Restored from cache BSSID:" MACSTR " CHN:%u", + MAC2STR(base_station.target_bssid), + static_cast(base_station.target_channel)); wifi_config.sta.scan_method = WIFI_FAST_SCAN; // Fast scan wifi_config.sta.bssid_set = true; // Enable BSSID binding @@ -102,8 +101,8 @@ esp_err_t SetupBssid(wifi_config_t& wifi_config, void SetupCredentials(wifi_config_t& wifi_config, WifiCreds const& creds) { # ifdef DEBUG // for debug purpose only, it's private data - AE_TELED_DEBUG("Connecting to ap SSID:{} PSWD:{}", creds.ssid, - creds.password); + ESP_LOGD(kTag, "Connecting to ap SSID:%s PSWD:%s", creds.ssid.c_str(), + creds.password.c_str()); # endif // DEBUG strncpy(reinterpret_cast(wifi_config.sta.ssid), creds.ssid.data(), @@ -160,7 +159,7 @@ esp_err_t SetStaticIp(esp_netif_t* netif, WiFiIP const& config) { // Stopping the DHCP client err = esp_netif_dhcpc_stop(netif); if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) { - AE_TELED_ERROR("Failed to stop DHCP client: {}", esp_err_to_name(err)); + ESP_LOGE(kTag, "Failed to stop DHCP client: %s", esp_err_to_name(err)); return err; } @@ -168,7 +167,7 @@ esp_err_t SetStaticIp(esp_netif_t* netif, WiFiIP const& config) { // Setting a static IP err = esp_netif_set_ip_info(netif, &ip_info); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set IP info: {}", esp_err_to_name(err)); + ESP_LOGE(kTag, "Failed to set IP info: %s", esp_err_to_name(err)); return err; } @@ -176,7 +175,7 @@ esp_err_t SetStaticIp(esp_netif_t* netif, WiFiIP const& config) { if (config.primary_dns_v4) { err = esp_netif_set_dns_info(netif, ESP_NETIF_DNS_MAIN, &dns_info1); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set primary DNS: {}", esp_err_to_name(err)); + ESP_LOGE(kTag, "Failed to set primary DNS: %s", esp_err_to_name(err)); return err; } } @@ -184,22 +183,38 @@ esp_err_t SetStaticIp(esp_netif_t* netif, WiFiIP const& config) { if (config.secondary_dns_v4) { err = esp_netif_set_dns_info(netif, ESP_NETIF_DNS_BACKUP, &dns_info2); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set secondary DNS: {}", esp_err_to_name(err)); + ESP_LOGE(kTag, "Failed to set secondary DNS: %s", esp_err_to_name(err)); return err; } } - AE_TELED_DEBUG("Static IP V4 configured: {}", config.static_ip_v4); + ESP_LOGD(kTag, "Static IP V4 configured: %u.%u.%u.%u", + static_cast(config.static_ip_v4.ipv4_value[0]), + static_cast(config.static_ip_v4.ipv4_value[1]), + static_cast(config.static_ip_v4.ipv4_value[2]), + static_cast(config.static_ip_v4.ipv4_value[3])); # endif # if AE_SUPPORT_IPV6 == 1 if (config.static_ip_v6.has_value()) { err = esp_netif_set_ip6_global(netif, &ip_info_v6.ip); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set IP V6 info: {}", esp_err_to_name(err)); + ESP_LOGE(kTag, "Failed to set IP V6 info: %s", esp_err_to_name(err)); return err; } - AE_TELED_DEBUG("Static IP V6 configured: {}", config.static_ip_v6); + auto const& ip = config.static_ip_v6->ipv6_value; + ESP_LOGD(kTag, + "Static IP V6 configured: " + "%02x%02x:%02x%02x:%02x%02x:%02x%02x:" + "%02x%02x:%02x%02x:%02x%02x:%02x%02x", + static_cast(ip[0]), static_cast(ip[1]), + static_cast(ip[2]), static_cast(ip[3]), + static_cast(ip[4]), static_cast(ip[5]), + static_cast(ip[6]), static_cast(ip[7]), + static_cast(ip[8]), static_cast(ip[9]), + static_cast(ip[10]), static_cast(ip[11]), + static_cast(ip[12]), static_cast(ip[13]), + static_cast(ip[14]), static_cast(ip[15])); } # endif @@ -217,7 +232,7 @@ esp_err_t StartWifiConnection( // Restore saved Base Station auto err = esp_wifi_driver_internal::SetupBssid(wifi_config, *base_station); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set BSSID."); + ESP_LOGE(kTag, "Failed to set BSSID."); // If an error occurs, exit return err; } @@ -239,36 +254,36 @@ esp_err_t StartWifiConnection( err = esp_wifi_driver_internal::SetStaticIp(espt_init_sta, wifi_ap.static_ip.value()); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set static IP, falling back to DHCP."); + ESP_LOGE(kTag, "Failed to set static IP, falling back to DHCP."); // If an error occurs, switch to DHCP return err; } } else { - AE_TELED_DEBUG("Using DHCP for IP configuration"); + ESP_LOGD(kTag, "Using DHCP for IP configuration"); } err = esp_wifi_set_mode(WIFI_MODE_STA); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set mode."); + ESP_LOGE(kTag, "Failed to set mode."); // If an error occurs, exit return err; } err = esp_wifi_set_config(WIFI_IF_STA, &wifi_config); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set config."); + ESP_LOGE(kTag, "Failed to set config."); // If an error occurs, exit return err; } if (psp) { err = esp_wifi_set_ps(static_cast(psp->wifi_ps_type)); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set ps."); + ESP_LOGE(kTag, "Failed to set ps."); // If an error occurs, exit return err; } err = esp_wifi_set_protocol(WIFI_IF_STA, psp->protocol_bitmap); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set protocol."); + ESP_LOGE(kTag, "Failed to set protocol."); // If an error occurs, exit return err; } @@ -276,7 +291,7 @@ esp_err_t StartWifiConnection( err = esp_wifi_start(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to start WiFi!"); + ESP_LOGE(kTag, "Failed to start WiFi!"); // If an error occurs, exit return err; } @@ -285,27 +300,27 @@ esp_err_t StartWifiConnection( err = esp_wifi_internal_set_fix_rate( WIFI_IF_STA, true, static_cast(psp->fix_rate)); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set fix rate."); + ESP_LOGE(kTag, "Failed to set fix rate."); // If an error occurs, exit return err; } err = esp_wifi_internal_set_retry_counter(psp->short_retry, psp->long_retry); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set retry counter."); + ESP_LOGE(kTag, "Failed to set retry counter."); // If an error occurs, exit return err; } err = esp_wifi_set_max_tx_power(psp->power); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to set tx power."); + ESP_LOGE(kTag, "Failed to set tx power."); // If an error occurs, exit return err; } } - AE_TELED_DEBUG("WifiInitSta finished."); - + ESP_LOGD(kTag, "WifiInitSta finished."); + return err; } @@ -313,6 +328,7 @@ esp_err_t StartWifiConnection( EspWifiDriver::EspWifiDriver(AeContext const& ae_context) : ae_context_{ae_context} { + esp_log_level_set(esp_wifi_driver_internal::kTag, ESP_LOG_DEBUG); Init(); } @@ -358,13 +374,13 @@ void EspWifiDriver::Init() { err = esp_netif_init(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to netif init."); + ESP_LOGE(esp_wifi_driver_internal::kTag, "Failed to netif init."); // If an error occurs, exit return; } err = esp_event_loop_create_default(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to create event loop."); + ESP_LOGE(esp_wifi_driver_internal::kTag, "Failed to create event loop."); // If an error occurs, exit return; } @@ -378,7 +394,7 @@ void EspWifiDriver::Init() { err = esp_wifi_init(&wifi_init_config); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to wifi init."); + ESP_LOGE(esp_wifi_driver_internal::kTag, "Failed to wifi init."); // If an error occurs, exit return; } @@ -397,12 +413,12 @@ void EspWifiDriver::InitNvs() { err == ESP_ERR_NVS_NEW_VERSION_FOUND) { err = nvs_flash_erase(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to flash erase."); + ESP_LOGE(esp_wifi_driver_internal::kTag, "Failed to flash erase."); return; } err = nvs_flash_init(); if (err != ESP_OK) { - AE_TELED_ERROR("Failed to flash init."); + ESP_LOGE(esp_wifi_driver_internal::kTag, "Failed to flash init."); return; } } @@ -435,8 +451,9 @@ void EspWifiDriver::ConnectingEventHandler(esp_event_base_t event_base, break; case WIFI_EVENT_STA_DISCONNECTED: { auto* event = static_cast(event_data); - AE_TELED_DEBUG("Wifi event disconnected, reasone {}", - static_cast(event->reason)); + ESP_LOGD(esp_wifi_driver_internal::kTag, + "Wifi event disconnected, reason %d", + static_cast(event->reason)); if (connection_state_.retry_count < esp_wifi_driver_internal::kMaxRetry) { esp_wifi_connect(); @@ -463,18 +480,18 @@ void EspWifiDriver::ConnectingEventHandler(esp_event_base_t event_base, esp_wifi_sta_get_ap_info(&ap_info); // save real SSID connected_to_ = std::string(reinterpret_cast(ap_info.ssid)); - AE_TELED_DEBUG("Connected to AP {}", *connected_to_); + ESP_LOGD(esp_wifi_driver_internal::kTag, "Connected to AP %s", + connected_to_->c_str()); WiFiBaseStation base_station{}; base_station.target_channel = ap_info.primary; // Set channel // Copy the BSSID to the configuration memcpy(base_station.target_bssid, ap_info.bssid, sizeof(base_station.target_bssid)); - std::array debug_bssid; - memcpy(debug_bssid.data(), base_station.target_bssid, - sizeof(base_station.target_bssid)); - AE_TELED_DEBUG("Storing to cash BSSID:{} CHN:{}", debug_bssid, - static_cast(base_station.target_channel)); + ESP_LOGD(esp_wifi_driver_internal::kTag, + "Storing to cache BSSID:" MACSTR " CHN:%u", + MAC2STR(base_station.target_bssid), + static_cast(base_station.target_channel)); connection_state_.state = State::kConnected; event_task_sub_ = ae_context_.scheduler().Task( @@ -488,13 +505,14 @@ void EspWifiDriver::ConnectingEventHandler(esp_event_base_t event_base, } void EspWifiDriver::ConnectedEventHandler(esp_event_base_t event_base, int32_t event_id, void* event_data) { - AE_TELED_DEBUG("Wifi event on Connected"); + ESP_LOGD(esp_wifi_driver_internal::kTag, "Wifi event on Connected"); if (event_base == WIFI_EVENT) { switch (event_id) { case WIFI_EVENT_STA_DISCONNECTED: { auto* event = static_cast(event_data); - AE_TELED_DEBUG("Wifi event disconnected, reasone {}", - static_cast(event->reason)); + ESP_LOGD(esp_wifi_driver_internal::kTag, + "Wifi event disconnected, reason %d", + static_cast(event->reason)); break; } default: @@ -507,14 +525,14 @@ void EspWifiDriver::ConnectedEventHandler(esp_event_base_t event_base, void EspWifiDriver::DisconnectingEventHandler(esp_event_base_t /* event_base */, int32_t /* event_id */, void* /* event_data */) { - AE_TELED_DEBUG("Wifi event on Disconnecting"); + ESP_LOGD(esp_wifi_driver_internal::kTag, "Wifi event on Disconnecting"); // TODO: } void EspWifiDriver::DisconnectedEventHandler(esp_event_base_t /* event_base */, int32_t /* event_id */, void* /* event_data */) { - AE_TELED_DEBUG("Wifi event on Disconnected"); + ESP_LOGD(esp_wifi_driver_internal::kTag, "Wifi event on Disconnected"); // TODO: } diff --git a/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults b/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults index e07b476f..51321559 100644 --- a/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults +++ b/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults @@ -38,6 +38,8 @@ CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON=y CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y +CONFIG_LOG_DEFAULT_LEVEL_NONE=y +CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y # 3. Disabling logs (UART is the main brake at startup) CONFIG_LOG_DEFAULT_LEVEL_NONE=y @@ -68,6 +70,11 @@ CONFIG_RTC_CLK_SRC_INT_RC=y CONFIG_ESP_CONSOLE_UART_DEFAULT=y CONFIG_ESP_CONSOLE_SECONDARY_NONE=y +# Enable USB console +#CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n +#CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y +#CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED=y + # Disabling USB-Serial-JTAG clocking in sleep mode CONFIG_ESP_BROWNOUT_DET=n CONFIG_ESP_BROWNOUT_DET_LVL_SEL_7=y From 987b17718027e9edbdbdbba1cd51932f76110c8d Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Wed, 15 Jul 2026 14:50:02 +0300 Subject: [PATCH 11/12] Fixing some issues. --- aether/transport/system_sockets/udp/udp.h | 4 ++-- .../platformio/aether-client-cpp/sdkconfig.defaults | 7 +++++++ .../vscode/aether-client-cpp/sdkconfig.defaults | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aether/transport/system_sockets/udp/udp.h b/aether/transport/system_sockets/udp/udp.h index 06610366..bdfa3a71 100644 --- a/aether/transport/system_sockets/udp/udp.h +++ b/aether/transport/system_sockets/udp/udp.h @@ -60,6 +60,7 @@ class SendAction final : public PacketSendAction { SetStatus(WriteAction::Status::kFail); return; } + AE_TELED_DEBUG("Data has been written size {}", *res); if (*res == 0) { reenqueue_ = true; // Not sent yet @@ -69,8 +70,7 @@ class SendAction final : public PacketSendAction { AE_TELED_ERROR("Send error, sent size isn't same as packet size"); SetStatus(WriteAction::Status::kFail); return; - } - AE_TELED_DEBUG("Data has been written size {}", *res); + } SetStatus(WriteAction::Status::kSuccess); } diff --git a/projects/espressif_riscv/platformio/aether-client-cpp/sdkconfig.defaults b/projects/espressif_riscv/platformio/aether-client-cpp/sdkconfig.defaults index e07b476f..a6f0ec38 100644 --- a/projects/espressif_riscv/platformio/aether-client-cpp/sdkconfig.defaults +++ b/projects/espressif_riscv/platformio/aether-client-cpp/sdkconfig.defaults @@ -38,6 +38,8 @@ CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON=y CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y +CONFIG_LOG_DEFAULT_LEVEL_NONE=y +CONFIG_LOG_MAXIMUM_LEVEL_INFO=y # 3. Disabling logs (UART is the main brake at startup) CONFIG_LOG_DEFAULT_LEVEL_NONE=y @@ -68,6 +70,11 @@ CONFIG_RTC_CLK_SRC_INT_RC=y CONFIG_ESP_CONSOLE_UART_DEFAULT=y CONFIG_ESP_CONSOLE_SECONDARY_NONE=y +# Enable USB console +#CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=n +#CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y +#CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED=y + # Disabling USB-Serial-JTAG clocking in sleep mode CONFIG_ESP_BROWNOUT_DET=n CONFIG_ESP_BROWNOUT_DET_LVL_SEL_7=y diff --git a/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults b/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults index 51321559..a6f0ec38 100644 --- a/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults +++ b/projects/espressif_riscv/vscode/aether-client-cpp/sdkconfig.defaults @@ -39,7 +39,7 @@ CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON=y CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y CONFIG_LOG_DEFAULT_LEVEL_NONE=y -CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y +CONFIG_LOG_MAXIMUM_LEVEL_INFO=y # 3. Disabling logs (UART is the main brake at startup) CONFIG_LOG_DEFAULT_LEVEL_NONE=y From b8abc126b174526dafe8b666dbba4a5a375f3d30 Mon Sep 17 00:00:00 2001 From: Kiryanov D V Date: Thu, 16 Jul 2026 10:59:55 +0300 Subject: [PATCH 12/12] Deleting Wi-Fi credentials. --- examples/cloud/aether_construct_esp_wifi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cloud/aether_construct_esp_wifi.h b/examples/cloud/aether_construct_esp_wifi.h index 44c06177..41f08c23 100644 --- a/examples/cloud/aether_construct_esp_wifi.h +++ b/examples/cloud/aether_construct_esp_wifi.h @@ -22,8 +22,8 @@ #if CLOUD_TEST_ESP_WIFI namespace ae::cloud_test { -static const std::string kWifi1Ssid = "Visuale"; -static const std::string kWifi1Pass = "Ws63$yhJ"; +static const std::string kWifi1Ssid = "Test1234"; +static const std::string kWifi1Pass = "Test1234"; static const std::string kWifi2Ssid = "Test2345"; static const std::string kWifi2Pass = "Test2345";