Skip to content

Commit

Permalink
check for Wifi availability before trying to connect to mqtt server
Browse files Browse the repository at this point in the history
  • Loading branch information
ernstkl committed Aug 9, 2021
1 parent 3c77d4f commit d861ead
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,21 @@ void show_data(void) //Daten anzeigen
void send_data_mqtt(void) // Daten auf mqtt-topic senden: tele/co2/<ab-cd>
//TODO Ausführung des Codes schaltbar machen über Ampel-Webseite (2 Buttons)
{
if (settings.mqtt_server[0] == 0) {
if (settings.mqtt_server[0] == 0)
{
// not configured
return;
}

if ((WiFi.status() == WL_CONNECT_FAILED) ||
(WiFi.status() == WL_CONNECTION_LOST) ||
(WiFi.status() == WL_DISCONNECTED))
{
Serial.println("mqtt: no Wifi");
return;
}


if (!mqtt_client.connected())
{
// connect or reconnect - timeout is 20s, even with mqtt_client.setSocketTimeout(2)
Expand Down

0 comments on commit d861ead

Please sign in to comment.