Apr-30-2018, 11:46 PM
(This post was last modified: May-01-2018, 12:04 AM by BadgerHack.)
Hi all,
Please excuse me for maybe a dumb question within this forum but I am currently working on my university final project and need to do some coding for it. The reason why I'm posting is just because I haven't got much time left and the code I have "built" does not loop at all - there is the code:

And sorry, just realised that probably I had to post it in Homework section not here, I am happy if this post will be moved to other section if that will help me faster :)
Please excuse me for maybe a dumb question within this forum but I am currently working on my university final project and need to do some coding for it. The reason why I'm posting is just because I haven't got much time left and the code I have "built" does not loop at all - there is the code:
import RPi.GPIO as GPIO import sys import MySQLdb import MFRC522GPS import time from time import strftime,localtime,sleep import logging import thread def connect(): return MySQLdb.connect(host='', user='', passwd='', db='') MySQLdb.close() MIFAREReader = MFRC522GPS.MFRC522() def setGpio(): GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(40, GPIO.OUT, initial=GPIO.HIGH) #power indicator GPIO.setup(38, GPIO.OUT, initial=GPIO.HIGH) #red LED GPIO.setup(36, GPIO.OUT, initial=GPIO.HIGH) #green LED GPIO.setup(32, GPIO.OUT, initial=GPIO.HIGH) #blue LED def write(cardId,row): db = connect() c = db.cursor() currentTime=strftime("%Y-%m-%d %H:%M:%S", localtime()) c.execute("""INSERT INTO zone1 (rfid_no, ticket_type, time) VALUES (%s, %s, %s)""",(cardId, row[2], currentTime)) db.commit() db.close() action = "Come In!" return action try: setGpio() while True: GPIO.output(40, GPIO.LOW) #Power indicator print("=============================================") print("Please scan Smart-Band") print("=============================================") def identity(): reading = True while reading: (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) if status == MIFAREReader.MI_OK: print("Card detected. Identifying...") GPIO.output(32, GPIO.LOW) #blue LED (status,backData) = MIFAREReader.MFRC522_Anticoll() if status == MIFAREReader.MI_OK: print ("Card ID: "+str(backData[0])+""+str(backData[1])+""+str(backData[2])+""+str(backData[3])+""+str(backData[4])) MIFAREReader.AntennaOff() reading = False return str(backData[0])+str(backData[1])+str(backData[2])+str(backData[3])+str(backData[4]) def read(): cardId=identity() return cardId def readTag(action): if (action): cardId=read() db = connect() c = db.cursor() find = c.execute("SELECT *FROM personal_info WHERE rfid_no = " + cardId) if find: for row in c.fetchall(): check = c.execute("SELECT zone_1 FROM access WHERE type=%s AND zone_1=%s", (row[2], 1)) if check: name = write(cardId,row) GPIO.output(32, GPIO.HIGH) #blue LED GPIO.output(36, GPIO.LOW) #green LED sleep(2.0) GPIO.output(36, GPIO.HIGH) print (name) else: print "denied" GPIO.output(32, GPIO.HIGH) #blue LED GPIO.output(38, GPIO.HIGH) #red LED sleep(0.2) GPIO.output(38, GPIO.LOW) sleep(0.2) GPIO.output(38, GPIO.HIGH) sleep(0.2) GPIO.output(38, GPIO.LOW) sleep(0.2) GPIO.output(38, GPIO.HIGH) sleep(0.2) GPIO.output(38, GPIO.LOW) sleep(0.2) GPIO.output(38, GPIO.HIGH) choice = readTag readTag(choice) except KeyboardInterrupt: GPIO.cleanup()Being honest with you all, if I would have more time I would give it another attempt to find the problem but I really need some help now


And sorry, just realised that probably I had to post it in Homework section not here, I am happy if this post will be moved to other section if that will help me faster :)