Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access logs and visualization #632

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/log.esp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ void ICACHE_FLASH_ATTR writeEvent(String type, String src, String desc, String d
#endif
}

void ICACHE_FLASH_ATTR writeLatest(String uid, String username, int acctype)
void ICACHE_FLASH_ATTR writeLatest(String uid, String username, int acctype, int access = ACCESS_GRANTED)
{
DynamicJsonDocument root(512);
root["uid"] = uid;
root["username"] = username;
root["acctype"] = acctype;
root["access"] = access;
root["timestamp"] = epoch;
File latestlog = SPIFFS.open("/latestlog.json", "a");
serializeJson(root, latestlog);
Expand Down
2 changes: 1 addition & 1 deletion src/magicnumbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#define ACCESS_GRANTED 1
#define ACCESS_ADMIN 99
#define ACCCESS_DENIED 0
#define ACCESS_DENIED 0

// Reader defines

Expand Down
11 changes: 8 additions & 3 deletions src/rfid.esp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void rfidProcess()
if (validUntilL < nowL || validSinceL > nowL)
{
processingState = expired;
} else if (config.openingHours[weekdayFromMonday(weekday())][hourTz] != '1')
} else if (config.openingHours[weekdayFromMonday(weekday(epoch))][hourTz] != '1')
{
processingState = notValid;
} else
Expand Down Expand Up @@ -485,6 +485,7 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" has access relay");
#endif
writeLatest(uid, username, accountType, ACCESS_GRANTED);
if (config.numRelays == 1) {
mqttPublishAccess(epoch, "true", "Always", username, uid);
} else {
Expand All @@ -495,6 +496,7 @@ void rfidOutsideMessaging()
if (processingState == validAdmin)
{
ws.textAll("{\"command\":\"giveAccess\"}");
writeLatest(uid, username, accountType, ACCESS_GRANTED);
if (config.numRelays == 1) {
mqttPublishAccess(epoch, "true", "Admin", username, uid);
} else {
Expand All @@ -507,12 +509,14 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" expired");
#endif
writeLatest(uid, username, accountType, ACCESS_DENIED);
mqttPublishAccess(epoch, "true", "Expired", username, uid);
ledAccessDeniedOn();
beeperAccessDenied();
}
if (processingState == wrongPincode)
{
writeLatest(uid, username, accountType, ACCESS_DENIED);
mqttPublishAccess(epoch, "true", "Wrong pin code", username, uid);
ledAccessDeniedOn();
beeperAccessDenied();
Expand All @@ -522,6 +526,7 @@ void rfidOutsideMessaging()
#ifdef DEBUG
Serial.println(" does not have access");
#endif
writeLatest(uid, username, accountType, ACCESS_DENIED);
mqttPublishAccess(epoch, "true", "Disabled", username, uid);
ledAccessDeniedOn();
beeperAccessDenied();
Expand All @@ -530,7 +535,7 @@ void rfidOutsideMessaging()
{
String data = String(uid) += " " + String(type);
writeEvent("WARN", "rfid", "Unknown rfid tag is scanned", data);
writeLatest(uid, "Unknown", 98);
writeLatest(uid, "Unknown", 98, ACCESS_DENIED);
DynamicJsonDocument root(512);
root["command"] = "piccscan";
root["uid"] = uid;
Expand All @@ -548,7 +553,7 @@ void rfidOutsideMessaging()
beeperAccessDenied();
} else if (uid != "" && processingState != waitingProcessing)
{
writeLatest(uid, username, accountType);
// message to the web UI to tell who has opened the door
DynamicJsonDocument root(512);
root["command"] = "piccscan";
root["uid"] = uid;
Expand Down
Loading
Loading