Hallo all,
hatte Hilfe.
Hier ist ein Script womit man steuern kann ob die Tür öffnet oder nicht mit der Beschränkung falsche PIN Eingabe oder außerhalb der Öffnungszeiten. Anstreuerung Relaise oder was auch immer muss angepasst werden. Was man noch in eine Datenbank Ausgliederung sollte sind die validen PINS.
Python
#!/usr/bin/env python
from time import sleep
#import pifacedigitalio as pfio
from subprocess import Popen
import string
from time import *
import sys
import termios
import tty
def checkpin(count):
if count >= 3:
print("Pin 3 mal falsch eingegeben!")
exit()
# end if pin counter check
#
# access array, change it!
# Syntax: [[PIN,"STARTTIME","ENDTIME"], ...]
#
valid_pins = [
[1234,"07:00","13:00"],
[2345],
[12345,"07:00","22:00"]
]
exitchar = "*"
#
#
#
x = getPin(exitchar)
# filter digits
try:
x = int(x)
except ValueError:
# wenn Buchstaben uebergeben wurden=>neustart
checkpin(count)
# end filter
for valid_array in valid_pins:
valid_pin = valid_array[0]
valid_start_time = 0
valid_end_time = 0
if len(valid_array) == 3:
valid_start_time = valid_array[1]
valid_end_time = valid_array[2]
# end if valid_array_check
if x == valid_pin:
if valid_start_time != 0 and valid_end_time != 0:
shall_pass = check_time(valid_start_time,valid_end_time)
else:
shall_pass = 1
# end if time check
if shall_pass == 1:
# pfio.init()
# p = Popen(['./tuer.sh'])
# pfio.digital_write(0, 1)
# sleep(3)
# pfio.digital_write(0, 0)
# p.terminate()
print("hat geklappt")
exit()
# end if shall_pass check
# pin is valid but user is not in time
print("Ausserhalb der Zeit!")
exit()
# end if valid_pin
# end for
checkpin(count+1)
# end def checkpin
def check_time(start,end):
lt = localtime()
time = strftime("%H:%M",lt)
# fuck ist das geil
if start < time and time < end:
return 1
else:
return 0
# end if time check
#end def check_time
def getPin(exitchar):
# version with enter as exit key
# x = raw_input("Pin?")
print("Pin?"),
x = ''
while True:
old = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin)
val = sys.stdin.read(1)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old)
if str(val) == exitchar:
break
else:
print("*"),
x = x + val
# end if str equality
# end while key loop
print("")
return x
# end def getPin
checkpin(0)
Alles anzeigen
Viel Spaß damit
Sebastian