Open mhaberler opened 9 months ago
actually the problem is more trivial: the Adafruit_PN532 library is plain wrong with respect to the maximum size of the reply buffer - when I increase this value to 255 the Ruuvi reading just works:
#define PN532_PACKBUFFSIZ 64
record 0: type 1 typelen 1 idlen 0 payloadlen 30
record 1: type 1 typelen 1 idlen 0 payloadlen 25
record 2: type 1 typelen 1 idlen 0 payloadlen 31
record 3: type 1 typelen 1 idlen 0 payloadlen 27
4
UID: 5F 3E 20 3F 0E AE 5E
This NFC Tag contains an NDEF Message with 4 NDEF Records.
NDEF Record 1
TNF: 1
Type: TxV����?,
Payload (HEX): 02 69 64 49 44 3A 20 43 35 3A 35 41 3A 42 34 3A 46 43 3A 35 32 3A 35 43 3A 46 34 3A 42 32 .idID: C5:5A:B4:FC:52:5C:F4:B2
Payload (as String): idID: C5:5A:B4:FC:52:5C:F4:B2
NDEF Record 2
TNF: 1
Type: TxV����?(
Payload (HEX): 02 61 64 4D 41 43 3A 20 43 32 3A 36 45 3A 44 31 3A 37 30 3A 32 42 3A 34 34 .adMAC: C2:6E:D1:70:2B:44
Payload (as String): adMAC: C2:6E:D1:70:2B:44
NDEF Record 3
TNF: 1
Type: TxV����?,
Payload (HEX): 02 73 77 53 57 3A 20 52 75 75 76 69 20 46 57 20 76 33 2E 33 31 2E 31 2B 64 65 66 61 75 6C 74 .swSW: Ruuvi FW v3.31.1+default
Payload (as String): swSW: Ruuvi FW v3.31.1+default
NDEF Record 4
TNF: 1
Type: TxV����?(
Payload (HEX): 02 64 74 05 11 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 .dt...���������������������
Payload (as String): dt���������������������
this seems to be a mixup between FIFO size (64) and the maximum extended frame size (262) as clarified in the accepted answer.
so this needs a patch of Adafruit_PN532 library unfortunately the strange "optimizations" taken there (uint8_t for what should be a size_t) come to roost
anyway will try to patch this up and post a PR
the previous fix covers only my specific case where the NDEF message length is > 64 but < 255
given that NDEF messages can be arbitrary size (subject to card limits) a chunked read ontop of inDataExchange() is still needed for a more general solution
I'm trying to read a RuuviTag to fetch configuration (ie MAC address)
the tag is recognized, but the code crashes in
NfcTag NTAGType4::read()
while parsing the NDEF content. The crash happens during the third record, when trying to parse unread content.The reason is that the
isoReadNTAGType4NdefFile
method assumes the NDEF message can be read in one go by oneinDataExchange()
callhowever
inDataExchange()
is limited to below 64 bytes (60 or so) actual return buffer size is limited to 64 bytes including overhead, see thepn532_packetbuffer
definitionI see two ways of dealing with the issue:
isoReadNTAGType4NdefFile
loop over 60byte chunks until the whole file is readnfc-tools implemented extended frames
with Adafruit-PN532, there has been an attempt io address the issue: https://github.com/adafruit/Adafruit-PN532/issues/38 but that never was merged
so for a start the chunked read variant looks easier to do while at it, it might make sense to factor out a generic file reading method (file id->(buffer, length)
this is what NXP Tag Info has to say about it: