forked from xiaozhi/xiaozhi-esp32
更新Wi-Fi组件版本,从OTA接口读取Websocket服务器
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "board.h"
|
||||
#include "system_info.h"
|
||||
#include "application.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cJSON.h>
|
||||
@@ -67,10 +68,18 @@ bool WebsocketProtocol::OpenAudioChannel() {
|
||||
delete websocket_;
|
||||
}
|
||||
|
||||
Settings settings("websocket", false);
|
||||
std::string url = settings.GetString("url");
|
||||
std::string token = settings.GetString("token");
|
||||
|
||||
busy_sending_audio_ = false;
|
||||
error_occurred_ = false;
|
||||
std::string url = CONFIG_WEBSOCKET_URL;
|
||||
std::string token = "Bearer " + std::string(CONFIG_WEBSOCKET_ACCESS_TOKEN);
|
||||
|
||||
// If token not starts with "Bearer " or "bearer ", add it
|
||||
if (token.empty() || (token.find("Bearer ") != 0 && token.find("bearer ") != 0)) {
|
||||
token = "Bearer " + token;
|
||||
}
|
||||
|
||||
websocket_ = Board::GetInstance().CreateWebSocket();
|
||||
websocket_->SetHeader("Authorization", token.c_str());
|
||||
websocket_->SetHeader("Protocol-Version", "1");
|
||||
@@ -109,6 +118,7 @@ bool WebsocketProtocol::OpenAudioChannel() {
|
||||
}
|
||||
});
|
||||
|
||||
ESP_LOGI(TAG, "Connecting to websocket server: %s with token: %s", url.c_str(), token.c_str());
|
||||
if (!websocket_->Connect(url.c_str())) {
|
||||
ESP_LOGE(TAG, "Failed to connect to websocket server");
|
||||
SetError(Lang::Strings::SERVER_NOT_FOUND);
|
||||
|
||||
Reference in New Issue
Block a user