Calendar question for arduino (security system)

Hi guys, i wonder how would you approach this project. I have a uno that will run a door security system and i need to control the time and day that a user is allowed.

I have built a simple array containing data like this:

char *uid[] = {"1469017337" , "43418136" , "9477240142"}; char *user[] = {"Michael Nilsson" , "Anders Ullberg" , "Jan Mostrom"}; int hourin[] = {0, 8, 8}; int minutein[] = {0, 15, 25}; int hourout[] = {23, 16, 22}; int minuteout[] = {59, 0 , 0};

The first user has a UID of 1469017337 and his name is Michael Nilsson, He is allowed entry from 00.00 to 23.59

But what if one wanted to allow entry between two sets of time for one user lets say between 0800-1500 and from 1600-2200. The file where i store these (in a .h file) will quickly become cumbersome to use. Do you guys have any other idea as to how i can solve this?

Then we have the days of the week. One user maybe only should have access on weekdays between 0800-1500 and on sundays between 0800-1000.

How would you solve this problem? With a calender online? Something else?

This is something i came up with, what do you think?

// Choose what day uses what schedule for what user. int groupdays1[] = {0, 1, 1, 1, 1, 1, 0}; // groupdays2 uses schedule 1 for all but sunday and saturday. int groupdays2[] = {0, 1, 1, 1, 1, 1, 0}; int groupdays3[] = {0, 1, 1, 1, 1, 1, 0}; // groupdays4 is an all access group that is open according to timeschedule#3. int groupdays4[] = {3, 3, 3, 3, 3, 3, 3}; int groupdays5[] = {0, 0, 0, 0, 0, 2, 0};

int timeschedule1[3][4] = { //Access to lunchtime {8, 0, 12, 0}, // After lunchbreak we get acccess again to 1600 {13, 15, 16, 0}, // You dont need to use all available time intervalls. {0, 0, 0, 0} };

int timeschedule2[3][4] = { // {0, 0, 0, 0}, // {0, 0, 0, 0}, // The order of the time intervall is not important either, here the space is rented out between 19-2100 hours. {19, 0, 21, 0} };

int timeschedule3[3][4] = { //The owner has 24h access. {0, 0, 23, 59}, // {0, 0, 0, 0}, // {0, 0, 0, 0} };

My first thought is that I would store the times for a single user as a string - perhaps "0,0,59,33" as keeping the stuff together would reduce the strain on my brain.

I suspect you will want to be able to change this data without re-compiling your program. So maybe store it in a file on an SD Card.

If you want the possibility of having several sets of permissions for each person it will inevitably become complex and I would begin to question its suitability for an Arduino. It's the sort of thing I would be inclined to use Python and a a database for. That would make it much easier to update the data with appropriate security.

Have you the option of running a PC (or RaspberryPI) based webserver which handles all the complex stuff and the Arduino just does the simple stuff. Even simpler would be a PC program linked to the Arduino with a USB cable or Bluetooth.

...R PS. I wrote the above before seeing Reply #1.

IMHO the system in Reply #1 would quickly become a nightmare to debug and maintain. Indeed, it already seems to have achieved that status.

if you insist on doing it on the Arduino learn about structs.

...R

I don't know if you would regard this as less cumbersome, but suppose you define a boolean variable for each user, and an array like {240, 450, 950,...,1440,...} (time in minutes from start of day) for each user's boolean variable. Set the variable true at the start of an entry period, set it false at the next time in the array, and so forth, providing effectively on/off periods for each user's entry.

If a user shows up when his boolean is true, he/she gets in, otherwise not.

I think the description in Reply #3 is a little confused.

I think the idea is to have an array for each user for the times s/he is allowed to enter - it would have [start-minutes, end-minutes [,start-minutes, end-minutes] ... ] to define as many allowed periods as required.

Alongside that there would be an array of boolean variables with an element for each user.

Then (if I understand correctly) every time through loop() the program would check for each user whether it is an allowed period or a refused period and set the user's boolean variable accordingly.

Then when a user tries to enter the program just needs to check the status of that user's boolean variable.

IMHO this is a neat idea.

But I think it would get very complicated if different times are needed for different days. And it still requires all the administration code that is required to alter times and add or delete users. It is much easier to build that sort of admin stuff on a PC or browser system where the almost unlimited memory allows the use of much higher-level programming.

...R

OK guys, after some thought i have come up with a new hopefully better plan to solv these problems (and a bunch of new ones).

I will divide the information between the reader and the card as shown below

the reader for my offline security system will contain: - 3 different user groups ABC that will contain information regarding when and on what dates a certain user group can pass through the door. - a unique (within reason) identifier for the door itself.

and on the card contained in one or two sectors of the card - What user group the card belongs to - Information regarding WHAT door it can enter. Ie the same unique identifier can be found both on the eeprom of the door and the card.

TO update the reader with new user group information, a blacklist (for lost UIDS) and so on i will also have a programming card.

Thanks for your help on this and please chime in on this new turn of events.

PS: I have borrowed functions freely from both Simons Voss, Salto and so on.

This way i dont have to worry about cluttering the reader side of things. And also i feel that the security hasn´t been compromised any as otherwise i would have used the freely available UID for passage control. Instead now i write a few bytes of code to the card that isn´t nearly as transparent as the UID (due to security on the card however lacking).

Or is this thinking wrong?