Skip to content

Commit

Permalink
Making better integration with esp32-discord-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
smford committed Jul 8, 2020
1 parent 71ecb81 commit dbd3a0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions eeh-esp32-rfid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// file upload progress based upon https://codepen.io/PerfectIsShit/pen/zogMXP
// wifi scanning based upon https://github.com/me-no-dev/ESPAsyncWebServer#scanning-for-available-wifi-networks

#define FIRMWARE_VERSION "v1.8.2-ota"
#define FIRMWARE_VERSION "v1.8.3-ota"

// configuration structure
struct Config {
Expand Down Expand Up @@ -381,11 +381,14 @@ void dowebcall(const char *foundrfid) {
enableLed(String(iteration) + " Access Granted: Enable LED: UserID:" + currentRFIDUserIDStr + " RFID:" + String(currentRFIDcard));
enableRelay(String(iteration) + " Access Granted: Enable LED: UserID:" + currentRFIDUserIDStr + " RFID:" + String(currentRFIDcard));
if (config.discordproxyenable) {
/*
HTTPClient http;
String deviceurl = config.discordproxyserver + "/" + config.device + "?user=" + currentRFIDFirstNameStr + "%20" + currentRFIDSurnameStr + "&api=" + config.discordproxyapitoken + "&action=on";
http.begin(deviceurl);
int httpResponseCode = http.GET();
Serial.println("getting " + deviceurl);
*/
discordProxySend("user", "login");
}
} else {
// in maintenance mode, show message, deny access
Expand Down Expand Up @@ -468,13 +471,16 @@ void loop() {
currentRFIDSurnameStr = "Mode";
currentRFIDUserIDStr = "0";
currentRFIDaccess = true;
inOverrideMode = true;
lcdPrint(config.device, "ACCESS GRANTED", "RFID: " + String(currentRFIDcard), currentRFIDFirstNameStr + " " + currentRFIDSurnameStr);
if (config.discordproxyenable) {
/*
HTTPClient http;
String deviceurl = config.discordproxyserver + "/" + config.device + "?api=" + config.discordproxyapitoken + "&action=override";
http.begin(deviceurl);
int httpResponseCode = http.GET();
Serial.println("getting " + deviceurl);
Serial.println("getting " + deviceurl);*/
discordProxySend("override", "on");
}
} else {
// normal user, do webcall
Expand All @@ -493,6 +499,7 @@ void loop() {
}
}

// card has been removed
mfrc522[0].PICC_HaltA();
mfrc522[0].PCD_StopCrypto1();
if (!config.inmaintenance) {
Expand All @@ -503,11 +510,13 @@ void loop() {
lcdPrint(config.device, "MAINTENANCE MODE", "ALL ACCESS DENIED");
}
if (config.discordproxyenable) {
HTTPClient http;
String deviceurl = config.discordproxyserver + "/" + config.device + "?api=" + config.discordproxyapitoken + "&action=off";
http.begin(deviceurl);
int httpResponseCode = http.GET();
Serial.println("getting " + deviceurl);
// discordProxySend(action, state)
if (inOverrideMode) {
discordProxySend("override", "off");
} else {
discordProxySend("user", "logout");
Serial.println("some generic message");
}
}
disableLed(String(iteration) + " " + "Access Revoked: Card Removed: Disable LED: " + String(newcard));
disableRelay(String(iteration) + " " + "Access Revoked: Card Removed: Disable Relay: " + String(newcard));
Expand Down
4 changes: 2 additions & 2 deletions webserver_functions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void configureWebServer() {
saveConfiguration(filename, config);
gotoToggleMaintenance = true;
if (config.discordproxyenable) {
discordProxySend("maintenance", "enable");
discordProxySend("maintenance", "on");
}
} else {
logmessage += " Already in maintenance mode";
Expand All @@ -339,7 +339,7 @@ void configureWebServer() {
saveConfiguration(filename, config);
gotoToggleMaintenance = true;
if (config.discordproxyenable) {
discordProxySend("maintenance", "disable");
discordProxySend("maintenance", "off");
}
} else {
logmessage += " Already not in maintenance mode";
Expand Down

0 comments on commit dbd3a0c

Please sign in to comment.