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

Add pincode #477

Merged
merged 4 commits into from
Feb 4, 2022
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
2 changes: 2 additions & 0 deletions src/config.esp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ bool ICACHE_FLASH_ATTR loadConfiguration()
numRelays = 1;

#ifdef OFFICIALBOARD
pinCodeRequested = hardware["pincoderequested"];
setupWiegandReader(5, 4);
#endif
#ifndef OFFICIALBOARD
Expand All @@ -109,6 +110,7 @@ bool ICACHE_FLASH_ATTR loadConfiguration()
{
int wgd0pin = hardware["wgd0pin"];
int wgd1pin = hardware["wgd1pin"];
pinCodeRequested = hardware["pincoderequested"];
setupWiegandReader(wgd0pin, wgd1pin); // also some other settings like weather to use keypad or not, LED pin, BUZZER pin, Wiegand 26/34 version
}
else if (readertype == READER_MFRC522 || readertype == READER_MFRC522_RDM6300)
Expand Down
2 changes: 1 addition & 1 deletion src/log.esp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void ICACHE_FLASH_ATTR writeEvent(String type, String src, String desc, String d
eventlog.close();
}
#ifdef DEBUG
Serial.println("[ " + type + " ] " + src + " | " + desc);
Serial.println("[ " + type + " ] " + src + " | " + desc + " | " + data);
#endif
}

Expand Down
12 changes: 1 addition & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ unsigned long previousLoopMillis = 0;
unsigned long currentMillis = 0;
unsigned long cooldown = 0;
unsigned long keyTimer = 0;
String currentInput = "";
bool pinCodeRequested;
unsigned long deltaTime = 0;
unsigned long uptime = 0;
bool shouldReboot = false;
Expand Down Expand Up @@ -480,14 +480,4 @@ void ICACHE_RAM_ATTR loop()
}
}
}
// Keep an eye on timeout waiting for keypress
// Clear code and timer when timeout is reached
if (keyTimer > 0 && millis() - keyTimer >= KEYBOARD_TIMEOUT_MILIS)
{
#ifdef DEBUG
Serial.println("[ INFO ] Keycode timeout");
#endif
keyTimer = 0;
currentInput = "";
}
}
6 changes: 3 additions & 3 deletions src/mqtt.esp
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
}
StaticJsonBuffer<255> jsonBuffer;
#ifdef DEBUG
Serial.print("[ INFO ] JSON msg :");
Serial.print("[ INFO ] JSON msg: ");
Serial.println(mqttBuffer);
#endif

JsonObject &root = jsonBuffer.parseObject(mqttBuffer);
if (!root.success())
{
#ifdef DEBUG
Serial.print("[ INFO ] Failed parse MQTT message :");
Serial.print("[ INFO ] Failed parse MQTT message: ");
Serial.println(mqttBuffer);
#endif
return;
Expand Down Expand Up @@ -486,7 +486,7 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
{

#ifdef DEBUG
Serial.print("[ INFO ] Add Users :");
Serial.print("[ INFO ] Add Users: ");
const char *name = root["user"];
Serial.println(name);
#endif
Expand Down
62 changes: 51 additions & 11 deletions src/rfid.esp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
String uid = "";
String type = "";
String currentInput = "";
String pinCode = "";

void wiegandRead()
void ICACHE_FLASH_ATTR wiegandRead()
{
// if we get 26 or 34 bit burst then we have a scanned PICC
if (wg.getWiegandType() == WIEGANDTYPE_PICC26 || wg.getWiegandType() == WIEGANDTYPE_PICC34)
Expand Down Expand Up @@ -30,13 +32,22 @@ void wiegandRead()
// When # is pressed stop keytimer to capture code
if (wg.getWiegandType() == WIEGANDTYPE_KEYPRESS && keyTimer > 0 && String(wg.getCode(), HEX) == "d")
{
if(pinCodeRequested) {
pinCode = currentInput;
} else {
uid = currentInput;
type = "PIN";
}
#ifdef DEBUG
Serial.println("Stop capture keycode . . .");
Serial.print(F("[ INFO ] PICC's UID: "));
if(pinCodeRequested) {
Serial.print(F("[ INFO ] PICC's pin code: "));
}
else {
Serial.print(F("[ INFO ] PICC's UID: "));
}
Serial.println(currentInput);
#endif
uid = currentInput;
type = "PIN";
currentInput = "";
keyTimer = 0;
cooldown = millis() + COOLDOWN_MILIS;
Expand Down Expand Up @@ -98,6 +109,28 @@ void ICACHE_FLASH_ATTR rfidloop()
delay(50);
return;
}
// Keep an eye on timeout waiting for keypress
// Clear code and timer when timeout is reached
if (keyTimer > 0 && millis() - keyTimer >= KEYBOARD_TIMEOUT_MILIS)
{
#ifdef DEBUG
Serial.println("[ INFO ] Keycode timeout");
#endif
keyTimer = 0;
currentInput = "";
return;
}
if (keyTimer > 0) // we are still waiting for keycode to build up
{
#ifdef DEBUG
Serial.println("[ INFO ] still waiting for keypress!!");
#endif
return;
}
// We need to wait for the pin code after a card is read
if (pinCodeRequested && pinCode == "") {
return;
}
}
else if (readertype == READER_PN532)
{
Expand Down Expand Up @@ -235,13 +268,6 @@ void ICACHE_FLASH_ATTR rfidloop()
return;
}
#endif
if (keyTimer > 0) // we are still waiting for keycode to build up
{
#ifdef DEBUG
Serial.println("[ INFO ] still waiting for keypress!!");
#endif
return;
}
String filename = "/P/";
filename += uid;
File f = SPIFFS.open(filename, "r");
Expand All @@ -266,6 +292,18 @@ void ICACHE_FLASH_ATTR rfidloop()
else
AccType = json["acctype" + String(currentRelay + 1)];

// if the pin code is wrong we deny access
if(pinCodeRequested && pinCode != json["pincode"]) {
AccType = ACCCESS_DENIED;
#ifdef DEBUG
Serial.println("Wrong pin code");
#endif
if (mqttEnabled)
{
mqtt_publish_access(now(), "true", "Wrong pin code", username, uid);
}
}

#ifdef DEBUG
Serial.println(" = known PICC");
Serial.print("[ INFO ] User Name: ");
Expand Down Expand Up @@ -387,6 +425,8 @@ void ICACHE_FLASH_ATTR rfidloop()
digitalWrite(accessdeniedpin, HIGH);
}
}
pinCode = "";
uid = "";
}

#ifndef OFFICIALBOARD
Expand Down
16 changes: 8 additions & 8 deletions src/webh/esprfid.htm.gz.h

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/webh/esprfid.js.gz.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/webh/glyphicons-halflings-regular.woff.gz.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/webh/index.html.gz.h

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions src/webh/required.css.gz.h

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions src/webh/required.js.gz.h

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/websrc/esprfid.htm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ <h6 class="text-muted">Please refer the <a href="https://github.com/esprfid/esp-
</select>
</span>
</div>
<div class="row form-group">
<label class="col-xs-3">Pin code requested<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Ask pin code after having swiped an RFID card."></i></label>
<span class="col-xs-9 col-md-5">
<select class="form-control input-sm" id="pincoderequested">
<option value="false">False</option>
<option value="true">True</option>
</select>
</span>
</div>
</div>
<div class="" id="mfrc522Form" style="display:none">
<div class="row form-group">
Expand Down Expand Up @@ -898,6 +907,12 @@ <h4 class="modal-title" id="editor-title">Add User</h4>
<input type="text" class="form-control" id="uid" name="uid" placeholder="UID" required>
</div>
</div>
<div class="form-group">
<label for="pincode" class="col-sm-3 control-label">Pin code</label>
<div class="col-sm-9" style="font-family:monospace">
<input type="text" class="form-control" id="pincode" name="pincode" placeholder="Pin code">
</div>
</div>
<div class="form-group required">
<label for="username" class="col-sm-3 control-label">User Name or Label</label>
<div class="col-sm-9">
Expand Down
15 changes: 14 additions & 1 deletion src/websrc/js/esprfid.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function listhardware() {
document.getElementById("doorbellpin").value = config.hardware.doorbellpin;
document.getElementById("openlockpin").value = config.hardware.openlockpin;
document.getElementById("accessdeniedpin").value = config.hardware.accessdeniedpin;
document.getElementById("pincoderequested").value = config.hardware.pincoderequested;
if (isOfficialBoard) {
document.getElementById("readertype").value = 1;
document.getElementById("wg0pin").value = 5;
Expand Down Expand Up @@ -222,6 +223,7 @@ function savehardware() {
config.hardware.readertype = parseInt(document.getElementById("readertype").value);
config.hardware.wgd0pin = parseInt(document.getElementById("wg0pin").value);
config.hardware.wgd1pin = parseInt(document.getElementById("wg1pin").value);
config.hardware.pincoderequested = document.getElementById("pincoderequested").value == "true";
config.hardware.sspin = parseInt(document.getElementById("gpioss").value);
config.hardware.rfidgain = parseInt(document.getElementById("gain").value);
config.hardware.rtype = parseInt(document.getElementById("typerly").value);
Expand Down Expand Up @@ -799,15 +801,17 @@ function restoreSet() {

function restore1by1(i, len, data) {
var part = 100 / len;
var uid, user, acc, valid;
var uid, pincode, user, acc, valid;
document.getElementById("dynamic").style.width = part * (i + 1) + "%";
var datatosend = {};
uid = data[i].uid;
pincode = data[i].pincode;
user = data[i].username;
acc = data[i].acctype;
valid = data[i].validuntil;
datatosend.command = "userfile";
datatosend.uid = uid;
datatosend.pincode = pincode;
datatosend.user = user;
datatosend.acctype = acc;
datatosend.validuntil = valid;
Expand Down Expand Up @@ -1181,6 +1185,12 @@ function initUserTable() {
"type": "text",
"style": "font-family:monospace"
},
{
"name": "pincode",
"title": "Pin code",
"type": "text",
"visible": false
},
{
"name": "username",
"title": "User Name or Label"
Expand Down Expand Up @@ -1287,6 +1297,7 @@ function initUserTable() {
if (xval === "Disabled") return 0;
}
$editor.find("#uid").val(values.uid);
$editor.find("#pincode").val(values.pincode);
$editor.find("#username").val(values.username);
$editor.find("#acctype").val(giveAccType(1));
$editor.find("#acctype2").val(giveAccType(2));
Expand Down Expand Up @@ -1320,6 +1331,7 @@ function initUserTable() {
var row = $modal.data("row"),
values = {
uid: $editor.find("#uid").val(),
pincode: $editor.find("#pincode").val(),
username: $editor.find("#username").val(),
acctype: parseInt($editor.find("#acctype").val()),
acctype2: parseInt($editor.find("#acctype2").val()),
Expand All @@ -1338,6 +1350,7 @@ function initUserTable() {
var datatosend = {};
datatosend.command = "userfile";
datatosend.uid = $editor.find("#uid").val();
datatosend.pincode = $editor.find("#pincode").val();
datatosend.user = $editor.find("#username").val();
datatosend.acctype = parseInt($editor.find("#acctype").val());
datatosend.acctype2 = parseInt($editor.find("#acctype2").val());
Expand Down
5 changes: 2 additions & 3 deletions src/wsResponses.esp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void ICACHE_FLASH_ATTR sendUserList(int page, AsyncWebSocketClient *client)
if (json.success())
{
String username = json["user"];
String pincode = json["pincode"];
for (int x = 1; x <= MAX_NUM_RELAYS; x++)
{
String theKey = String();
Expand All @@ -34,14 +35,12 @@ void ICACHE_FLASH_ATTR sendUserList(int page, AsyncWebSocketClient *client)
else
theKey = "acctype" + String(x);
int AccType = json[theKey];
#ifdef DEBUG
// Serial.printf ("[ DEBUG ] User uid %s Acctype %d %d key %s\n", uid.c_str() , x ,AccType,theKey.c_str());
#endif
item[theKey] = AccType;
}
unsigned long validuntil = json["validuntil"];
item["username"] = username;
item["validuntil"] = validuntil;
item["pincode"] = pincode;
}
}
i++;
Expand Down
Loading