def attend(macAddr): result = json.setAttendence(macAddr, "mac") if (result['status'] == True): return result else: return "Not working"
def poolDevices(self): #try: self.shutdown = False replyQueue = Queue.Queue() print 'Pool devices' if(self.isDeviceActive('nfc') or self.isDeviceActive('camera') ): if(self.isDeviceActive('nfc')): thread1 = threading.Thread(target=self.poolNFC, args=(replyQueue, )) thread1.setDaemon(True) thread1.start() if(self.isDeviceActive('camera')): thread2 = threading.Thread(target=self.poolCamera, args=(replyQueue, )) thread2.setDaemon(True) thread2.start() endTime = datetime.datetime.now() + datetime.timedelta(seconds = config.ActiveTime) currentTime = datetime.datetime.now() while (currentTime < endTime): currentTime = datetime.datetime.now() if(replyQueue.empty != True): # Data receved from one of the devices #get the data data, dataType = replyQueue.get() #if data not in self.dataList: # check for repetition if self.dataList != data: self.dataList = data userData = json.setAttendence(data, dataType) # If server isn't avalable to be connected to, store data to the db if(userData = "cannot connect"): user = self.db.findTag(data, dataType) self.db.addTag(data, dataType) self.displayMessage("-- Offline --") if (user != "not found"): self.displayMessage(user[0][3] + ": " + user[0][2]) else: self.displayMessage(dataType + " tag saved") else: if(userData['status'] != False): # If error happens, display a message otherwise the person's name self.displayMessage(userData['name'] + ": " + userData['studentid']) #TODO else: user = self.db.findTag(data, dataType) if (user != "not found"): self.displayMessage("Error: " + userData['message']) else: self.displayMessage(user[0][3] + ": " + userData['message']) print userData shutdown = True if(self.isDeviceActive('nfc')): thread1.join() if(self.isDeviceActive('camera')): thread2.join() self.cleanGPIO() if(replyQueue.empty != True and config.Testing == True): displayMessage("Queue isn't empty") else: print ("Camera and NFC reader don't exist")