如何使系统实现第二次读取RFID卡以退出?

问题描述 投票:0回答:1

我是初学者,我需要一些帮助/指导!因此,基本上我想尝试使用Raspberry Pi 4和RFID读写器构建考勤系统。到目前为止,一切工作都很好,但是我正在努力发送用于sign_out的数据。现在,在数据库中的sign_out中也标记了sign_in中相同的时间戳,但是在这里我想使当第二次读取RFID卡时,数据被填充在sign_out列中。如果您还有其他建议,我将很乐意听到/学习,谢谢。python代码如下:

#!/usr/bin/env python
import time
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import mysql.connector
import I2C_LCD_driver

db = mysql.connector.connect(
host="localhost",
user="admin",
passwd="*****",
database="attendancesystem")

cursor = db.cursor()
reader = SimpleMFRC522()
lcd = I2C_LCD_driver.lcd()
redLED = 4
yellowLED = 17
greenLED = 27
GPIO.setmode(GPIO.BCM)

try:
  while True:
    lcd.lcd_clear()
    lcd.lcd_display_string('Place Card to')
    lcd.lcd_display_string('record attendance', 2)
    id, text = reader.read()
    cursor.execute("Select id, name FROM users WHERE rfid_uid="+str(id))
    result = cursor.fetchone()

    lcd.lcd_clear()

if cursor.rowcount >= 1:
  lcd.lcd_display_string("Welcome" + result[1])
  lcd.lcd_display_string("" + result[1])
  GPIO.output(greenLED,GPIO.HIGH)
  sleep(3)
  GPIO.output(greenLED,GPIO.LOW)
  cursor.execute("INSERT INTO attendance (user_id) VALUES (%s)", (result[0],) )
  db.commit()
else:
  lcd.lcd_display_string("User does")
  lcd.lcd_display_string("not exist !!", 2)
  GPIO.output(yellowLED,GPIO.HIGH)
  sleep(3)
  GPIO.output(yellowLED,GPIO.LOW)
time.sleep(2)

最后:GPIO.cleanup()

python mariadb rfid
1个回答
0
投票

您是否考虑过将登录/注销视为交换机?默认状态为sign-in设置为0或false,sign-out设置为1或true。然后,在读取卡后,它将检查登录值。如果为0 / false,则翻转为1 / true,然后进行相反的翻转以退出。当第二次读取卡时,它将读取注销,如果为0 / false,则将其设置为1 / true,并执行与登录相反的操作。

© www.soinside.com 2019 - 2024. All rights reserved.