2

I have a PN532 connected via UART to a Raspberry Pi 3B. In a Python script (V3.7.4) I activate the reader and read in the data form a tag. If there is a NDEF message, I read the tag's data and return the NDEF records in a dictionary. All this is based on the nfcpy and ndeflib libraries.

The problem is, that checking the tag for a NDEF message doesn't seem to work properly. When emulating a tag with the Android App NFC Tools Pro, the NDEF message could be read. Using various other apps, the NDEF message could not be read. When I program a real tag or card with NFC tools Pro, the NDEF message can also not be found. Using the other apps or the tag with an USB NFC reader or scanning a tag with the phone, the NDEF data can be found and read.

So for some reason the result of if tag.ndef: does not always return true, even if it should return it.

from time import sleep

import nfc
import ndef
from nfc.clf import RemoteTarget

def parseNDEF():
    with nfc.ContactlessFrontend("tty:S0:pn532") as clf:
        while True:
            target = clf.sense(RemoteTarget("106A"), RemoteTarget("106B"), 
            RemoteTarget("212F"))
            print("Traget: "+str(target))

            if target is None:
                print("No target found ...")
                sleep(0.5)
                continue

            serial = target.sdd_res.hex()
            print("Found a target with serial " + serial + "!")

            tag = nfc.tag.activate(clf, target)
            print("tag data:\n" + str(tag.dump))

            nfcrecs = {}
            if tag.ndef:
                print("Tag is NDEF formatted!")
                print("It has " + str(len(tag.ndef.records)) + " records.")

                i=1;
                for record in tag.ndef.records:
                    print("Record: "+str(record))
                    nfcrecs["rec"+str(i)] = record.text
                    i+=1;

            else:
                print("No NDEF formatted tag.")

            if (len(nfcrecs)>0):
                return nfcrecs

This is the Result of reading the data from the Android App NFC tools Pro with the PN532 on the Pi: click here

I programmed a chip with the same data I've sent with the app. Programming was also done with NFC tools Pro. This is the result of reading the chip with NFC tools Pro: click here

This is the result when I read the above programmed chip with the PN532 on the Pi: click here

Any idea what's going wrong here?

Thanks in advance for any kind of help.

ab3d
  • 21
  • 3

0 Answers0