-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbkms-door-code.ino
65 lines (53 loc) · 1.51 KB
/
bkms-door-code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Arduino.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
/*
* Required values
* - SECRET_KEY: uint8_t[6] secret key to use
* - mac: mac address to use
*/
#include "bkms-secrets.h"
#include "config.h"
#include "makey.h"
#include "ethernetMaintainer.h"
#include "doorDisplay.h"
#include "doorLock.h"
#include "cardReaderSystem.h"
EthernetClient client;
EthernetMaintainer maintainer;
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
#ifdef DISPLAY_LCD
LiquidCrystal_I2C lcd_peripherial(0x27,20,4);
DoorLCDDisplay lcd_display(&lcd_peripherial);
DoorDisplay *display = &lcd_display;
#else
DoorSerialDisplay serial_display;
DoorDisplay *display = &serial_display;
#endif
Makey makey(SERVER_URL, SERVER_PORT, &client);
DoorLock lock(DOOR_PIN);
CardReaderSystem readerSystem(display, &lock, &makey, &nfc, SECRET_KEY);
void setup(void) {
delay(2000);
Serial.begin(115200);
lock.reset();
Serial.println("Hello!");
display->loadingMessage("INIT NFC...");
readerSystem.initializeReader();
display->loadingMessage("INIT NETWORK...");
maintainer.initialize(mac, ip, myDns);
display->loadingMessage("INIT KEYS...");
makey.rotateKey();
Serial.println("Waiting for an ISO14443A Card ...");
display->readyMessage();
}
void loop(void) {
readerSystem.attemptRead();
while(!maintainer.maintain()) {
display->message("NETWORK FAILURE", "DHCP ERROR");
delay(500);
}
}