     WiFi.mode( WIFI_AP_STA );
     WiFi.beginSmartConfig();
 
-    const unsigned long rebootDelayMs = 60 * 5 * 1000;
+    const time_t DELAY_SECONDS = 60 * 5;
+    const time_t END_TIME = time( NULL ) + DELAY_SECONDS;
 
-    const unsigned long smartConfigStartMs = millis();
+    ESP_LOGI( TAG, "Waiting %i seconds for SmartConfig.", DELAY_SECONDS );
 
-    ESP_LOGI( TAG, "Waiting %i seconds for SmartConfig.", rebootDelayMs / 1000 );
-
-    while ( !WiFi.smartConfigDone() && ( (unsigned long)millis() - smartConfigStartMs ) < rebootDelayMs ) {
+    while ( !WiFi.smartConfigDone() && time( NULL ) < END_TIME ) {
       char remainingSCTime[12];
       if ( xOledTaskHandle ) {
         OLED.clear();
         OLED.setFont( ArialMT_Plain_10 );
         OLED.drawString( 64, 10, "Waiting for SmartConfig." );
-        snprintf( remainingSCTime, sizeof( remainingSCTime), "%i seconds", ( (unsigned long)( smartConfigStartMs + rebootDelayMs ) - millis() ) / 1000 );
+        snprintf( remainingSCTime, sizeof( remainingSCTime), "%3.i seconds", END_TIME - time( NULL ) );
         OLED.drawString( 64, 30, remainingSCTime );
         OLED.invertDisplay();
         OLED.display();


  WiFi.waitForConnectResult();

  if ( WiFi.status() != WL_CONNECTED ) {
    if ( xTftTaskHandle ) {
      tft.println( "\nNo WiFi connection.\nWaiting for SmartConfig." );
      tft.invertDisplay( true );

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

  if ( wifi_network != "" ) WiFi.begin( wifi_network, wifi_password );
  else WiFi.begin();

  if ( xTftTaskHandle ) {
    tft.setTextColor( TFT_TEXT_COLOR , TFT_BACK_COLOR );
