feat: ws connect

This commit is contained in:
0Xiao0
2026-05-18 15:56:50 +08:00
parent 417f52d759
commit 928d40826f
5 changed files with 978 additions and 4 deletions

View File

@ -302,11 +302,15 @@ void Application::HandleActivationDoneEvent() {
SystemInfo::PrintHeapStats();
SetDeviceState(kDeviceStateIdle);
has_server_time_ = ota_->HasServerTime();
if (ota_ != nullptr) {
has_server_time_ = ota_->HasServerTime();
}
auto display = Board::GetInstance().GetDisplay();
std::string message = std::string(Lang::Strings::VERSION) + ota_->GetCurrentVersion();
display->ShowNotification(message.c_str());
if (ota_ != nullptr) {
std::string message = std::string(Lang::Strings::VERSION) + ota_->GetCurrentVersion();
display->ShowNotification(message.c_str());
}
display->SetChatMessage("system", "");
// Release OTA object after activation is complete
@ -321,6 +325,10 @@ void Application::HandleActivationDoneEvent() {
}
void Application::ActivationTask() {
#if CONFIG_USE_DIRECT_WEBSOCKET
CheckAssetsVersion();
InitializeProtocol();
#else
// Create OTA object for activation process
ota_ = std::make_unique<Ota>();
@ -332,6 +340,7 @@ void Application::ActivationTask() {
// Initialize the protocol
InitializeProtocol();
#endif
// Signal completion to main loop
xEventGroupSetBits(event_group_, MAIN_EVENT_ACTIVATION_DONE);
@ -477,6 +486,9 @@ void Application::InitializeProtocol() {
display->SetStatus(Lang::Strings::LOADING_PROTOCOL);
#if CONFIG_USE_DIRECT_WEBSOCKET
protocol_ = std::make_unique<WebsocketProtocol>();
#else
if (ota_->HasMqttConfig()) {
protocol_ = std::make_unique<MqttProtocol>();
} else if (ota_->HasWebsocketConfig()) {
@ -485,6 +497,7 @@ void Application::InitializeProtocol() {
ESP_LOGW(TAG, "No protocol specified in the OTA config, using MQTT");
protocol_ = std::make_unique<MqttProtocol>();
}
#endif
protocol_->OnConnected([this]() {
DismissAlert();
@ -1128,4 +1141,3 @@ void Application::ResetProtocol() {
protocol_.reset();
});
}