SHOW:
|
|
- or go back to the newest paste.
1 | import time | |
2 | import serial | |
3 | import RPi.GPIO as GPIO | |
4 | import mysql.connector | |
5 | ||
6 | cnx = mysql.connector.connect(user='necro', database='cards') | |
7 | cursor = cnx.cursor() | |
8 | ||
9 | query = ("SELECT RFID, active FROM cards WHERE RFID = '%s';") | |
10 | - | cursor.execute(query, (ID)) |
10 | + | |
11 | GPIO.setmode(GPIO.BCM) | |
12 | ||
13 | GPIO.setup(Majak,GPIO.OUT) | |
14 | - | Tag1 = str('0000CDC66D66') |
14 | + | |
15 | GPIO.setup(Zvonek,GPIO.IN) | |
16 | GPIO.setup(Dvernik,GPIO.IN) | |
17 | GPIO.output(23,False) | |
18 | GPIO.output(24,False) | |
19 | PortRF = serial.Serial('/dev/ttyAMA0',9600) | |
20 | while True: | |
21 | ||
22 | if GPIO.input(Zvonek,True): | |
23 | GPIO.output(Majak,True) | |
24 | time.sleep(5) | |
25 | GPIO.output(Majak,False) | |
26 | if GPIO.input(Dvernik,True): | |
27 | GPIO.output(Zamek,True) | |
28 | time.sleep(10) | |
29 | GPIO.output(Zamek,False) | |
30 | ID = "" | |
31 | read_byte = PortRF.read() | |
32 | if read_byte=="\x02": | |
33 | for Counter in range(12): | |
34 | read_byte=PortRF.read() | |
35 | ID = ID + str(read_byte) | |
36 | print hex(ord( read_byte)) | |
37 | print ID | |
38 | cursor.execute(query, (ID)) | |
39 | ||
40 | for (name, active) in cursor: | |
41 | if active == 1; | |
42 | GPIO.output(Zamek,True) | |
43 | time.sleep(5) | |
44 | GPIO.output(Zamek,False) |