diff --git a/src/LogMessages_DE.cpp b/src/LogMessages_DE.cpp index 31d75c9a..358e377c 100644 --- a/src/LogMessages_DE.cpp +++ b/src/LogMessages_DE.cpp @@ -192,7 +192,7 @@ const char ftpServerStarted[] = "FTP-Server gestartet"; const char freeHeapAfterSetup[] = "Freier Heap-Speicher nach Setup-Routine"; const char tryStaticIpConfig[] = "Statische IP-Konfiguration wird durchgeführt..."; const char staticIPConfigFailed[] = "Statische IP-Konfiguration fehlgeschlagen"; -const char wakeUpRfidNoCard[] = "ESP32 wurde vom Kartenleser aus dem Deepsleep aufgeweckt. Allerdings wurde keine Karte gefunden. Gehe zurück in den Deepsleep..."; +const char wakeUpRfidNoCard[] = "ESP32 wurde vom Kartenleser aus dem Deepsleep aufgeweckt. Allerdings wurde keine bekannte Karte gefunden. Gehe zurück in den Deepsleep..."; const char lowPowerCardSuccess[] = "Kartenerkennung via 'low power' erfolgreich durchgeführt"; const char rememberLastVolume[] = "Lautstärke vor dem letzten Shutdown wird wiederhergestellt. Dies überschreibt die Einstellung der initialen Lautstärke aus der GUI."; const char unableToStartFtpServer[] = "Der FTP-Server konnte nicht gestartet werden. Entweder weil er ist bereits gestartet oder kein WLAN verfügbar ist."; diff --git a/src/LogMessages_EN.cpp b/src/LogMessages_EN.cpp index 048cafdc..07a9fcfb 100644 --- a/src/LogMessages_EN.cpp +++ b/src/LogMessages_EN.cpp @@ -193,7 +193,7 @@ const char freeHeapAfterSetup[] = "Free heap after setup"; const char ftpServerStarted[] = "FTP-Server started"; const char tryStaticIpConfig[] = "Performing IP-configuration..."; const char staticIPConfigFailed[] = "IP-configuration failed"; -const char wakeUpRfidNoCard[] = "Wakeup caused by low power card-detection. RF-field changed but no card on reader was found. So I'll return back to sleep now..."; +const char wakeUpRfidNoCard[] = "Wakeup caused by low power card-detection. RF-field changed but no known card on reader was found. So I'll return back to sleep now..."; const char lowPowerCardSuccess[] = "Switch to low power card-detection: success"; const char rememberLastVolume[] = "Restored volume used before last shutdown. This overwrites the initial volume configured via webgui."; const char unableToStartFtpServer[] = "FTP-server cannot be started. This is because FTP-service is already active or because WiFi is unavailable."; diff --git a/src/LogMessages_FR.cpp b/src/LogMessages_FR.cpp index 5417cd41..5ae1a8f2 100644 --- a/src/LogMessages_FR.cpp +++ b/src/LogMessages_FR.cpp @@ -191,7 +191,7 @@ const char freeHeapAfterSetup[] = "Espace libre après la configuration"; const char ftpServerStarted[] = "Serveur FTP démarré"; const char tryStaticIpConfig[] = "Configuration IP statique en cours..."; const char staticIPConfigFailed[] = "Échec de la configuration IP statique"; -const char wakeUpRfidNoCard[] = "Réveil causé par la détection de carte à faible puissance. Le champ RF a changé mais aucune carte sur le lecteur n'a été trouvée. Je vais donc retourner en mode veille maintenant..."; +const char wakeUpRfidNoCard[] = "Réveil causé par la détection de carte à faible puissance. Le champ RF a changé mais aucune carte connu sur le lecteur n'a été trouvée. Je vais donc retourner en mode veille maintenant..."; const char lowPowerCardSuccess[] = "Passage à la détection de carte à faible puissance : réussite"; const char rememberLastVolume[] = "Volume utilisé avant le dernier arrêt restauré. Cela écrase le volume initial configuré via l'interface Web."; const char unableToStartFtpServer[] = "Le serveur FTP ne peut pas être démarré. Cela est dû au fait que le service FTP est déjà actif ou parce que le WiFi est indisponible."; diff --git a/src/RfidPn5180.cpp b/src/RfidPn5180.cpp index 59d5c71e..8fde991c 100644 --- a/src/RfidPn5180.cpp +++ b/src/RfidPn5180.cpp @@ -377,7 +377,7 @@ void Rfid_EnableLpcd(void) { #endif } -// wake up from LPCD, check card is present. This works only for ISO-14443 compatible cards +// wake up from LPCD, check card is present in NVS void Rfid_WakeupCheck(void) { #ifdef PN5180_ENABLE_LPCD // disable pin hold from deep sleep @@ -387,36 +387,63 @@ void Rfid_WakeupCheck(void) { #if (RFID_IRQ >= 0 && RFID_IRQ <= MAX_GPIO) pinMode(RFID_IRQ, INPUT); #endif + + // read card serial to check NVS for entries + uint8_t uid[10]; + bool isCardPresent; + bool cardInNVS = false; + static PN5180ISO14443 nfc14443(RFID_CS, RFID_BUSY, RFID_RST); nfc14443.begin(); nfc14443.reset(); // enable RF field nfc14443.setupRF(); - // 1.check for ISO-14443 card present - bool isCardPresent = nfc14443.isCardPresent(); + + // 1. check for ISO-14443 card present + isCardPresent = nfc14443.readCardSerial(uid) >= 4; + + // 2. check for ISO-15693 card present if (!isCardPresent) { - // 2.check for ISO-15693 card present static PN5180ISO15693 nfc15693(RFID_CS, RFID_BUSY, RFID_RST); nfc15693.begin(); nfc15693.setupRF(); - uint8_t uid[10]; + // do not handle encrypted cards in any way here isCardPresent = nfc15693.getInventory(uid) == ISO15693_EC_OK; } - if (!isCardPresent) { - // no card found, go back to deep sleep + + // check for card id in NVS + if (isCardPresent) { + // uint8_t[10] -> char[cardIdStringSize] + char tagId[cardIdStringSize]; + size_t pos = 0; + for (size_t i = 0; i < 10; i++) { + pos += snprintf(tagId + pos, cardIdStringSize - pos, "%03d", uid[i]); + } + tagId[cardIdStringSize - 1] = '\0'; + + // Try to lookup tagId in NVS + if (gPrefsRfid.isKey(tagId)) { + cardInNVS = gPrefsRfid.getString(tagId, "-1").compareTo("-1"); + } + } + + if (!cardInNVS) { + // no card found or card not in NVS, go back to deep sleep nfc14443.reset(); uint16_t wakeupCounterInMs = 0x3FF; // needs to be in the range of 0x0 - 0xA82. max wake-up time is 2960 ms. if (nfc14443.switchToLPCD(wakeupCounterInMs)) { Log_Println(lowPowerCardSuccess, LOGLEVEL_INFO); - // configure wakeup pin for deep-sleep wake-up, use ext1 - #if (RFID_IRQ >= 0 && RFID_IRQ <= MAX_GPIO) - // configure wakeup pin for deep-sleep wake-up, use ext1. For a real GPIO only, not PE - esp_sleep_enable_ext1_wakeup((1ULL << (RFID_IRQ)), ESP_EXT1_WAKEUP_ALL_LOW); - #endif - #if (defined(PORT_EXPANDER_ENABLE) && (RFID_IRQ > 99)) - // reset IRQ state on port-expander - Port_Exit(); - #endif + + // configure wakeup pin for deep-sleep wake-up, use ext1 + #if (RFID_IRQ >= 0 && RFID_IRQ <= MAX_GPIO) + // configure wakeup pin for deep-sleep wake-up, use ext1. For a real GPIO only, not PE + esp_sleep_enable_ext1_wakeup((1ULL << (RFID_IRQ)), ESP_EXT1_WAKEUP_ALL_LOW); + #endif + #if (defined(PORT_EXPANDER_ENABLE) && (RFID_IRQ > 99)) + // reset IRQ state on port-expander + Port_Exit(); + #endif + // freeze pin states in deep sleep gpio_hold_en(gpio_num_t(RFID_CS)); // CS/NSS gpio_hold_en(gpio_num_t(RFID_RST)); // RST diff --git a/src/System.cpp b/src/System.cpp index 66393e47..bf21463f 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -38,10 +38,19 @@ volatile uint8_t System_OperationMode; void System_SleepHandler(void); void System_DeepSleepManager(void); +// Init only NVS required for LPCD +void System_Init_LPCD(void) { + #ifdef PN5180_ENABLE_LPCD + gPrefsRfid.begin(prefsRfidNamespace); + #endif +} + void System_Init(void) { srand(esp_random()); - gPrefsRfid.begin(prefsRfidNamespace); + #ifndef PN5180_ENABLE_LPCD + gPrefsRfid.begin(prefsRfidNamespace); + #endif gPrefsSettings.begin(prefsSettingsNamespace); // Get maximum inactivity-time from NVS diff --git a/src/System.h b/src/System.h index 25acb102..be9f1952 100644 --- a/src/System.h +++ b/src/System.h @@ -5,6 +5,7 @@ extern Preferences gPrefsRfid; extern Preferences gPrefsSettings; extern TaskHandle_t AudioTaskHandle; +void System_Init_LPCD(void); void System_Init(void); void System_Cyclic(void); void System_UpdateActivityTimer(void); diff --git a/src/main.cpp b/src/main.cpp index 8f6e170c..6d5152dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,7 +122,9 @@ void setup() { // Make sure all wakeups can be enabled *before* initializing RFID, which can enter sleep immediately Button_Init(); // To preseed internal button-storage with values + #ifdef PN5180_ENABLE_LPCD + System_Init_LPCD(); Rfid_Init(); #endif