Tag.is_present on Type2 not working (works on Type4)

Asked by Rune Espensen on 2017-04-13

Hi,

I am a newbie on NFC, so sorry if this is obvious - I've tried searching this forum for an answer, but only came close with a similar issue on Type4 cards, which is working for me just fine.

So, I have a need to register when a card is present and when it leaves again. I have some Type2 tags for this.

Given this code:

def connected(tag):
    print(tag)
    return True
def released(tag):
    print("Bye")

tag = clf.connect(rdwr={'on-connect': connected, 'on-release': released})

I would expect it to echo out the Tag ID when I present it to the reader, and the echo "Bye" once I remove it. This works as expected on a Type4 tag I have..
Output (Put tag on and keep it)
>Type4BTag MIU=255 FWT=0.154657
Output (When tag is removed)
>Bye

But on the Type2's it simply fires bothcallbacks in an endless loop, as if it "looses connection" to the tag right away - I am guessing it is Tag.is_present not working properly (hence the headline).
Output (Put tag on and keep it there):
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
Type2Tag ID=4A17ABDD
Bye
..... This continues until I remove the tag from the reader.:

I have tried to format the Type2 tag (as that is apparently required for Type4 tags at least - but I am not allowed to).

The hardware I am using is a Raspberry Pi 3, with the Adafruit NFC Breakout board (PN532)

Any suggestions?

Question information

Language:
English Edit question
Status:
Answered
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Last query:
2017-04-13
Last reply:
2017-04-18

Can you check if this is a Mifare Classic, usually reads Mifare 1K or 4K.

Rune Espensen <email address hidden> schrieb am Do., 13.
Apr. 2017, 18:28:

> New question #617298 on nfcpy:
> https://answers.launchpad.net/nfcpy/+question/617298
>
> Hi,
>
>
> I am a newbie on NFC, so sorry if this is obvious - I've tried searching
> this forum for an answer, but only came close with a similar issue on Type4
> cards, which is working for me just fine.
>
> So, I have a need to register when a card is present and when it leaves
> again. I have some Type2 tags for this.
>
> Given this code:
>
> def connected(tag):
> print(tag)
> return True
> def released(tag):
> print("Bye")
>
>
> tag = clf.connect(rdwr={'on-connect': connected, 'on-release': released})
>
>
>
> I would expect it to echo out the Tag ID when I present it to the reader,
> and the echo "Bye" once I remove it. This works as expected on a Type4 tag
> I have..
> Output (Put tag on and keep it)
> >Type4BTag MIU=255 FWT=0.154657
> Output (When tag is removed)
> >Bye
>
>
> But on the Type2's it simply fires bothcallbacks in an endless loop, as
> if it "looses connection" to the tag right away - I am guessing it is
> Tag.is_present not working properly (hence the headline).
> Output (Put tag on and keep it there):
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> Type2Tag ID=4A17ABDD
> Bye
> ..... This continues until I remove the tag from the reader.:
>
>
> I have tried to format the Type2 tag (as that is apparently required for
> Type4 tags at least - but I am not allowed to).
>
> The hardware I am using is a Raspberry Pi 3, with the Adafruit NFC
> Breakout board (PN532)
>
> Any suggestions?
>
> --
> You received this question notification because you are an answer
> contact for nfcpy.
>

Rune Espensen (runee) said : #2

Hi Stephen,

Thank you for taking the time to answer :-)

So, the NFC tags I am using are all blank whites, with no writing on them - however, I see same results with both the demo card that follows with the board, (https://www.adafruit.com/product/364 - labelled as a "13.56MHz 1K card") as well as the tags I really need for the project (https://www.adafruit.com/product/360 - which is also listed as a 1k)

I experimented a bit more, looking in the source, the is_present is simply trying to a transcieve operation - if that times out, card is not present.
When I try to do this myself, I also simply end up with a timeout. I tried some more operations, like reading and writing records and select sectors, and everything ends up in error. So basically, I can read the Tag UID and do nothing else it seems. Are these tags simply un-supported? (I hope not, I bought 50 of them ;-) )

I'm afraid those cards are Mifare Classic 1K not supported by nfcpy. It is
possible to read the UID but any other command requires to first
authenticate and use the Mifare Crypto scheme. This should be doable with
NXP reader ICs but I do not have any plan for it. And NXP has a good
selection of NFC Forum compatible Type 2 Tags that work just great - I
don't know why Adafruit is still bundling a Mifare Classic card.

Rune Espensen <email address hidden> schrieb am Sa., 15.
Apr. 2017, 16:58:

> Question #617298 on nfcpy changed:
> https://answers.launchpad.net/nfcpy/+question/617298
>
> Rune Espensen posted a new comment:
> Hi Stephen,
>
>
> Thank you for taking the time to answer :-)
>
> So, the NFC tags I am using are all blank whites, with no writing on
> them - however, I see same results with both the demo card that follows
> with the board, (https://www.adafruit.com/product/364 - labelled as a
> "13.56MHz 1K card") as well as the tags I really need for the project
> (https://www.adafruit.com/product/360 - which is also listed as a 1k)
>
> I experimented a bit more, looking in the source, the is_present is simply
> trying to a transcieve operation - if that times out, card is not present.
> When I try to do this myself, I also simply end up with a timeout. I tried
> some more operations, like reading and writing records and select sectors,
> and everything ends up in error. So basically, I can read the Tag UID and
> do nothing else it seems. Are these tags simply un-supported? (I hope not,
> I bought 50 of them ;-) )
>
> --
> You received this question notification because you are an answer
> contact for nfcpy.
>

Rune Espensen (runee) said : #4

Oh Bollocks - That was not the answer I was hoping for :-D

One question, before I start to look for other tags - since you say that "any other command....." I was wondering. I have absolutely no need to use other commands, write data or anything. My ONLY need is to register the UID once it enters and register when it leaves again - and since the first part is supported (Register the UID) would it make sense to try and rewrite the _is_present to rely on that, to determine whether a card is present? I have no idea where to start on that, but if you think that would be feasible, I think it would be faster and cheaper for me, to look into that instead of buying new tags.

If you are just interested in UID and presence then try with clf.sense - as
used in example/sense.py. Once a tag is found you'd use further sense calls
to check for presence. With the target returned by sense given as argument
back to the next sense, it will find only the target with the same UID.

Rune Espensen <email address hidden> schrieb am Di., 18.
Apr. 2017, 13:14:

> Question #617298 on nfcpy changed:
> https://answers.launchpad.net/nfcpy/+question/617298
>
> Rune Espensen posted a new comment:
> Oh Bollocks - That was not the answer I was hoping for :-D
>
> One question, before I start to look for other tags - since you say that
> "any other command....." I was wondering. I have absolutely no need to
> use other commands, write data or anything. My ONLY need is to register
> the UID once it enters and register when it leaves again - and since the
> first part is supported (Register the UID) would it make sense to try
> and rewrite the _is_present to rely on that, to determine whether a card
> is present? I have no idea where to start on that, but if you think that
> would be feasible, I think it would be faster and cheaper for me, to
> look into that instead of buying new tags.
>
> --
> You received this question notification because you are an answer
> contact for nfcpy.
>

Rune Espensen (runee) said : #6

Hi,

Thanks - will try to play with that later today - initial tests shows that clf.sense just returns None no matter which tag I use (Including the Type4) - same goes for the example sense.py. I guess I am doing something blatantly wrong on this ;-)

Can you help with this problem?

Provide an answer of your own, or ask Rune Espensen for more information if necessary.

To post a message you must log in.