40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import time
|
|
import nfc
|
|
import subprocess
|
|
import requests
|
|
import oled
|
|
import subprocess
|
|
|
|
url="http://172.16.1.105/api/"
|
|
|
|
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):
|
|
id = int.from_bytes(tag.identifier, "big")
|
|
response = requests.post(f"{url}tag_id", data={"id":id})
|
|
#try:
|
|
if response.json()["mode"] == "balance" or response.json()["mode"] == "message":
|
|
subprocess.run(oled.balance(response.json()["username"], response.json()["balance"]))
|
|
return True
|
|
#except:
|
|
# None
|
|
return False
|
|
|
|
def start_nfc_normal():
|
|
device = get_reader()
|
|
clf = nfc.ContactlessFrontend(device)
|
|
clf.open(device)
|
|
while True:
|
|
clf.connect(rdwr={'on-connect': onTagSense, 'beep-on-connect': True })
|
|
time.sleep(0.75)
|
|
|
|
if __name__ == "__main__":
|
|
start_nfc_normal()
|
|
|