Skip to content

Commit

Permalink
cchanged Wiegand library to WiegandNG, Bits selectable in HardwareSet…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
pvtex committed Jun 12, 2024
1 parent cba9955 commit cc7b24c
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 37 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.piolibdeps
.clang_complete
.gcc-flags.json
.pio

# esp-rfid
src/websrc/css/required.css
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ lib_deps =
https://github.com/lorol/ESPAsyncWebServer
[email protected]
https://github.com/miguelbalboa/rfid#ea7ee3f3daafd46d0c5b8438ba41147c384a1f0d
matjack1/Wiegand Protocol Library for Arduino - for esp-rfid@^1.1.1
;matjack1/Wiegand Protocol Library for Arduino - for esp-rfid@^1.1.1
https://github.com/pvtex/Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino
[email protected]
[email protected]

Expand Down
4 changes: 3 additions & 1 deletion src/config.esp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ bool ICACHE_FLASH_ATTR loadConfiguration(Config &config)
{
int wgd0pin = hardware["wgd0pin"];
int wgd1pin = hardware["wgd1pin"];
int wiegandbits = hardware["wiegandbits"];
if (hardware.containsKey("requirepincodeafterrfid"))
{
config.pinCodeRequested = hardware["requirepincodeafterrfid"];
Expand All @@ -136,7 +137,8 @@ bool ICACHE_FLASH_ATTR loadConfiguration(Config &config)
{
config.wiegandReadHex = hardware["useridstoragemode"] == "hexadecimal";
}
setupWiegandReader(wgd0pin, wgd1pin, config.removeParityBits); // also some other settings like weather to use keypad or not, LED pin, BUZZER pin, Wiegand 26/34 version

setupWiegandReader(wgd0pin, wgd1pin, config.removeParityBits, wiegandbits); // also some other settings like weather to use keypad or not, LED pin, BUZZER pin, Wiegand 26/34 version
}
else if (config.readertype == READER_MFRC522 || config.readertype == READER_MFRC522_RDM6300)
{
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ struct Config {
uint8_t wifipin = 255;
const char *wifiPassword = NULL;
unsigned long wifiTimeout = 0;
int wiegandbits = 58;
};
4 changes: 4 additions & 0 deletions src/magicnumbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#define WIEGANDTYPE_KEYPRESS8 8
#define WIEGANDTYPE_PICC24 24
#define WIEGANDTYPE_PICC34 34
#define WIEGANDTYPE_PICC37 37
#define WIEGANDTYPE_PICC44 44
#define WIEGANDTYPE_PICC56 56
#define WIEGANDTYPE_PICC58 58

// hardware defines

Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ Config config;

#include <MFRC522.h>
#include "PN532.h"
#include <Wiegand.h>
#include <WiegandNG.h>
#include "rfid125kHz.h"

MFRC522 mfrc522 = MFRC522();
PN532 pn532;
WIEGAND wg;
WiegandNG wg;
RFID_Reader RFIDr;

// relay specific variables
Expand Down
33 changes: 23 additions & 10 deletions src/rfid.esp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ String v1uid = "";
String username = "";
bool wiegandAvailable = false;

#define WIEGAND_ENT 0xD
#define WIEGAND_ESC 0x1B
#define WIEGAND_ENT "b" //0xD
#define WIEGAND_ESC "a" //0x1B

enum RfidStates
{
Expand Down Expand Up @@ -52,11 +52,12 @@ void wiegandRead()
{
if (wiegandAvailable && rfidState == waitingRfid)
{
// if we get anything between 24 or 34 bit burst then we have a scanned PICC
if (wg.getWiegandType() >= WIEGANDTYPE_PICC24 && wg.getWiegandType() <= WIEGANDTYPE_PICC34)
wg.pause();
// if we get anything between 24 or 58 bit burst then we have a scanned PICC
if (wg.getBitCounted() >= WIEGANDTYPE_PICC24 && wg.getBitCounted() <= WIEGANDTYPE_PICC58)
{
uid = String(wg.getCode(), config.wiegandReadHex ? HEX : DEC);
type = String(wg.getWiegandType(), DEC);
type = String(wg.getBitCounted(), DEC);
#ifdef DEBUG
Serial.print(F("[ INFO ] PICC's UID: "));
Serial.println(uid);
Expand Down Expand Up @@ -100,6 +101,7 @@ void wiegandRead()
processingState = unknown;
}
}
wg.clear();
}
}

Expand Down Expand Up @@ -273,19 +275,23 @@ void pinCodeRead()
// for the next key unless * or # have been pressed
// we do not require * as the first character because some
// readers use this as special admin code and would hence require *#PIN#
if (wg.getWiegandType() == WIEGANDTYPE_KEYPRESS4 || wg.getWiegandType() == WIEGANDTYPE_KEYPRESS8)

wg.pause();
if (int(wg.getBitCounted()) == WIEGANDTYPE_KEYPRESS4 || int(wg.getBitCounted()) == WIEGANDTYPE_KEYPRESS8)
{
if (wg.getCode() != WIEGAND_ENT && wg.getCode() != WIEGAND_ESC) // normal key entry, add to currentInput
if (String(wg.getCode(), HEX) != WIEGAND_ENT && String(wg.getCode(), HEX) != WIEGAND_ESC) // normal key entry, add to currentInput
{
#ifdef DEBUG
Serial.println("Keycode captured. . .");
Serial.print("Key: ");
Serial.println(String(wg.getCode(), HEX));
#endif
currentInput = currentInput + String(wg.getCode());
keyTimer = millis();
ledWaitingOn();
} else if (keyTimer > 0) // if we are waitingProcessing on input still
{
if(wg.getCode() == WIEGAND_ESC) // esc, abort pincode
if(String(wg.getCode(), HEX) == WIEGAND_ESC) // esc, abort pincode
{
#ifdef DEBUG
Serial.println("Keycode escape, aborting pincode entry");
Expand All @@ -294,7 +300,7 @@ void pinCodeRead()
processingState = cancelled;
cooldown = millis() + COOLDOWN_MILIS;
}
if(wg.getCode() == WIEGAND_ENT) // enter, process pincode
if(String(wg.getCode(), HEX) == WIEGAND_ENT) // enter, process pincode
{
pinCode = currentInput;
if (config.pinCodeOnly && rfidState == waitingRfid)
Expand All @@ -316,6 +322,7 @@ void pinCodeRead()
}
}
}
wg.clear();
}

int weekdayFromMonday(int weekdayFromSunday) {
Expand Down Expand Up @@ -638,7 +645,13 @@ void ICACHE_FLASH_ATTR ShowMFRC522ReaderDetails()

void ICACHE_FLASH_ATTR setupWiegandReader(int d0, int d1, bool removeParityBits)
{
wg.begin(d0, d1, removeParityBits);
wg.begin(d0, d1, 58, 15); //58bit
rfidState = waitingRfid;
}

void ICACHE_FLASH_ATTR setupWiegandReader(int d0, int d1, bool removeParityBits, int wiegandbits)
{
wg.begin(d0, d1, wiegandbits, 15);
rfidState = waitingRfid;
}

Expand Down
Loading

0 comments on commit cc7b24c

Please sign in to comment.