SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --If you want this to start at every boot of a computer run the following line of code in the startup |
| 1 | + | os.loadAPI("StrUtils")
|
| 2 | - | -- shell.run("RFID","door")
|
| 2 | + | |
| 3 | function inFile(file, string) | |
| 4 | ||
| 5 | - | --The door stays open as long as you stay in the area of the reader |
| 5 | + | local f = fs.open(file,"r") |
| 6 | - | -- !!! Make sure there is no creeper behind you !!! |
| 6 | + | local line |
| 7 | ||
| 8 | - | -- Set up your own door system |
| 8 | + | repeat |
| 9 | - | doorPass = "wsxedcrfvbgtnhzmjuzvrnzcif" --Max Length 82 chars |
| 9 | + | line = f.readLine() |
| 10 | - | cardLabel = "Ident: Front Door" --Max Length 20 chars |
| 10 | + | if string==line then |
| 11 | - | --Make sure the following sides are equal to your build |
| 11 | + | f.close() |
| 12 | - | readerSide = "right" |
| 12 | + | return true |
| 13 | end | |
| 14 | until not line | |
| 15 | ||
| 16 | - | --Variables (Don¥B4t change) |
| 16 | + | f.close() |
| 17 | - | tArgs = {...}
|
| 17 | + | return false |
| 18 | ||
| 19 | end | |
| 20 | - | -- Check the arguments given |
| 20 | + | |
| 21 | - | if #tArgs < 1 then |
| 21 | + | readerSide = "back" |
| 22 | - | print("Usage:")
|
| 22 | + | |
| 23 | - | print("RFID write")
|
| 23 | + | |
| 24 | - | print("RFID door")
|
| 24 | + | |
| 25 | - | return |
| 25 | + | |
| 26 | - | end |
| 26 | + | |
| 27 | reader = peripheral.wrap(readerSide) | |
| 28 | - | mode = tArgs[1] |
| 28 | + | |
| 29 | - | shell.run("clear")
|
| 29 | + | |
| 30 | reader.scan() --Creats an "rfid_detected" when a card is in range | |
| 31 | - | if mode == "write" then |
| 31 | + | |
| 32 | - | writer = peripheral.wrap(writerSide) |
| 32 | + | |
| 33 | - | print("Enter writing mode")
|
| 33 | + | if inFile("//.keys", StrUtils.SHA1(p1)) and p2 < 3 then
|
| 34 | - | print("Insert card in the writer")
|
| 34 | + | |
| 35 | - | while not writer.isPresent() do --Waits until a card is in the writer |
| 35 | + | |
| 36 | - | sleep(0) |
| 36 | + | |
| 37 | - | end |
| 37 | + | |
| 38 | - | |
| 38 | + | |
| 39 | - | if writer.encode(doorPass, cardLabel) then --Start write to card |
| 39 | + | |
| 40 | - | print("Start writing Pass to card")
|
| 40 | + | end |