 
   // log change in connection status
   if(canConnect != canConnect_prev) {
-    time_to_string(now(), time_as_string);
+    time_now = now();
+    time_to_string(time_now, time_as_string);
     logfile.print(time_as_string);
     logfile.print(" - ");
-    if(canConnect)
-      logfile.println("connected.");
-    else
-      logfile.println("NOT CONNECTED!");
+    if(!canConnect) logfile.println("not");
+    logfile.println("connected");
     logfile.flush();
+
+    if(!time_lastchange) {
+      logfile.print("Seconds elapsed since last status change: ");
+      logfile.println(time_now - time_lastchange);
+    }
+    time_lastchange = time_now;
 
     canConnect_prev = canConnect;
   }

byte packetBuffer[NTP_PACKET_SIZE];
WiFiUDP Udp;
char time_as_string[] = "12/20/1969 00:00:00";

// LED pins
const int redLed = 3;

}

void resetRouter(void) {
  digitalWrite(routerPin, LOW);
  delay(resetRouterTime);
  digitalWrite(routerPin, HIGH);
  delay(resetRouterTime);
}