diff --git a/README b/README index 2c9ee60..734bcf9 100644 --- a/README +++ b/README @@ -17,6 +17,7 @@ This project is a card reader system for Techinc that uses a WIEGAND based reade -DLOCAL_ACL_API : Enable API for managing ACL's (needs -DWEB_SERVER and -DLOCAL_ACL) -DLATCH_DOOR : Release RELAY1 for a a certain amount of time in this case its 1 second -DTOGGLE_DOOR : Instead of Relasing relay for 1 second keep it in the opposite state to what it was at the time the card was scanned. +-DTINANCE2_BACKEND : Enables use of Tinance2 System # Important Notes: diff --git a/include/secrets.h.dist b/include/secrets.h.dist index 6c08b4e..9c854e4 100644 --- a/include/secrets.h.dist +++ b/include/secrets.h.dist @@ -12,7 +12,7 @@ #endif #ifdef TINANCE2_BACKEND - const char* tinance2_url = "https://tinance2.local/accesscontrol/api/"; + const char* tinance2_url = "https://tinance2.local/accesscontrol/api/check-card-id"; const char* tinance2_reader_identifer = "mx-test-reader-1"; const char* tinance2_reader_key = "access-key"; #endif diff --git a/src/main.cpp b/src/main.cpp index fe4c8a8..84ff4a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -383,6 +383,67 @@ void setup() { #endif #endif + #ifdef TINANCE2_BACKEND + #include + // Function to send the authentication request to the endpoint + void tinance2authrequest(String fullCardID) { + #ifdef SERIAL_DEBUG + Serial.println("Sending Request to Tinance2 for card: " + fullCardID); + #endif + + HTTPClient http; + + // Set the endpoint URL + String url = tinance2_url; + http.begin(url); + + // Set the headers + http.addHeader("Content-Type", "application/json"); + http.addHeader("X-Identifier", tinance2_reader_identifer); + http.addHeader("X-Access-Key", tinance2_reader_key); + + // Create the JSON payload + String payload = "{\"full_card_id\":\"" + String(fullCardID) + "\"}"; + #ifdef SERIAL_DEBUG + Serial.println("Payload: " + payload); + #endif + // Send the POST request + int httpResponseCode = http.POST(payload); + #ifdef SERIAL_DEBUG + Serial.println("response code: " + httpResponseCode); + Serial.println("response body: " + http.getString()); + #endif + // Check the response code + if (httpResponseCode == 200) { + // Unlock the door + unlockDoor(false); + delay(RELAY_DELAY); + lockDoor(); + } else { + #ifdef SERIAL_DEBUG + Serial.println("Tinance2 Door Access Denied"); + #endif + // Perform actions for denied access + } + + #ifdef SERIAL_DEBUG + // Print the response code + Serial.print("HTTP Response Code: "); + Serial.println(httpResponseCode); + + // Print the response body + String responseBody = http.getString(); + Serial.print("HTTP Response Body: "); + Serial.println(responseBody); + Serial.println("End of Tinance2 Request"); + #endif + // Cleanup + http.end(); + } + #endif + + + void loop() { #ifdef LOCAL_ACL @@ -451,6 +512,11 @@ void loop() { bitCount = 0; // Reset the bit count + + #ifdef TINANCE2_BACKEND + tinance2authrequest(String(fullCardID)); + #endif + #ifdef LOCAL_ACL if (acl.validateAccess(String(cardID))) { #ifdef SERIAL_DEBUG