first commit
This commit is contained in:
parent
eaed6e792e
commit
22094f9dfa
@ -40,7 +40,7 @@ void MQTTClient::connect()
|
||||
auto tok = client_->connect(connOpts); // 异步连接
|
||||
if (!tok->wait_for(std::chrono::seconds(2))) // 设置超时
|
||||
{
|
||||
LOG_WARN("[MQTTClient] Connect timed out to broker: " + config_.server_ip);
|
||||
LOG_WARN("[MQTT] Connect timed out to broker: " + config_.server_ip);
|
||||
startReconnect();
|
||||
return;
|
||||
}
|
||||
@ -50,12 +50,10 @@ void MQTTClient::connect()
|
||||
|
||||
if (on_connect_)
|
||||
on_connect_();
|
||||
|
||||
LOG_INFO("[MQTTClient] Connected to broker: " + config_.server_ip);
|
||||
}
|
||||
catch (const mqtt::exception &e)
|
||||
{
|
||||
LOG_ERROR("[MQTTClient] Connect failed: " + std::string(e.what()));
|
||||
LOG_ERROR("[MQTT] Connect failed: " + std::string(e.what()));
|
||||
startReconnect();
|
||||
}
|
||||
}
|
||||
@ -72,12 +70,10 @@ void MQTTClient::disconnect()
|
||||
connected_ = false;
|
||||
if (on_disconnect_)
|
||||
on_disconnect_();
|
||||
|
||||
LOG_INFO("[MQTTClient] Disconnected from broker: " + config_.server_ip);
|
||||
}
|
||||
catch (const mqtt::exception &e)
|
||||
{
|
||||
LOG_ERROR("[MQTTClient] Disconnect failed: " + std::string(e.what()));
|
||||
LOG_ERROR("[MQTT] Disconnect failed: " + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +89,7 @@ void MQTTClient::publish(const std::string &topic, const std::string &payload, i
|
||||
}
|
||||
catch (const mqtt::exception &e)
|
||||
{
|
||||
LOG_ERROR("[MQTTClient] Publish failed: " + std::string(e.what()));
|
||||
LOG_ERROR("[MQTT] Publish failed: " + std::string(e.what()));
|
||||
if (!connected_)
|
||||
startReconnect();
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ extern std::atomic<bool> g_running;
|
||||
// MQTT 回调定义
|
||||
static void on_mqtt_connected()
|
||||
{
|
||||
LOG_INFO("[MQTT] Connected to broker.");
|
||||
LOG_INFO("[MQTT] Connected to broker: " + g_app_config.mqtt.server_ip);
|
||||
|
||||
const auto &topics = g_app_config.mqtt.topics;
|
||||
mqtt_client->subscribe(topics.video_down);
|
||||
@ -19,7 +19,7 @@ static void on_mqtt_connected()
|
||||
|
||||
static void on_mqtt_disconnected()
|
||||
{
|
||||
LOG_WARN("[MQTT] Disconnected from broker.");
|
||||
LOG_WARN("[MQTT] Disconnected from broker: " + g_app_config.mqtt.server_ip);
|
||||
}
|
||||
|
||||
static void on_mqtt_message_received(const std::string &topic, const std::string &message)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user