Compare commits

...

9 Commits
0.05 ... master

2 changed files with 82 additions and 76 deletions

View File

@ -1,7 +1,7 @@
/*
* Open Source RFID Access Controller - Ethernet Branch
*
* 3/21/2013 v0.05 (branch based on upstream 4/3/2011 v1.32)
* 12/01/2013 v0.06 (branch based on upstream 4/3/2011 v1.32)
* Will Bradley - will@heatsynclabs.org
* Short Tie - tie.short@gmail.com
*
@ -72,6 +72,7 @@
* L=locked (1=door1, 2=door2, 3=bedtime)
* M=minute (#=minute)
* m=alarm state (# level)
* p=power on (reboot)
* R=read tag (# card num)
* r=second half of tag
* Q=superuser authed (#=superuser)
@ -138,42 +139,42 @@ IPAddress ip(192,168,1,177);
#define ALARMSIRENPIN relayPins[1] // Define the alarm siren pin. This should be a LOUD siren for alarm purposes.
/* Definitions for Log types */
#define LOG_REBOOT 0
#define LOG_CHIME 1
#define LOG_TAG_PRESENT 2
#define LOG_ACCESS_GRANTED 3
#define LOG_ACCESS_DENIED 4
#define LOG_KEYPAD_COMMAND 5
#define LOG_ALARM_ZONE 6
#define LOG_ALARM_TRIGGERED 7
#define LOG_UNLOCK 8
#define LOG_LOCK 9
#define LOG_ALARM_STATE 10
#define LOG_ALARM_ARMED 11
#define LOG_PRIVELEDGE_FAILED 12
#define LOG_ALARM_TRAIN 13
#define LOG_SUPERUSER 14
#define LOG_HARDWARE_TEST 15
#define LOG_CLEAR_USERS 16
#define LOG_ADD_USER_FAIL 17
#define LOG_ADD_USER_SUCCESS 18
#define LOG_DELETE_USER_FAIL 19
#define LOG_DELETE_USER_SUCCESS 20
#define LOG_CHECK_USER 21
#define LOG_LOGIN_FAIL 22
#define LOG_LOGIN_SUCCESS 23
#define LOG_LOCKED_OUT_USER 24
#define LOG_CLEAR_LOG 25
#define LOG_REBOOT 0
#define LOG_CHIME 1
#define LOG_TAG_PRESENT 2
#define LOG_ACCESS_GRANTED 3
#define LOG_ACCESS_DENIED 4
#define LOG_KEYPAD_COMMAND 5
#define LOG_ALARM_ZONE 6
#define LOG_ALARM_TRIGGERED 7
#define LOG_UNLOCK 8
#define LOG_LOCK 9
#define LOG_ALARM_STATE 10
#define LOG_ALARM_ARMED 11
#define LOG_PRIVELEDGE_FAILED 12
#define LOG_ALARM_TRAIN 13
#define LOG_SUPERUSER 14
#define LOG_HARDWARE_TEST 15
#define LOG_CLEAR_USERS 16
#define LOG_ADD_USER_FAIL 17
#define LOG_ADD_USER_SUCCESS 18
#define LOG_DELETE_USER_FAIL 19
#define LOG_DELETE_USER_SUCCESS 20
#define LOG_CHECK_USER 21
#define LOG_LOGIN_FAIL 22
#define LOG_LOGIN_SUCCESS 23
#define LOG_LOCKED_OUT_USER 24
#define LOG_CLEAR_LOG 25
/* Definitions for LOG_PRIVILEDGE_FAILED */
#define WRONG_PASSWORD 0
#define TOO_MANY_TRIES 1
#define NOT_LOGGED_IN 2
#define WRONG_PASSWORD 0
#define TOO_MANY_TRIES 1
#define NOT_LOGGED_IN 2
/* Defintions for LOG_LOCK */
#define DOOR1 1
#define DOOR2 2
#define BEDTIME 3
#define DOOR1 1
#define DOOR2 2
#define BEDTIME 3
byte reader1Pins[]={2,3}; // Reader 1 connected to pins 4,5
byte reader2Pins[]= {4,5}; // Reader2 connected to pins 6,7
@ -252,16 +253,16 @@ PCATTACH pcattach; // Software interrupt library
*/
const prog_uchar httpheaderok[] PROGMEM = {"HTTP/1.1 200 OK\r\nCache-Control: no-store\r\nContent-Type: text/html\r\n\r\n"};
const prog_uchar title[] PROGMEM = {"<h2>OAC</h2>"};
const prog_uchar help[] PROGMEM = {"<hr/>See source for command syntax."}; //<pre>Numbers must be padded.\n\n?e=0000 - enable priv (0 to logout)\n?s000 - show user\n?m000&p000&t00000000 - modify user(0-200) perm(0-255) tag(0-f)\n?a - list all\n?r000 - remove user\n?o1 ?o2 - open door 1/2\n?u ?u=1 ?u=2 - unlock all/1/2\n?l ?l=1 ?l=2 - lock all/1/2\n?1 - disarm\n?2 - arm\n?3 - train\n?9 - status\n?z - show log\n?y - clear log\n?w0000000000000 - show year-month-day-dayofweek-hour-min-sec\n?x - set year-month-day-dayofweek-hour-min-sec\n?v=0 ?v=1 ?v=2 ?v=3 - set logging to MostVerbose/Verbose/Quiet/MostQuiet</pre>"};
const prog_uchar noauth[] PROGMEM = {"<a href='/'>Not logged in.</a>"};
const prog_uchar unlockboth[] PROGMEM = {"Unlocked all."};
const prog_uchar unlock1[] PROGMEM = {"Unlocked 1."};
const prog_uchar unlock2[] PROGMEM = {"Unlocked 2."};
const prog_uchar open1[] PROGMEM = {"Opened 1."};
const prog_uchar open2[] PROGMEM = {"Opened 2."};
const prog_uchar lockboth[] PROGMEM = {"Locked all."};
const unsigned char httpheaderok[] PROGMEM = {"HTTP/1.1 200 OK\r\nCache-Control: no-store\r\nContent-Type: text/html\r\n\r\n"};
const unsigned char title[] PROGMEM = {"<h2>Open Access Control</h2>"};
const unsigned char help[] PROGMEM = {"<hr/>See help[] source for command syntax (https://github.com/zyphlar/Open_Access_Control_Ethernet)."}; //<pre>Numbers must be padded.\n\n?e=0000 - enable priv (0 to logout)\n?s000 - show user\n?m000&p000&t00000000 - modify user(0-200) perm(0-255) tag(0-f)\n?a - list all\n?r000 - remove user\n?o1 ?o2 - open door 1/2\n?u ?u=1 ?u=2 - unlock all/1/2\n?l ?l=1 ?l=2 - lock all/1/2\n?1 - disarm\n?2 - arm\n?3 - train\n?9 - status\n?z - show log\n?y - clear log\n?w0000000000000 - show year-month-day-dayofweek-hour-min-sec\n?x - set year-month-day-dayofweek-hour-min-sec\n?v=0 ?v=1 ?v=2 ?v=3 - set logging to MostVerbose/Verbose/Quiet/MostQuiet</pre>"};
const unsigned char noauth[] PROGMEM = {"<a href='/'>Not logged in.</a>"};
const unsigned char unlockboth[] PROGMEM = {"Unlocked all."};
const unsigned char unlock1[] PROGMEM = {"Unlocked 1."};
const unsigned char unlock2[] PROGMEM = {"Unlocked 2."};
const unsigned char open1[] PROGMEM = {"Opened 1."};
const unsigned char open2[] PROGMEM = {"Opened 2."};
const unsigned char lockboth[] PROGMEM = {"Locked all."};
const int divisor = 32767;
@ -297,7 +298,7 @@ void setup(){ // Runs once at Arduino boot-up
// Serial.begin(57600); // Set up Serial output at 8,N,1,57600bps
// Serial.begin(57600); // Set up Serial output at 8,N,1,57600bps
log(LOG_REBOOT, 0, 0);
@ -711,7 +712,7 @@ void loop() // Main branch, runs over and ov
if(alarmActivated==0){ // If alarm is armed but not currently alarming, check sensor zones.
for(int i=0; i<NUM_SENSORS; i++) { // For each of the Sensors Check their status
for(int i=0; i<NUM_SENSORS; i++) { // For each of the Sensors Check their status
if(pollAlarm(i) == 1 ){
if(i == 0 || i == 3){ // If zone 0 or 3 are tripped, immediately set Alarm State to 2 (alarm delay).
@ -727,7 +728,7 @@ void loop() // Main branch, runs over and ov
sensor[i]=true; // Set value to not log this again
}
}
}
}
}
if(alarmActivated==1) { // If alarm is actively going off (siren/strobe) for 10 min (6e5=10min)
if(millis()-alarmSirenTimer >=3.6e6) // Check for alarm interval expired and turn off if needed
@ -1085,7 +1086,7 @@ int processTagAccess(long reader, int doorNum) {
}
else
{
{
if(checkSuperuser(reader) >= 0) { // Check if a superuser, grant access.
log(LOG_ACCESS_GRANTED,reader, doorNum); // Log and unlock door 2
alarmState(0);
@ -1238,10 +1239,10 @@ void log(byte Action, long LongInfo, byte ShortInfo)
// Most Verbose Logging level.
case 0: {
switch(Action) {
case LOG_CHIME: { // Chime
case LOG_CHIME: { // Chime
//PROGMEMprintln(doorChimeMessage);
}
case LOG_ALARM_ARMED: { //log Alarm Armed - ShortInof is alarm level
case LOG_ALARM_ARMED: { //log Alarm Armed - ShortInof is alarm level
addToLog('A',ShortInfo);
break;
}
@ -1249,11 +1250,11 @@ void log(byte Action, long LongInfo, byte ShortInfo)
addToLog('c', ShortInfo);
break;
}
case LOG_ALARM_STATE: { // Log Alarm State - ShortInfo is alarm level
case LOG_ALARM_STATE: { // Log Alarm State - ShortInfo is alarm level
addToLog('m',ShortInfo);
break;
}
case LOG_ALARM_ZONE: { // Log Alarm zone events - ShortInfo is zone
case LOG_ALARM_ZONE: { // Log Alarm zone events - ShortInfo is zone
addToLog('s',ShortInfo);
break;
}
@ -1267,11 +1268,11 @@ void log(byte Action, long LongInfo, byte ShortInfo)
// Verbose Logging level.
case 1: {
switch(Action) {
case LOG_SUPERUSER: { // Log superuser card used - ShortInfo is the SuperUser number
case LOG_SUPERUSER: { // Log superuser card used - ShortInfo is the SuperUser number
addToLog('Q',ShortInfo);
break;
}
case LOG_TAG_PRESENT: { // Log Tag Presented event - LongInfo is user, ShortInfo door number
case LOG_TAG_PRESENT: { // Log Tag Presented event - LongInfo is user, ShortInfo door number
addToLog('R',LongInfo%divisor);
addToLog('r',LongInfo/divisor);
break;
@ -1291,32 +1292,32 @@ void log(byte Action, long LongInfo, byte ShortInfo)
// Queit Logging level.
case 2: {
switch(Action) {
case LOG_ACCESS_GRANTED: { // Log Access Granted event - LongInfo is user, ShortInfo door number
case LOG_ACCESS_GRANTED: { // Log Access Granted event - LongInfo is user, ShortInfo door number
addToLog('G',LongInfo%divisor);
addToLog('g',LongInfo/divisor);
break;
}
case LOG_ACCESS_DENIED: { // Log Access Denied event - LongInfo is user, ShortInfo door number
case LOG_ACCESS_DENIED: { // Log Access Denied event - LongInfo is user, ShortInfo door number
addToLog('D',LongInfo%divisor);
addToLog('d',LongInfo/divisor);
break;
}
case LOG_KEYPAD_COMMAND: { // Log Keypad command - logkeypadCommand(byte user, long command)
case LOG_KEYPAD_COMMAND: { // Log Keypad command - logkeypadCommand(byte user, long command)
addToLog('C',LongInfo%divisor);
addToLog('c',LongInfo/divisor);
break;
}
case LOG_UNLOCK: { // Log unlock event - LongInfo is user, ShortInfo is door
case LOG_UNLOCK: { // Log unlock event - LongInfo is user, ShortInfo is door
addToLog('U',ShortInfo);
break;
}
case LOG_LOCK: { // Log lock event - ShortInfo is door number
case LOG_LOCK: { // Log lock event - ShortInfo is door number
addToLog('L',ShortInfo);
break;
}
case LOG_ALARM_TRAIN: {
//PROGMEMprintln(alarmtrainMessage);
addToLog('t',LongInfo/divisor); // Log training of sensor values - LongInfo is sensor average, ShortInfo is sensor number
addToLog('t',LongInfo/divisor); // Log training of sensor values - LongInfo is sensor average, ShortInfo is sensor number
break;
}
default: {}
@ -1326,11 +1327,11 @@ void log(byte Action, long LongInfo, byte ShortInfo)
// Most Queit Logging level. These will always be logged.
default:{
switch(Action) {
case LOG_REBOOT: { // Reboot - Log system startup
//PROGMEMprintln(rebootMessage);
case LOG_REBOOT: { // Reboot - Log system startup
addToLog('p',1);
break;
}
case LOG_ALARM_TRIGGERED: { // Log Alarm Triggered
case LOG_ALARM_TRIGGERED: { // Log Alarm Triggered
addToLog('T',0);
break;
}
@ -1362,7 +1363,7 @@ void log(byte Action, long LongInfo, byte ShortInfo)
addToLog('F',1);
break;
}
case LOG_LOCKED_OUT_USER: { // log Locked out user attempted access, LongInfo user, ShortInfo usermask
case LOG_LOCKED_OUT_USER: { // log Locked out user attempted access, LongInfo user, ShortInfo usermask
addToLog('f',ShortInfo);
break;
}
@ -1587,20 +1588,20 @@ boolean login(long input) {
}
void printStatus(EthernetClient client) {
client.println("<pre>");
client.print("Alarm armed:");
client.println(alarmArmed,DEC);
client.print("Alarm activated:");
client.println("{");
client.print("\"armed\":");
client.print(alarmArmed,DEC);
client.print(",\"activated\":");
client.println(alarmActivated,DEC);
client.print("Alarm 3:");
client.print(",\"alarm_3\":");
client.println(pollAlarm(3),DEC);
client.print("Alarm 2:");
client.println(pollAlarm(2),DEC);
client.print("Door 1 locked:");
client.println(door1Locked);
client.print("Door 2 locked:");
client.println(door2Locked);
client.println("</pre>");
client.print(",\"alarm_2\":");
client.println(pollAlarm(2),DEC);
client.print(",\"door_1_locked\":");
client.println(door1Locked);
client.print(",\"door_2_locked\":");
client.println(door2Locked);
client.println("}");
}
@ -1625,7 +1626,7 @@ void printLog(EthernetClient client) {
}
void PROGMEMprintln(EthernetClient client, const prog_uchar str[]) // Function to retrieve strings from program memory
void PROGMEMprintln(EthernetClient client, const unsigned char str[]) // Function to retrieve strings from program memory
{
char c;
if(!str) return;

View File

@ -37,6 +37,8 @@ The software has the following features:
-(4) Relay outputs
USAGE:
The following pin assignments are assumed by this software:
-Pins 2,3 for Reader 1
@ -45,4 +47,7 @@ The following pin assignments are assumed by this software:
-Pins A0,A1,A2,A3 for alarm sensors
-Pins A4,A5 for SDA,SCL (I2C)
You'll need to adjust the IPAddress and the PRIVPASSWORD to fit your environment/preferences.
(g*32767+G-1)/2