   else {
     //sendCode();
   }
-  lastButtonState = buttonState;
    
   WiServer.server_task();
 }

void sendCodeOnce() {
  unsigned long time = millis();

  if ( (time - sentLockMillis) > 10000) { //10 seconds
    Serial.println("Sending once");
    sendCode();
    sentLockMillis = time;
  }
}

void loop()
{
  int buttonState = digitalRead(BUTTON_PIN);
  int lightValue = analogRead(ANALOG_LIGHT_PIN);
  
  if (lightValue < 200) {
    sendCodeOnce();
  }

  if (buttonState == HIGH) {
    if (irrecv.decode(&results)) {
      storeCode(&results);
      irrecv.resume(); // resume receiver

   {
      WiServer.print("<html><head><title>Led switch</title></head>");
    
      WiServer.print("<body><center>Temperature: ");
      WiServer.print(prevTemp);
      WiServer.print("C</br>Humidity: ");
      WiServer.print(prevHumidity);
      WiServer.print("%</br>");
      for (stateCounter = 0; stateCounter < 1; stateCounter++) //for each led
      {
        numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 - 3 rather than 0 - 2
