Skip to content

Commit 3404180

Browse files
committed
更新Wi-Fi组件版本,从OTA接口读取Websocket服务器
1 parent c380617 commit 3404180

File tree

15 files changed

+67
-58
lines changed

15 files changed

+67
-58
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# CMakeLists in this exact order for cmake to work correctly
55
cmake_minimum_required(VERSION 3.16)
66

7-
set(PROJECT_VER "1.6.0")
7+
set(PROJECT_VER "1.6.1")
88

99
# Add this line to disable the specific warning
1010
add_compile_options(-Wno-missing-field-initializers)

docs/websocket.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
2. **建立 WebSocket 连接**
1515
- 当设备需要开始语音会话时(例如用户唤醒、手动按键触发等),调用 `OpenAudioChannel()`
16-
- 根据编译配置获取 WebSocket URL`CONFIG_WEBSOCKET_URL`
16+
- 根据配置获取 WebSocket URL
1717
- 设置若干请求头(`Authorization`, `Protocol-Version`, `Device-Id`, `Client-Id`
1818
- 调用 `Connect()` 与服务器建立 WebSocket 连接
1919

main/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ set(SOURCES "audio_codecs/audio_codec.cc"
1111
"display/lcd_display.cc"
1212
"display/oled_display.cc"
1313
"protocols/protocol.cc"
14+
"protocols/mqtt_protocol.cc"
15+
"protocols/websocket_protocol.cc"
1416
"iot/thing.cc"
1517
"iot/thing_manager.cc"
1618
"system_info.cc"
@@ -148,12 +150,6 @@ file(GLOB BOARD_SOURCES
148150
)
149151
list(APPEND SOURCES ${BOARD_SOURCES})
150152

151-
if(CONFIG_CONNECTION_TYPE_MQTT_UDP)
152-
list(APPEND SOURCES "protocols/mqtt_protocol.cc")
153-
elseif(CONFIG_CONNECTION_TYPE_WEBSOCKET)
154-
list(APPEND SOURCES "protocols/websocket_protocol.cc")
155-
endif()
156-
157153
if(CONFIG_USE_AUDIO_PROCESSOR)
158154
list(APPEND SOURCES "audio_processing/audio_processor.cc")
159155
endif()

main/Kconfig.projbuild

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
menu "Xiaozhi Assistant"
22

3-
config OTA_VERSION_URL
4-
string "OTA Version URL"
3+
config OTA_URL
4+
string "Default OTA URL"
55
default "https://api.tenclass.net/xiaozhi/ota/"
66
help
7-
The application will access this URL to check for updates.
7+
The application will access this URL to check for new firmwares and server address.
88

99

1010
choice
@@ -23,32 +23,6 @@ choice
2323
bool "Japanese"
2424
endchoice
2525

26-
27-
choice CONNECTION_TYPE
28-
prompt "Connection Type"
29-
default CONNECTION_TYPE_MQTT_UDP
30-
help
31-
网络数据传输协议
32-
config CONNECTION_TYPE_MQTT_UDP
33-
bool "MQTT + UDP"
34-
config CONNECTION_TYPE_WEBSOCKET
35-
bool "Websocket"
36-
endchoice
37-
38-
config WEBSOCKET_URL
39-
depends on CONNECTION_TYPE_WEBSOCKET
40-
string "Websocket URL"
41-
default "wss://api.tenclass.net/xiaozhi/v1/"
42-
help
43-
Communication with the server through websocket after wake up.
44-
45-
config WEBSOCKET_ACCESS_TOKEN
46-
depends on CONNECTION_TYPE_WEBSOCKET
47-
string "Websocket Access Token"
48-
default "test-token"
49-
help
50-
Access token for websocket communication.
51-
5226
choice BOARD_TYPE
5327
prompt "Board Type"
5428
default BOARD_TYPE_BREAD_COMPACT_WIFI

main/application.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ void Application::CheckNewVersion() {
7878
ESP_LOGE(TAG, "Too many retries, exit version check");
7979
return;
8080
}
81+
82+
char buffer[128];
83+
snprintf(buffer, sizeof(buffer), Lang::Strings::CHECK_NEW_VERSION_FAILED, retry_delay, ota_.GetCheckVersionUrl().c_str());
84+
Alert(Lang::Strings::ERROR, buffer, "sad", Lang::Sounds::P3_EXCLAMATION);
85+
8186
ESP_LOGW(TAG, "Check new version failed, retry in %d seconds (%d/%d)", retry_delay, retry_count, MAX_RETRY);
8287
for (int i = 0; i < retry_delay; i++) {
8388
vTaskDelay(pdMS_TO_TICKS(1000));
@@ -372,11 +377,16 @@ void Application::Start() {
372377

373378
// Initialize the protocol
374379
display->SetStatus(Lang::Strings::LOADING_PROTOCOL);
375-
#ifdef CONFIG_CONNECTION_TYPE_WEBSOCKET
376-
protocol_ = std::make_unique<WebsocketProtocol>();
377-
#else
378-
protocol_ = std::make_unique<MqttProtocol>();
379-
#endif
380+
381+
if (ota_.HasMqttConfig()) {
382+
protocol_ = std::make_unique<MqttProtocol>();
383+
} else if (ota_.HasWebsocketConfig()) {
384+
protocol_ = std::make_unique<WebsocketProtocol>();
385+
} else {
386+
ESP_LOGW(TAG, "No protocol specified in the OTA config, using MQTT");
387+
protocol_ = std::make_unique<MqttProtocol>();
388+
}
389+
380390
protocol_->OnNetworkError([this](const std::string& message) {
381391
SetDeviceState(kDeviceStateIdle);
382392
Alert(Lang::Strings::ERROR, message.c_str(), "sad", Lang::Sounds::P3_EXCLAMATION);
@@ -529,7 +539,7 @@ void Application::Start() {
529539
SetDeviceState(kDeviceStateConnecting);
530540
wake_word_detect_.EncodeWakeWordData();
531541

532-
if (!protocol_->OpenAudioChannel()) {
542+
if (!protocol_ || !protocol_->OpenAudioChannel()) {
533543
wake_word_detect_.StartDetection();
534544
return;
535545
}

main/assets/en-US/language.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
"ERROR": "Error",
99
"VERSION": "Ver ",
1010
"LOADING_PROTOCOL": "Logging in...",
11-
"CHECKING_NEW_VERSION": "Checking for new version...",
1211
"INITIALIZING": "Initializing...",
1312
"PIN_ERROR": "Please insert SIM card",
1413
"REG_ERROR": "Unable to access network, please check SIM card status",
1514
"DETECTING_MODULE": "Detecting module...",
1615
"REGISTERING_NETWORK": "Waiting for network...",
16+
"CHECKING_NEW_VERSION": "Checking for new version...",
17+
"CHECK_NEW_VERSION_FAILED": "Check for new version failed, will retry in %d seconds: %s",
1718

1819
"STANDBY": "Standby",
1920
"CONNECT_TO": "Connect to ",

main/assets/ja-JP/language.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"DETECTING_MODULE": "モジュールを検出中...",
1515
"REGISTERING_NETWORK": "ネットワーク接続待機中...",
1616
"CHECKING_NEW_VERSION": "新しいバージョンを確認中...",
17+
"CHECK_NEW_VERSION_FAILED": "更新確認に失敗しました。%d 秒後に再試行します: %s",
1718

1819
"STANDBY": "待機中",
1920
"CONNECT_TO": "接続先 ",

main/assets/zh-CN/language.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"DETECTING_MODULE":"检测模组...",
1515
"REGISTERING_NETWORK":"等待网络...",
1616
"CHECKING_NEW_VERSION":"检查新版本...",
17+
"CHECK_NEW_VERSION_FAILED":"检查新版本失败,将在 %d 秒后重试:%s",
1718

1819
"STANDBY":"待命",
1920
"CONNECT_TO":"连接 ",

main/assets/zh-TW/language.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"DETECTING_MODULE": "檢測模組...",
1515
"REGISTERING_NETWORK": "等待網絡...",
1616
"CHECKING_NEW_VERSION": "檢查新版本...",
17+
"CHECK_NEW_VERSION_FAILED": "檢查新版本失敗,將在 %d 秒後重試:%s",
1718

1819
"STANDBY": "待命",
1920
"CONNECT_TO": "連接 ",

main/boards/common/wifi_board.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,13 @@ Http* WifiBoard::CreateHttp() {
114114
}
115115

116116
WebSocket* WifiBoard::CreateWebSocket() {
117-
#ifdef CONFIG_CONNECTION_TYPE_WEBSOCKET
118-
std::string url = CONFIG_WEBSOCKET_URL;
117+
Settings settings("websocket", false);
118+
std::string url = settings.GetString("url");
119119
if (url.find("wss://") == 0) {
120120
return new WebSocket(new TlsTransport());
121121
} else {
122122
return new WebSocket(new TcpTransport());
123123
}
124-
#endif
125124
return nullptr;
126125
}
127126

0 commit comments

Comments
 (0)