Reading text payload (2 records)

Asked by ian@iwjohnston.com on 2016-12-21

Stephen,

Again this is my lack of understanding of nfc.ndef module. The data below is a tagtool show of a simple 2 text record NDEF card.

pi@raspberrypi:~/nfcpy/trunk/examples $ python tagtool.py show
[nfc.clf] searching for reader on path usb
[nfc.clf] using SONY RC-S380/P NFC Port-100 v1.11 at usb:001:005
** waiting for a tag **
Type3Tag 'FeliCa Lite-S (RC-S966)' ID=012E34E829CE1E71 PMM=00F1000000014300 SYS=88B4
[nfc.tag.tt3] got ndef attributes {'ver': 16, 'ln': 36, 'nbr': 4, 'nmaxb': 13, 'nbw': 1, 'rwflag': 0, 'writef': 0}
[nfc.tag.tt3] got 36 byte ndef data 9d000f02743149616e2057204a6f686e73746f6e0a5d00090274323132333435...
NDEF Capabilities:
  readable = yes
  writeable = no
  capacity = 208 byte
  message = 36 byte
NDEF Message:
record 1
  type = 'unknown'
  name = 't1'
  data = 'Ian W Johnston\n'
record 2
  type = 'unknown'
  name = 't2'
  data = '12345678\n'

What I want to do is simply parse the two text payload records to be payload text only. (not the NDEF flags etc). See my mangled code below which fails. BTW I do not want to use print.pretty() here at all.

#!/usr/bin/python2.7

import nfc.ndef
import time

while True:
    print "Awaiting Tag"
    with nfc.ContactlessFrontend('usb') as clf:
        def connected(tag): return False
        tag = clf.connect(rdwr={'on-connect':connected})
        if tag.ndef is not None:

            record1=tag.ndef.message[0]
            record2=tag.ndef.message[1]

            name=nfc.ndef.TextRecord(record1).text
            mob=nfc.ndef.TextRecord(record2).text

            print name
            print
            print mob

        else:
            print "Empty Record"

        time.sleep(10)

Thx in advance for any help,
Ian

Question information

Language:
English Edit question
Status:
Answered
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Last query:
2016-12-21
Last reply:
2016-12-22

I think the problem is that you do not have two text records on the tag but they are both type "unknown". NDEF Text records must have type "urn:nfc:wkt:T".

Can you help with this problem?

Provide an answer of your own, or ask ian@iwjohnston.com for more information if necessary.

To post a message you must log in.