Commit 1c1e5c9c authored by Eric Duminil's avatar Eric Duminil
Browse files

More mqtt info

parent b87383a2
Pipeline #5769 passed with stage
in 2 minutes and 18 seconds
......@@ -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);
......
Markdown is supported
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