Skip to content

Instantly share code, notes, and snippets.

@henrycjc
Last active November 2, 2017 22:58
Show Gist options
  • Save henrycjc/c1632b2d1f210ae0ff33d860c7c2eb8f to your computer and use it in GitHub Desktop.
Save henrycjc/c1632b2d1f210ae0ff33d860c7c2eb8f to your computer and use it in GitHub Desktop.
NFC bulk encoder script
import nfc
import ndef
tags = set()
rec = ndef.UriRecord("https://google.com")
def on_connect(tag):
if tag.identifier not in tags:
tags.add(tag.identifier)
fmt = tag.format()
if fmt is None:
print("Tag cannot be formatted (not supported).")
elif fmt is False:
print("Tag failed to be formatted (for some reason).")
else:
tag.ndef.records = [rec]
if __name__ == "__main__":
clf = nfc.ContactlessFrontend()
if not clf.open('usb'):
raise RuntimeError("Failed to open NFC device.")
while True:
config = {
'interval': 0.35,
'on-connect': on_connect
}
ret = clf.connect(rdwr=config)
if ret is None:
pass
elif not ret:
print ("NFC connection terminated due to an exception.")
break
else:
pass
clf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment