forked from xiaozhi/xiaozhi-esp32
Support MQTT endpoint port
This commit is contained in:
@@ -490,7 +490,7 @@ void Application::Start() {
|
||||
}
|
||||
}
|
||||
});
|
||||
protocol_->Start();
|
||||
bool protocol_started = protocol_->Start();
|
||||
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
audio_processor_.Initialize(codec, realtime_chat_enabled_);
|
||||
@@ -556,12 +556,15 @@ void Application::Start() {
|
||||
// Wait for the new version check to finish
|
||||
xEventGroupWaitBits(event_group_, CHECK_NEW_VERSION_DONE_EVENT, pdTRUE, pdFALSE, portMAX_DELAY);
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
std::string message = std::string(Lang::Strings::VERSION) + ota_.GetCurrentVersion();
|
||||
display->ShowNotification(message.c_str());
|
||||
display->SetChatMessage("system", "");
|
||||
// Play the success sound to indicate the device is ready
|
||||
ResetDecoder();
|
||||
PlaySound(Lang::Sounds::P3_SUCCESS);
|
||||
|
||||
if (protocol_started) {
|
||||
std::string message = std::string(Lang::Strings::VERSION) + ota_.GetCurrentVersion();
|
||||
display->ShowNotification(message.c_str());
|
||||
display->SetChatMessage("system", "");
|
||||
// Play the success sound to indicate the device is ready
|
||||
ResetDecoder();
|
||||
PlaySound(Lang::Sounds::P3_SUCCESS);
|
||||
}
|
||||
|
||||
// Enter the main event loop
|
||||
MainEventLoop();
|
||||
|
||||
@@ -27,8 +27,8 @@ MqttProtocol::~MqttProtocol() {
|
||||
vEventGroupDelete(event_group_handle_);
|
||||
}
|
||||
|
||||
void MqttProtocol::Start() {
|
||||
StartMqttClient(false);
|
||||
bool MqttProtocol::Start() {
|
||||
return StartMqttClient(false);
|
||||
}
|
||||
|
||||
bool MqttProtocol::StartMqttClient(bool report_error) {
|
||||
@@ -90,7 +90,16 @@ bool MqttProtocol::StartMqttClient(bool report_error) {
|
||||
});
|
||||
|
||||
ESP_LOGI(TAG, "Connecting to endpoint %s", endpoint_.c_str());
|
||||
if (!mqtt_->Connect(endpoint_, 8883, client_id_, username_, password_)) {
|
||||
std::string broker_address;
|
||||
int broker_port = 8883;
|
||||
size_t pos = endpoint_.find(':');
|
||||
if (pos != std::string::npos) {
|
||||
broker_address = endpoint_.substr(0, pos);
|
||||
broker_port = std::stoi(endpoint_.substr(pos + 1));
|
||||
} else {
|
||||
broker_address = endpoint_;
|
||||
}
|
||||
if (!mqtt_->Connect(broker_address, broker_port, client_id_, username_, password_)) {
|
||||
ESP_LOGE(TAG, "Failed to connect to endpoint");
|
||||
SetError(Lang::Strings::SERVER_NOT_CONNECTED);
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
MqttProtocol();
|
||||
~MqttProtocol();
|
||||
|
||||
void Start() override;
|
||||
bool Start() override;
|
||||
void SendAudio(const std::vector<uint8_t>& data) override;
|
||||
bool OpenAudioChannel() override;
|
||||
void CloseAudioChannel() override;
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
void OnAudioChannelClosed(std::function<void()> callback);
|
||||
void OnNetworkError(std::function<void(const std::string& message)> callback);
|
||||
|
||||
virtual void Start() = 0;
|
||||
virtual bool Start() = 0;
|
||||
virtual bool OpenAudioChannel() = 0;
|
||||
virtual void CloseAudioChannel() = 0;
|
||||
virtual bool IsAudioChannelOpened() const = 0;
|
||||
|
||||
@@ -22,7 +22,9 @@ WebsocketProtocol::~WebsocketProtocol() {
|
||||
vEventGroupDelete(event_group_handle_);
|
||||
}
|
||||
|
||||
void WebsocketProtocol::Start() {
|
||||
bool WebsocketProtocol::Start() {
|
||||
// Only connect to server when audio channel is needed
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebsocketProtocol::SendAudio(const std::vector<uint8_t>& data) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
WebsocketProtocol();
|
||||
~WebsocketProtocol();
|
||||
|
||||
void Start() override;
|
||||
bool Start() override;
|
||||
void SendAudio(const std::vector<uint8_t>& data) override;
|
||||
bool OpenAudioChannel() override;
|
||||
void CloseAudioChannel() override;
|
||||
|
||||
Reference in New Issue
Block a user