beta client tinance2
This commit is contained in:
parent
a2aa741236
commit
71340b05f1
3 changed files with 68 additions and 1 deletions
1
README
1
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:
|
||||
|
|
|
@ -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
|
||||
|
|
66
src/main.cpp
66
src/main.cpp
|
@ -383,6 +383,67 @@ void setup() {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINANCE2_BACKEND
|
||||
#include <HTTPClient.h>
|
||||
// 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
|
||||
|
|
Loading…
Reference in a new issue