Skip to content

Commit f199ca0

Browse files
committed
PN532 is now working
1 parent 5b15c40 commit f199ca0

File tree

9 files changed

+74
-29
lines changed

9 files changed

+74
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.pio
22
.vscode
3+
src/websrc/process
34
tools/webfilesbuilder/node_modules
45
tools/webfilesbuilder/package-lock.json
56
tools/wsemulator/node_modules

src/config.esp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,55 @@ bool loadConfiguration(Config &config)
132132
config.numRelays = 1;
133133

134134
config.readertype = hardware["readertype"];
135+
int rfidss;
135136
config.pinCodeRequested = false;
136137
config.pinCodeOnly = false;
137-
138-
config.wgd0pin = hardware["wgd0pin"];
139-
config.wgd1pin = hardware["wgd1pin"];
140-
config.wiegandbits = hardware["wiegandbits"];
138+
if (config.readertype == READER_WIEGAND || config.readertype == READER_WIEGAND_RDM6300)
139+
{
140+
int wgd0pin = hardware["wgd0pin"];
141+
int wgd1pin = hardware["wgd1pin"];
142+
config.wiegandbits = hardware["wiegandbits"];
143+
if (hardware["requirepincodeafterrfid"].is<bool>())
144+
{
145+
config.pinCodeRequested = hardware["requirepincodeafterrfid"];
146+
}
147+
if (hardware["allowpincodeonly"].is<bool>())
148+
{
149+
config.pinCodeOnly = hardware["allowpincodeonly"];
150+
}
151+
if (hardware["removeparitybits"].is<bool>())
152+
{
153+
config.removeParityBits = hardware["removeparitybits"];
154+
}
155+
if (hardware["useridstoragemode"].is<String>())
156+
{
157+
config.wiegandReadHex = hardware["useridstoragemode"] == "hexadecimal";
158+
}
159+
setupWiegandReader(wgd0pin, wgd1pin, config.removeParityBits); // also some other settings like weather to use keypad or not, LED pin, BUZZER pin, Wiegand 26/34 version
160+
}
161+
else if (config.readertype == READER_MFRC522 || config.readertype == READER_MFRC522_RDM6300)
162+
{
163+
if (hardware["sspin"].is<int>())
164+
{
165+
rfidss = hardware["sspin"];
166+
}
167+
int rfidgain = hardware["rfidgain"];
168+
setupMFRC522Reader(rfidss, rfidgain);
169+
}
170+
else if (config.readertype == READER_PN532 || config.readertype == READER_PN532_RDM6300)
171+
{
172+
if (hardware["sspin"].is<int>())
173+
{
174+
rfidss = hardware["sspin"];
175+
}
176+
setupPN532Reader(rfidss);
177+
}
178+
// RDM6300 can be configured alongside the other readers
179+
if (config.readertype > READER_PN532)
180+
{
181+
int rmd6300TxPin = hardware["rdm6300pin"];
182+
setupRDM6300Reader(rmd6300TxPin);
183+
}
141184

142185
if (hardware["requirepincodeafterrfid"].is<bool>())
143186
{

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct Config
5555
bool pinCodeOnly = false;
5656
bool wiegandReadHex = true;
5757
bool present = false;
58-
int readertype = 1;
58+
int readertype = 2;
5959
int relayType[MAX_NUM_RELAYS];
6060
bool removeParityBits = true;
6161
IPAddress subnetIp;

src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Config config;
4343
#include "rfid125kHz.h"
4444
#include <SoftwareSerial.h>
4545

46+
#define PN532_SCK (14)
47+
#define PN532_MISO (15)
48+
#define PN532_MOSI (2)
49+
int rfidss = 5;
50+
4651
Desfire desfire;
4752
MFRC522 mfrc522 = MFRC522();
4853
PN532 pn532;

src/rfid.esp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ void pn532Read()
185185
}
186186
}
187187

188-
189188
/*
190189
* Try first to read from RDM6300 hardware. If that received
191190
* nothing, check the other configured reader.
@@ -273,7 +272,6 @@ void rfidRead()
273272
}
274273
}
275274

276-
277275
/*
278276
* Try and read a PIN code from Wiegand hardware
279277
*/
@@ -344,15 +342,13 @@ int weekdayFromMonday(int weekdayFromSunday) {
344342
return ( weekdayFromSunday + 5 ) % 7;
345343
}
346344

347-
348345
/*
349346
* If we have successfully read an RFID card, check if access
350347
* should be granted
351348
*/
352349
void rfidProcess()
353350
{
354-
if (rfidState == waitingRfid ||
355-
(config.pinCodeRequested && rfidState == cardSwiped))
351+
if (rfidState == waitingRfid || (config.pinCodeRequested && rfidState == cardSwiped))
356352
{
357353
return;
358354
}
@@ -657,7 +653,7 @@ void setupMFRC522Reader(int rfidss, int rfidgain)
657653
void setupPN532Reader(int rfidss)
658654
{
659655
// init controller
660-
pn532.InitSoftwareSPI(14, 12, 13, rfidss, 0);
656+
pn532.InitSoftwareSPI(PN532_SCK, PN532_MISO, PN532_MOSI, rfidss, 0);
661657
do
662658
{ // pseudo loop (just used for aborting with break;)
663659
// Reset the PN532

src/webh/esprfid.js.gz.h

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

src/websrc/process/final/esprfid.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
1 Byte
Binary file not shown.

src/websrc/ui/esprfid.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ var config = {
3636
"dnseth": ""
3737
},
3838
"hardware": {
39-
"readertype": 1,
39+
"readertype": 2,
4040
"wgd0pin": 4,
4141
"wgd1pin": 5,
4242
"rdm6300pin": 4,
43-
"sspin": 0,
43+
"sspin": 5,
4444
"rfidgain": 32,
4545
"wifipin": 255,
4646
"rtype": 1,
@@ -54,7 +54,7 @@ var config = {
5454
"doorbellpin": 255,
5555
"accessdeniedpin": 255,
5656
"useridstoragemode": "hexadecimal",
57-
"requirepincodeafterrfid": 1,
57+
"requirepincodeafterrfid": 0,
5858
"allowpincodeonly": 0,
5959
"removeparitybits": 1,
6060
"doorstatpin": 255,

0 commit comments

Comments
 (0)