A USB powered RFID card reader (125khz) is plugged into the other Tessel USB port. This reader behaves like a keyboard; when a card is scanned it sends a string of card numbers as keys with a newline character.
The application listens for card scan events and when one if found, it looks the card number up in a local database (the above mentioned `json` file). If it finds a card, it opens the door, if not it shows an error message.
To open the door, we use a relay (or optionally a TIP120 transistor) which powers a [12v door latch][latch]. If no power is sent to the door latch, it remains locked. When it gets a 12v current it opens and allows the member entry.
When the device first turns on it connects to WiFi and then fetches all the member RFID cards from the Cobot checkin token API and then updates the `json` card file. It completely overwrites the existing list of cards. If there is a failure getting the cards, we keep the original card list as a fallback.
We periodically sync this list every few minutes (configurable).
#### Access Log
We log every door open event so we can keep and eye on usage. We log an entry containing the member name, datetime and RFID card number in a `json` file. This list is sent to Cobot periodically so we can create a "checkin" for a member. Once the list is pushed successfully we clear out the file.
We use [Jest][jest] to do testing of the core code in the library. Make sure to write tests for new code or update tests on existing code as needed. Test files are next to their source file named with a `.test.js` extension.