Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
1c1e5c9c
Commit
1c1e5c9c
authored
Feb 09, 2022
by
Eric Duminil
Browse files
More mqtt info
parent
b87383a2
Pipeline
#5769
passed with stage
in 2 minutes and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/mqtt.cpp
View file @
1c1e5c9c
...
...
@@ -59,7 +59,7 @@ namespace mqtt {
}
void
publish
(
const
char
*
timestamp
,
int16_t
co2
,
float
temperature
,
float
humidity
)
{
if
(
WiFi
.
status
()
==
WL_CONNECTED
&&
mqttClient
.
connected
())
{
if
(
wifi
::
connected
()
&&
mqttClient
.
connected
())
{
led_effects
::
onBoardLEDOn
();
Serial
.
print
(
F
(
"MQTT - Publishing message ... "
));
...
...
@@ -105,7 +105,7 @@ namespace mqtt {
// It failed less than wait_after_fail ago. Not even trying.
return
;
}
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
//NOTE: Sadly, WiFi.status is sometimes WL_CONNECTED even though it's really not
if
(
!
wifi
::
connected
()
)
{
//NOTE: Sadly, WiFi.status is sometimes WL_CONNECTED even though it's really not
// No WIFI
return
;
}
...
...
@@ -141,10 +141,23 @@ namespace mqtt {
Serial
.
println
(
F
(
" Connected."
));
last_failed_at
=
0
;
}
else
{
char
const
*
mqtt_statuses
[]
=
{
// As defined in PubSubClient
"Connection timeout"
,
// -4
"Connection lost"
,
"Connection failed"
,
"Disconnected"
,
"Connected!"
,
// 0
"Bad protocol"
,
"Bad client ID"
,
"Unavailable"
,
"Bad credentials"
,
"Unauthorized"
};
// 5
last_failed_at
=
seconds
();
Serial
.
print
(
F
(
" Failed! Error code="
));
Serial
.
print
(
F
(
" Failed! "
));
Serial
.
print
(
mqtt_statuses
[
mqttClient
.
state
()
+
4
]);
Serial
.
print
(
" (Code="
);
Serial
.
print
(
mqttClient
.
state
());
Serial
.
print
(
F
(
". Will try again in "
));
Serial
.
print
(
F
(
"
)
. Will try again in "
));
Serial
.
print
(
config
::
wait_after_fail
);
Serial
.
println
(
"s."
);
}
...
...
@@ -178,9 +191,9 @@ namespace mqtt {
led_effects
::
showKITTWheel
(
color
::
green
,
1
);
}
// It can be hard to find the local IP of a sensor if it isn't connected to Serial port, and if mDNS is disabled.
// If the sensor can be reach by MQTT, it can answer with info about local_ip and ssid.
// The sensor will send the info to "CO2sensors/ESP123456/info".
// It can be hard to find the local IP of a sensor if it isn't connected to Serial port, and if mDNS is disabled.
// If the sensor can be reach by MQTT, it can answer with info about local_ip and ssid.
// The sensor will send the info to "CO2sensors/ESP123456/info".
void
sendInfoAboutLocalNetwork
()
{
char
info_topic
[
60
];
// Should be enough for "CO2sensors/ESP123456/info"
snprintf
(
info_topic
,
sizeof
(
info_topic
),
"%s/info"
,
publish_topic
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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