 #define MFRC522_RSTO    (32)
 #define MFRC522_3V3     /* 3v3 */
 
+#define SOLENOID_GPIO     (4)
+#define SOLENOID_OFF      (LOW)
+#define SOLENOID_ENGAGED  (HIGH)
+
 #define BUZZER_GPIO       (2)
-#define SOLENOID_GPIO     (4)
-#define LED_AART          (16)
-
-#define DOOR_OPEN_DELAY   (10*1000)
-#define REPORTING_PERIOD  (300*1000)
+#define BUZZER_OFF        (HIGH)
+#define BUZZER_ENGAGED    (LOW)
+
+#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.
+//
+#ifdef LOCALMQTT
+#define REPORTING_PERIOD        (300*1000)  //   5 minutes -- how often to report our states; in milli seconds.
+#define PREFIX ""
+#else
+#define REPORTING_PERIOD        (10*1000)   //  10 seconds -- -- how often to report our states; in milli seconds.
+#define PREFIX "test"
+#define MQTT_KEEPALIVE          (10)        // seconds -- keep alive check; default is 2 minutes - but it is 
+// easier to keep this short during debugging - i.e. when testing breaking connections. Note that this may not
+// work if the Arduino CPP gets the order wrong.
+#endif
 
 typedef enum doorstates { CLOSED, CHECKINGCARD, OPEN } doorstate_t;
+const char doorstates_names[OPEN + 1][15] = { "closed", "checking-card", "open" };
+
 doorstate_t doorstate;
 unsigned long long last_doorstatechange = 0;
 

        type = "SPIFFS";
        break;
      default: {
          const char buff[] = "Unknown type of reprogramming attempt. Rejecting.";
          Serial.println(buff);
          client.publish(log_topic, buff);
          client.loop();

#include <ArduinoOTA.h>
#include <ESP32Ticker.h>
#include <PubSubClient.h>

// Requires modifed MFRC522 (see pull rq) or the -master branch as of late DEC 2017.
// https://github.com/miguelbalboa/rfid.git
#include <MFRC522.h>

SPIClass spirfid = SPIClass(VSPI);
const SPISettings spiSettings = SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0);
