2024-02-07 23:22:45 +00:00
|
|
|
import time
|
|
|
|
import nfc
|
2024-02-16 20:16:05 +00:00
|
|
|
import subprocess
|
|
|
|
import requests
|
2024-04-12 20:01:57 +00:00
|
|
|
import oled
|
2024-04-17 17:46:43 +00:00
|
|
|
import subprocess
|
2024-02-16 20:16:05 +00:00
|
|
|
|
|
|
|
url="http://172.16.1.105/api/"
|
2024-02-07 23:22:45 +00:00
|
|
|
|
|
|
|
def get_reader():
|
|
|
|
devices = subprocess.check_output("lsusb")
|
|
|
|
for i in devices.split(b'\n'):
|
|
|
|
if str(i).__contains__("Advanced Card Systems, Ltd ACR122U"):
|
|
|
|
bus = str(i).split(":")[0].split(" Device ")[0].split("Bus ")[1]
|
|
|
|
device = str(i).split(":")[0].split("Device ")[1]
|
|
|
|
return("usb:{}:{}".format(bus, device))
|
|
|
|
raise Exception("\n\n Error: NFC reader not found")
|
|
|
|
|
|
|
|
def onTagSense(tag):
|
2024-02-16 20:16:05 +00:00
|
|
|
id = int.from_bytes(tag.identifier, "big")
|
|
|
|
response = requests.post(f"{url}tag_id", data={"id":id})
|
2024-04-17 18:01:14 +00:00
|
|
|
#try:
|
|
|
|
if response.json()["mode"] == "balance" or response.json()["mode"] == "message":
|
2024-04-17 18:03:10 +00:00
|
|
|
subprocess.run(oled.balance(response.json()["username"], responese.json()["balance"]))
|
2024-04-17 18:01:14 +00:00
|
|
|
return True
|
|
|
|
#except:
|
|
|
|
# None
|
2024-02-16 20:16:05 +00:00
|
|
|
return False
|
2024-02-07 23:22:45 +00:00
|
|
|
|
|
|
|
def start_nfc_normal():
|
2024-04-12 20:13:18 +00:00
|
|
|
device = get_reader()
|
2024-02-07 23:22:45 +00:00
|
|
|
clf = nfc.ContactlessFrontend(device)
|
|
|
|
clf.open(device)
|
|
|
|
while True:
|
|
|
|
clf.connect(rdwr={'on-connect': onTagSense, 'beep-on-connect': True })
|
2024-02-16 21:06:08 +00:00
|
|
|
time.sleep(0.75)
|
2024-02-21 23:10:29 +00:00
|
|
|
|
2024-02-07 23:22:45 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
start_nfc_normal()
|
|
|
|
|