Hardware Reference
In-Depth Information
Run your program and enter your name as Andrew and the password as 1234 . You will see
the following output:
checking for input
please enter your name: Andrew
please enter your password: 1234
reading from file
checking input of 'Andrew', password: 1234, against ;
secret password '9876'
authentication is: False
Notice how the password 9876 is read from the ile. Add more usernames and passwords
(commas separated) to the ile secrets.txt, one per line. Test the program with diferent user-
names and passwords to check that the door opens when it should, and more importantly,
that it doesn't when it shouldn't! For the full code listing, go to the topic's website at www.
wiley.com/g o/raspberrypiprojects .
It is tempting to think that your program works when it gives the behaviour you want - such
as in the case of the door lock, if the door is unlocked when the correct password is entered.
However, it is just as important to test programs for other cases; for the door lock example,
you need to test that the door isn't opened if the incorrect password is entered. In industry,
testing is very important, and programmers aim for high levels of code coverage - that is, that
much of the code has been tested. This may mean running the program with a wide range of
sample inputs.
Unlocking Doors Without Touching
You may have seen door locks for which you can wave a card or plastic fob against a reader.
hese work using radio frequency identiication (RFID) technology. he Raspberry Pi makes it
easy to incorporate an RFID reader into your door lock.
You will need to buy a USB RFID reader and matching tags, similar to those shown in Figure
12-5. Although these are available from the major component distributors, you may ind
online auction sites to be cheaper. USB RFID readers can appear in diferent ways to the
computer - for example, as an HID USB device (which sends input as if it were a keyboard
typing in characters from the tag) or as a serial port. he USB RFID reader used in this chap-
ter is an HID USB device as it is simplest to program. You could use a USB serial RFID reader,
but you would have to modify the code yourself.
 
Search WWH ::




Custom Search