LoginSignup
0
0

More than 1 year has passed since last update.

NFCpyでタグに書き込む

Posted at

hardware

setup

brew install libusb
pip3 install nfcpy

script

公式のものを改変

nfcwriter.py

import nfc
import sys

def on_connect(tag):
    global data 

    if tag.ndef is not None:
        for record in tag.ndef.records:
            print(record)
        if tag.ndef.is_writeable:
            from ndef import TextRecord
            tag.ndef.records = [TextRecord(data)]
            print("write complete")

def main():

    with nfc.ContactlessFrontend("usb") as clf:
        rdwr = {
            'on-connect': on_connect
        }
        clf.connect(rdwr=rdwr)


if __name__ == '__main__':
    global data 
    if len(sys.argv) > 1:
        data=sys.argv[1]
        print("Put NFC-Tag")
        main()
    else: 
        print("Need Record-Text")

実行

python3 nfcwriter.py helloworld

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0