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

improve some debug messages

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