Skip to content
Snippets Groups Projects
Commit 85a55298 authored by Johannes Mey's avatar Johannes Mey
Browse files

improve some debug messages

parent b133f7bf
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ bool MqttConnection::ensureConnection() {
constexpr int N_ATTEMPT = 30;
if (!client.is_connected()) {
ROS_WARN_STREAM_NAMED("MqttConnection", client.get_client_id() << ": Lost connection. Reconnecting.");
ROS_WARN_STREAM("[MqttConnection] Client '" << client.get_client_id() << "' lost connection. Reconnecting.");
for (int i = 0; i < N_ATTEMPT && !client.is_connected(); ++i) {
try {
auto rsp = client.reconnect();
......@@ -20,12 +20,11 @@ bool MqttConnection::ensureConnection() {
}
return true;
} catch (const mqtt::exception &exception) {
ROS_ERROR_STREAM_NAMED("MqttConnection",
"Problem during reconnection. Retrying in 1s. " << exception.to_string());
ROS_ERROR_STREAM("[MqttConnection] Problem during reconnection. Retrying in 1s. Exception: " << exception.to_string());
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
ROS_ERROR_STREAM_NAMED("MqttConnection", client.get_client_id() << ": Reconnection failed!");
ROS_ERROR_STREAM("[MqttConnection] Reconnection failed for client '" << client.get_client_id() << "'.");
return false;
}
return true;
......@@ -33,6 +32,8 @@ bool MqttConnection::ensureConnection() {
bool MqttConnection::send(const std::string &channel, const std::string &message) {
ROS_INFO_STREAM(
"[MqttConnection] Sending message to channel " << channel << " with a length of " << message.size() << ".");
if (ensureConnection()) {
try {
int length = message.size();
......@@ -41,13 +42,14 @@ bool MqttConnection::send(const std::string &channel, const std::string &message
auto pub_msg = mqtt::make_message(channel, data, length);
pub_msg->set_qos(QOS);
getClient().publish(pub_msg);
ROS_INFO_STREAM("[MqttConnection] Message has been sent successfully.");
}
catch (const mqtt::exception &exc) {
ROS_ERROR_STREAM("MqttUtil: Unable to publish message. " << exc.what());
ROS_ERROR_STREAM("[MqttConnection] Unable to publish message. " << exc.what());
return false;
}
} else {
ROS_ERROR_STREAM("MqttUtil: Not connected! Unable to listen to messages.");
ROS_ERROR_STREAM("[MqttConnection] Not connected! Unable to listen to messages.");
return false;
}
return true;
......
......@@ -82,7 +82,7 @@ bool NngConnection::send(const std::string &channel, const std::string &message)
ROS_ERROR_STREAM("[NngConnection] nng_send returned: " << nng_strerror(rv));
return false;
} else {
ROS_INFO_STREAM("[NngConnection] Scene has been sent successfully.");
ROS_INFO_STREAM("[NngConnection] Message has been sent successfully.");
return true;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment