 #define SOLENOID_GPIO     (4)
 #define SOLENOID_OFF      (LOW)
 #define SOLENOID_ENGAGED  (HIGH)
-#define AARTLED_GPIO     (16)
+#define AARTLED_GPIO      (16)
 
 #define DOOR_OPEN_DELAY         (10*1000)   //  10 seconds -- how long to hold the relay engaged; in milli seconds.
 #define CACHE_FALLBACK_TIMEOUT  (500)       // 0.5 second  -- how long to wait for a reply before checking the cache.
+#define MAX_RESPONSE_TIMEOUT    (3500)      // 3.5 seconds -- max wait for reply from the server.
 
 // Report regulary - but swithc to a higher frequency if we are in test mode. Also prefix our MQTT topic with 'test'
 // to avoid confusing production.

}

void openDoor() {
  doorstate = OPEN;
  client.publish(log_topic, "Engaging solenoid");

  // Engage solenoid.
  digitalWrite(SOLENOID_GPIO, SOLENOID_ENGAGED);

  }

  static doorstate_t lastdoorstate = CLOSED;
  if (lastdoorstate != doorstate) {
    char msg[255];
    snprintf(msg, sizeof(msg), "[%s] Change from state %s(%d) to %s(%d)",
             pname,
             doorstates_names[lastdoorstate], lastdoorstate, doorstates_names[doorstate], doorstate);
    Serial.println(msg);
#ifndef LOCALMQTT
    client.publish(log_topic, msg);
#endif
    lastdoorstate = doorstate;
    last_doorstatechange = millis();
  }

  switch (doorstate) {
    case CHECKINGCARD:
      if (millis() - last_doorstatechange > CACHE_FALLBACK_TIMEOUT && caching && checkCache(uid)) {
