 String commandUnlock = "GET /log_visit_state/1 HTTP/1.0\r\n\r\n";
 
 int count;
-int switchState;
+int lastState;
+int courtesyDelay = 6;
+long lastStateTimestamp;
 
-void setup()
-{
+
+// sometimes you want to run with leds only
+boolean espActive = false;
+
+void setup() {
+
   pinMode(ESP_RESET, INPUT);
   //pinMode(ESP_RESET, OUTPUT);
   //digitalWrite(ESP_RESET, HIGH);

  pinMode(GREEN, OUTPUT);
  pinMode(RED, OUTPUT);
  pinMode(YELLOW, OUTPUT);
  pinMode(SWITCH, INPUT_PULLUP);
  
  // setup serial with esp-01
  digitalWrite(LED, HIGH);

  blink(BLINK_COUNT, BLINK_DURATION, 1, 1, 1);
}



void loop() {
  if (lastState == LOW) {
    count++;
  } else if (count > 0) { 
      count -= courtesyDelay;
      digitalWrite(RED, LOW);
      digitalWrite(YELLOW, HIGH);
      digitalWrite(GREEN, LOW);
  } else {
      count = 0;
      digitalWrite(RED, LOW);
      digitalWrite(YELLOW, LOW);
      digitalWrite(GREEN, HIGH);
  }
  
  delay(500);
}

