更新Wi-Fi组件版本,从OTA接口读取Websocket服务器

This commit is contained in:
Terrence
2025-04-21 15:12:52 +08:00
parent c380617cca
commit 3404180a77
15 changed files with 67 additions and 58 deletions

View File

@@ -78,6 +78,11 @@ void Application::CheckNewVersion() {
ESP_LOGE(TAG, "Too many retries, exit version check");
return;
}
char buffer[128];
snprintf(buffer, sizeof(buffer), Lang::Strings::CHECK_NEW_VERSION_FAILED, retry_delay, ota_.GetCheckVersionUrl().c_str());
Alert(Lang::Strings::ERROR, buffer, "sad", Lang::Sounds::P3_EXCLAMATION);
ESP_LOGW(TAG, "Check new version failed, retry in %d seconds (%d/%d)", retry_delay, retry_count, MAX_RETRY);
for (int i = 0; i < retry_delay; i++) {
vTaskDelay(pdMS_TO_TICKS(1000));
@@ -372,11 +377,16 @@ void Application::Start() {
// Initialize the protocol
display->SetStatus(Lang::Strings::LOADING_PROTOCOL);
#ifdef CONFIG_CONNECTION_TYPE_WEBSOCKET
protocol_ = std::make_unique<WebsocketProtocol>();
#else
protocol_ = std::make_unique<MqttProtocol>();
#endif
if (ota_.HasMqttConfig()) {
protocol_ = std::make_unique<MqttProtocol>();
} else if (ota_.HasWebsocketConfig()) {
protocol_ = std::make_unique<WebsocketProtocol>();
} else {
ESP_LOGW(TAG, "No protocol specified in the OTA config, using MQTT");
protocol_ = std::make_unique<MqttProtocol>();
}
protocol_->OnNetworkError([this](const std::string& message) {
SetDeviceState(kDeviceStateIdle);
Alert(Lang::Strings::ERROR, message.c_str(), "sad", Lang::Sounds::P3_EXCLAMATION);
@@ -529,7 +539,7 @@ void Application::Start() {
SetDeviceState(kDeviceStateConnecting);
wake_word_detect_.EncodeWakeWordData();
if (!protocol_->OpenAudioChannel()) {
if (!protocol_ || !protocol_->OpenAudioChannel()) {
wake_word_detect_.StartDetection();
return;
}