Commit 9cfa14d3 authored by Michael Ott's avatar Michael Ott
Browse files

Reduce verbosity of MQTT connection attempts

parent 13b9b5cb
......@@ -85,14 +85,20 @@ MQTTPusher::~MQTTPusher() {
void MQTTPusher::push() {
int mosqErr;
uint64_t idleTime = 0;
int connectTimer = 0;
//connect to broker (if necessary)
while (_keepRunning && !_connected) {
if (mosquitto_connect(_mosq, _brokerHost.c_str(), _brokerPort, 1000) != MOSQ_ERR_SUCCESS) {
LOGM(error) << "Could not connect to MQTT broker " << _brokerHost << ":" << _brokerPort;
sleep(1);
if (connectTimer == 0) {
LOGM(warning) << "Could not connect to MQTT broker " << _brokerHost << ":" << _brokerPort;
}
connectTimer++;
sleep(5);
} else {
_connected = true;
LOGM(info) << "Connection established!";
LOGM(info) << "Connection to MQTT broker " << _brokerHost << ":" << _brokerPort << " established!";
connectTimer = 0;
}
}
......@@ -113,13 +119,17 @@ void MQTTPusher::push() {
//there was a (unintended) disconnect in the meantime --> reconnect
if (!_connected) {
LOGM(error) << "Lost connection. Reconnecting...";
if (connectTimer == 0) {
LOGM(info) << "Lost connection. Reconnecting...";
}
if (mosquitto_reconnect(_mosq) != MOSQ_ERR_SUCCESS) {
LOGM(error) << "Could not reconnect to MQTT broker " << _brokerHost << ":" << _brokerPort << std::endl;
// LOGM(debug) << "Could not reconnect to MQTT broker " << _brokerHost << ":" << _brokerPort << std::endl;
connectTimer++;
sleep(5);
} else {
_connected = true;
LOGM(info) << "Connection established!";
LOGM(info) << "Connection to MQTT broker " << _brokerHost << ":" << _brokerPort << " established!";
connectTimer = 0;
}
}
......@@ -209,7 +219,7 @@ int MQTTPusher::sendReadings(SensorBase &s, reading_t *reads, std::size_t &total
if (rc == MOSQ_ERR_NOMEM) {
LOGM(info) << "Can\'t queue additional messages";
} else {
LOGM(error) << "Could not send message: " << mosquitto_strerror(rc) << " Trying again later";
LOGM(debug) << "Could not send message: " << mosquitto_strerror(rc) << " Trying again later";
_connected = false;
}
s.pushReadingQueue(reads, count);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment