Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
We have upgraded GitLab to 15.1. Due to major code changes GitLab was down for some time.
Open sidebar
dcdb
dcdb
Commits
9cfa14d3
Commit
9cfa14d3
authored
May 05, 2020
by
Michael Ott
Browse files
Reduce verbosity of MQTT connection attempts
parent
13b9b5cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
dcdbpusher/MQTTPusher.cpp
View file @
9cfa14d3
...
...
@@ -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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment