logging
This commit is contained in:
parent
204e874eb4
commit
5c904055fa
8 changed files with 80 additions and 11 deletions
|
@ -6,6 +6,10 @@
|
|||
#include "webhooks.h"
|
||||
#include "secrets.h"
|
||||
#endif
|
||||
#ifdef TINANCE2_BACKEND
|
||||
#include "tinance2.h"
|
||||
#include "secrets.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BOARD1
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#ifdef TINANCE2_BACKEND
|
||||
extern const char* tinance2_url_validatecard;
|
||||
extern const char* tinance2_url_readerinfo;
|
||||
extern const char* tinance2_url_log;
|
||||
extern const char* tinance2_url_acls;
|
||||
extern const char* tinance2_reader_identifer;
|
||||
extern const char* tinance2_reader_key;
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
#include <Preferences.h>
|
||||
|
||||
#ifdef WIFI
|
||||
#ifdef TINANCE2_BACKEND
|
||||
#include "tinance2.h"
|
||||
#include "secrets.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class Settings {
|
||||
private:
|
||||
bool disableDoor;
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
#include "local_acl.h"
|
||||
#endif
|
||||
|
||||
void tinance2SyncTaskFunction(void *parameter);
|
||||
void tinance2authrequest(String fullCardID, String cardID);
|
||||
extern void tinance2SyncTaskFunction(void *parameter);
|
||||
extern void tinance2authrequest(String fullCardID, String cardID);
|
||||
extern void tinance2logrequest(String message);
|
||||
extern HTTPClient tinance2_http;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,13 +9,17 @@ void unlockDoor(bool silent) {
|
|||
if (!silent) {
|
||||
granted_beep();
|
||||
}
|
||||
|
||||
#ifdef WIFI
|
||||
#ifdef WEBHOOKS
|
||||
#ifdef WEBHOOK_UNLOCK
|
||||
ExecuteHTTPRequest(String(webhook_unlock_url));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINANCE2_BACKEND
|
||||
tinance2logrequest("Door Unlocked");
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef RELAY1
|
||||
#ifdef RELAY1_REVERSED
|
||||
|
@ -40,12 +44,18 @@ void lockDoor(bool silent) {
|
|||
short_beep();
|
||||
}
|
||||
|
||||
#ifdef WIFI
|
||||
#ifdef WEBHOOKS
|
||||
#ifdef WEBHOOK_LOCK
|
||||
ExecuteHTTPRequest(String(webhook_lock_url));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINANCE2_BACKEND
|
||||
tinance2logrequest("Door Locked");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifdef RELAY1
|
||||
#ifdef RELAY1_REVERSED
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
const char* tinance2_url_validatecard = "https://tinance2.domain.nl/accesscontrol/api/check-card-id";
|
||||
const char* tinance2_url_readerinfo = "https://tinance2.domain.nl/accesscontrol/api/readerinfo";
|
||||
const char* tinance2_url_acls = "https://tinance2.domain.nl/accesscontrol/api/acls";
|
||||
const char* tinance2_url_log = "https://tinance2.domain.nl/accesscontrol/api/readerlog";
|
||||
const char* tinance2_reader_identifer = "RDR-DOOR-01";
|
||||
const char* tinance2_reader_key = "REPLACE-WITH-UUID";
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,13 @@ void Settings::saveToEEPROM() {
|
|||
void Settings::setDisableDoor(bool value) {
|
||||
if (disableDoor != value) {
|
||||
disableDoor = value;
|
||||
|
||||
#ifdef WIFI
|
||||
#ifdef TINANCE2_BACKEND
|
||||
tinance2logrequest("Settings::setDisableDoor: " + value);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Settings::setDisableDoor: ");
|
||||
Serial.println(disableDoor);
|
||||
|
@ -38,6 +45,13 @@ void Settings::setDoorMode(const String mode) {
|
|||
if (mode == "LATCH" || mode == "TOGGLE") {
|
||||
if (doorMode != mode) {
|
||||
doorMode = mode;
|
||||
|
||||
#ifdef WIFI
|
||||
#ifdef TINANCE2_BACKEND
|
||||
tinance2logrequest("Settings::setDoorMode: " + mode);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.print("Settings::setDoorMode: ");
|
||||
Serial.println(doorMode);
|
||||
|
|
|
@ -5,8 +5,6 @@ HTTPClient tinance2_http;
|
|||
|
||||
class Tinance2HttpClient {
|
||||
public:
|
||||
Tinance2HttpClient() {}
|
||||
|
||||
std::pair<String, int> sendHttpRequest(String url, String method, String payload) {
|
||||
|
||||
if (!tinance2_http.begin(url)) {
|
||||
|
@ -73,6 +71,39 @@ HTTPClient tinance2_http;
|
|||
}
|
||||
};
|
||||
|
||||
void tinance2logrequest(String message) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("WIFI Status: " + String(WiFi.status()));
|
||||
#endif
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Sending Request to Tinance2 for log: " + message);
|
||||
#endif
|
||||
|
||||
// Create the JSON payload
|
||||
String payload = "{\"message\":\"" + String(message) + "\"}";
|
||||
// Send the HTTP request and get the response
|
||||
Tinance2HttpClient httpClient;
|
||||
std::pair<String, int> responsePair = httpClient.sendHttpRequest(tinance2_url_log, "POST", payload);
|
||||
String response = responsePair.first;
|
||||
int httpResponseCode = responsePair.second;
|
||||
|
||||
// Process the response
|
||||
if (httpResponseCode != 201) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Got unexpected http response from log endpoint.");
|
||||
Serial.println("HTTP Response: " + response);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Tinance2 Wifi Disconnected using offline processes for log management.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Function to send the authentication request to Tinance2
|
||||
void tinance2authrequest(String fullCardID, String cardID) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
|
|
Loading…
Reference in a new issue