             );
   }
 
-  if ( !MDNS.begin( "" ) )
-  {
-    ESP_LOGE( TAG, "Error setting up mDNS." );
-  }
-  else if ( !setupMDNS( hostName ) )
-  {
+  if ( !MDNS.begin( "" ) && !setupMDNS( hostName ) )
     ESP_LOGE( TAG, "Error setting up %s as hostname. ", hostName );
-  }
 
   /* start network dependent tasks */
   xTaskCreatePinnedToCore(

        OLED.display();
      }

      if ( xTftTaskHandle )
      {
        tft.setCursor( 70, 100 );
        tft.print( remainingSCTime );
      }
      else
      {
        digitalWrite( TFT_BACKLIGHT_PIN, !gpio_get_level( gpio_num_t( TFT_BACKLIGHT_PIN ) ) );
      }
      vTaskDelay( 500 / portTICK_PERIOD_MS );
    }

    if ( !WiFi.smartConfigDone() )
    {
      ESP.restart();
    }

    if ( !xTftTaskHandle )
    {
      digitalWrite( TFT_BACKLIGHT_PIN, LOW );
    }
  }

  waitForWifi();

  /* We have succesfully connected */
  ESP_LOGI( TAG, "WiFi connected to %s", WiFi.SSID().c_str() );
  tcpip_adapter_ip_info_t ip_info;
  ESP_ERROR_CHECK( tcpip_adapter_get_ip_info( TCPIP_ADAPTER_IF_STA, &ip_info ) );
  ESP_LOGI( TAG, "Local IP: %s", ip4addr_ntoa( &ip_info.ip ) );
  uint8_t mac[6];
  esp_efuse_mac_get_default(mac);
  ESP_LOGI( TAG, "MAC: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  if ( xTftTaskHandle )
  {
    tft.invertDisplay( false );
    tft.printf( "WiFi connected.\nLocal IP: %s\n", ip4addr_ntoa( &ip_info.ip ) );
  }
  if ( xOledTaskHandle )
  {
    OLED.normalDisplay();
  }
  strncpy( hostName, preferences.getString( "hostname", "" ).c_str(), sizeof( hostName ) );

  if ( hostName[0] ==  0 )
  {
    snprintf( hostName, sizeof( hostName ), "%s%c%c%c%c%c%c", DEFAULT_HOSTNAME_PREFIX,
              WiFi.macAddress()[9], WiFi.macAddress()[10],
              WiFi.macAddress()[12], WiFi.macAddress()[13],

void wifiTask( void * pvParameters ) {
  /* trying last accesspoint */
  WiFi.mode( WIFI_STA );
  WiFi.begin();
