 
   if (caching)
     setCache(uid, false);
+
   uid.size = 0;
 
   char msg[256];


MFRC522::Uid uid;

void callback(char* topic, byte * payload, unsigned int length) {
  char buff[256];


    if (client.connected())
      client.disconnect();
  }

  {
    static doorstate_t lastdoorstate = CLOSED;
    switch (doorstate) {
      case CHECKINGCARD:
        if (millis() - last_doorstatechange > 1500 && caching && checkCache(uid)) {
          char msg[255];
          snprintf(msg, sizeof(msg), "[%s] Allowing door to open based on cached information.", pname);
          Serial.println(msg);
          client.publish(log_topic, msg);
          openDoor();
        }
        break;
      case OPENING:
        if (isOpen()) {
          char msg[256];
          snprintf(msg, sizeof(msg), "[%s] Door is open.", pname);
          Serial.println(msg);
          client.publish(log_topic, msg);
          doorstate = OPEN;
          cnt_opens++;
        };
        break;
      case OPEN:
        if (millis() - last_doorstatechange > DOOR_OPEN_DELAY) {
          Serial.println("Closing door.");
          closeDoor();
        };
      case CLOSING:
        if (isClosed()) {
          char msg[256];
          snprintf(msg, sizeof(msg), "[%s] Door is closed.", pname);
          Serial.println(msg);
          client.publish(log_topic, msg);
          doorstate = CLOSED;
          cnt_closes++;
        };
        break;
      case CLOSED:
        if (!isClosed()) {
          /// some alerting ? clearly a bug ?
        }
      default:
        break;
    };

    if (lastdoorstate != doorstate) {
      lastdoorstate = doorstate;
      last_doorstatechange = millis();
    }
  }
  // catch any logic errors or strange cases where the door is open while we think
  // we are not doing anything.
  //
