 SystemState systemState;
 
 void setup() {
-  unsigned long startTime = millis();
+  unsigned long systemStart = millis();
   
   Serial.begin(115200);
-
-  Serial.println("Beginning");
+  Serial.println("Beginning"); // More importantly: move cursor to the beginning of the line
 
   SystemState systemStateFromRtc;
   bool systemStateValid = systemStateFromRtc.readFromRtc(0, sizeof(SystemState));

        ESP.deepSleep(3e6);
      }
    }
    
    Serial.print("T ");
    Serial.print(t);
    Serial.print(" H ");
    Serial.println(h);
    
    //*
    if (systemState.roundsWithoutTransmission < 5) {


  //*/

  unsigned long systemOnMillis = (millis() - connectionTime) + (connectStart - systemStart);

  sleepNowForServer(serverSecondsUntilOff, systemOnMillis);
}

void loop() {

}

void sleepNowForServer(short serverSecondsUntilOff, unsigned long systemOnMillis)
{
  unsigned long sleepMillis = 1;
  unsigned long correctionMillis = systemOnMillis;
  if (serverSecondsUntilOff >= 0)
    correctionMillis += (8 - serverSecondsUntilOff) * 1000; // shift wake up time to the start of the window
    
  if (systemState.serverSleepSeconds*1000 > correctionMillis) {
    sleepMillis = systemState.serverSleepSeconds * 1000 - correctionMillis;
  }
  Serial.print("Sleeping ");
  Serial.println(sleepMillis);
  
  ESP.deepSleep(sleepMillis * 1000, RF_NO_CAL);
}

