我用的是射频识别标签,我在标签上写了auth1。我想使用它作为身份验证标记。因此,如果扫描标记,并且标记的内容与变量auth1相同,则返回“授予访问权”。如果标记的内容与变量auth1不相同,则返回“拒绝访问”。
下面是我使用的代码:
#!/usr/bin/env python
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
auth0 = 'Access Denied'
auth1 = 'Access Granted'
try:
id, text = reader.read()
print(id)
if text == auth1:
print(auth1)
else:
return auth0
finally:
GPIO.cleanup()我使用了上面的代码,并尝试让它读取标记的内容(reader.read()),如果文本等于auth1打印auth1,否则返回auth0。但没起作用。
发布于 2022-11-08 11:36:00
您正在将标记上的文本与变量auth1进行比较,该变量的值为"Acces授予“。
auth1 = 'Access Granted'
if text == auth1:
-> if text == "Access Granted"因此,如果标签上有"auth1“,则应该将其与之进行比较。
if text == "auth1":https://stackoverflow.com/questions/74359972
复制相似问题