forked from xiaozhi/xiaozhi-esp32
fix network error
This commit is contained in:
@@ -13,8 +13,6 @@
|
||||
|
||||
MqttProtocol::MqttProtocol() {
|
||||
event_group_handle_ = xEventGroupCreate();
|
||||
|
||||
StartMqttClient();
|
||||
}
|
||||
|
||||
MqttProtocol::~MqttProtocol() {
|
||||
@@ -28,6 +26,10 @@ MqttProtocol::~MqttProtocol() {
|
||||
vEventGroupDelete(event_group_handle_);
|
||||
}
|
||||
|
||||
void MqttProtocol::Start() {
|
||||
StartMqttClient();
|
||||
}
|
||||
|
||||
bool MqttProtocol::StartMqttClient() {
|
||||
if (mqtt_ != nullptr) {
|
||||
ESP_LOGW(TAG, "Mqtt client already started");
|
||||
@@ -98,7 +100,12 @@ void MqttProtocol::SendText(const std::string& text) {
|
||||
if (publish_topic_.empty()) {
|
||||
return;
|
||||
}
|
||||
mqtt_->Publish(publish_topic_, text);
|
||||
if (!mqtt_->Publish(publish_topic_, text)) {
|
||||
ESP_LOGE(TAG, "Failed to publish message");
|
||||
if (on_network_error_ != nullptr) {
|
||||
on_network_error_("发送失败,请检查网络");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MqttProtocol::SendAudio(const std::vector<uint8_t>& data) {
|
||||
|
||||
Reference in New Issue
Block a user