Test CardLost

This commit is contained in:
TheJoKlLa 2022-09-23 23:01:42 +02:00
parent 72c052fc59
commit e4049af19e
5 changed files with 35 additions and 13 deletions

View File

@ -1,11 +1,12 @@
## Protocol:
READERID is 5 Digits
1. Hello: Topic="fabreader", Payload="READERID"
1. Start: Topic="fabreader/READERID/startOTA", Payload=NULL
1. Start: Topic="fabreader/READERID/startOTA", Payload=UID of Card
1. Request: Topic="fabreader/READERID/requestOTA", Payload=256 Bytes APDU Command
1. Response: Topic="fabreader/READERID/responseOTA", Payload=256 Bytes APDU Response
1. Stop: Topic="fabreader/READERID/stopOTA", Payload=NULL
1. Cancel: Topic="fabreader/READERID/cancelOTA", Payload=NULL
1. Restart: Topic="fabreader/READERID/restartOTA", Payload=NULL
## Procedure:
After Start Reader sends "Hello".
@ -17,4 +18,7 @@ After new Card is on Reader:
Repeat Request and Response until:
"Stop" <- from Server
"Cancel" -> to Server
"Cancel" -> to Server
If FabReader works as deadmen switch the OTA connection is not stopped and the next check can be started with restartOTA.
If DESFire Card uses Random UID the UID changes every new connection, so the connections stays active until the server restartsOTA and performs new OTA.

View File

@ -43,13 +43,18 @@ void NFC::deselectCard()
bool NFC::isCardLost()
{
Serial.println(rfid->PICC_ReadCardSerial());
Serial.println(rfid->PICC_ReadCardSerial());
Serial.println(rfid->PICC_ReadCardSerial());
return rfid->PICC_ReadCardSerial() && rfid->uid.uidByte != uid.uidByte;
MFRC522::StatusCode status = rfid->PICC_Select(&(uid));
Serial.printf("PICC_Select: 0x%02x\n", status);
return status != MFRC522::STATUS_OK;
}
MFRC522::StatusCode NFC::Transceive(byte* command, byte command_len, byte* response, byte response_len)
{
return rfid->PCD_TransceiveData(command, command_len, response, &response_len, NULL, 0, true);
}
MFRC522::Uid NFC::getUID()
{
return uid;
}

View File

@ -18,7 +18,8 @@ class NFC
bool hasNewCard();
void selectCard();
void deselectCard();
bool isCardLost();
bool isCardLost();
MFRC522::Uid getUID();
MFRC522::StatusCode Transceive(byte* command, byte command_len, byte* response, byte response_len);
};

View File

@ -21,7 +21,8 @@ void OTAProxy::startOTA()
char topic[] = "fabreader/00000/startOTA";
sprintf(topic, "fabreader/%05d/startOTA", id);
mqtt->publish(topic, 0);
MFRC522::Uid uid = nfc->getUID();
mqtt->publish(topic, uid.uidByte, int(uid.size));
}
void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
@ -35,6 +36,9 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
char topic_stopOTA[] = "fabreader/00000/stopOTA";
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", id);
char topic_restartOTA[] = "fabreader/00000/restartOTA";
sprintf(topic_restartOTA, "fabreader/%05d/restartOTA", id);
if(strcmp(topic, topic_requestOTA))
{
byte response[APDU_BUFFER_SIZE] = {0};
@ -42,12 +46,20 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
mqtt->publish(topic_responseOTA, response, APDU_BUFFER_SIZE);
}
if(strcmp(topic, topic_stopOTA))
else if(strcmp(topic, topic_stopOTA))
{
nfc->deselectCard();
activeOTA = false;
}
else if(strcmp(topic, topic_restartOTA))
{
nfc->deselectCard();
if(nfc->hasNewCard())
{
nfc->selectCard();
startOTA();
}
}
}
void OTAProxy::cancelOTA()

View File

@ -83,9 +83,9 @@ void callback(char* topic, byte* payload, unsigned int length)
void setup()
{
config.ID = 1;
strcpy(config.WLAN_SSID, "");
strcpy(config.WLAN_Password, "");
strcpy(config.MQTT_Broker, "");
strcpy(config.WLAN_SSID, "SSID");
strcpy(config.WLAN_Password, "dodahV3eePeiducaicae");
strcpy(config.MQTT_Broker, "10.7.255.233");
Serial.begin(115200);
Serial.print("\n\n\n");