0

How can I send an NDEF message from phone to MIFARE card reader?

On the reader side I use this code from https://github.com/AlterCodex/nxppy:

import nxppy
import ndef

# Instantiate reader
mifare = nxppy.Mifare()

# Select tag
uid = mifare.select()

# Read NDEF data
ndef_data = mifare.read_ndef()

# Parse NDEF data
ndef_records = list(ndef.message_decoder(ndef_data))

When I try to send an NDEF message with this code I get memory error:

    public NdefMessage CreateNdefMessage(NfcEvent e)
    {
        NdefRecord uriRecord = NdefRecord.CreateUri("http://myURL");
        NdefMessage message = new NdefMessage(new[] { uriRecord });
        return message;
    }

For this code I am getting error: ndef_data = milfare.read_ndef() MemoryError.

How can I edit this solution to make it work? I just want to read a simple NDEF message from Android application with nfc-explorer board but I am completly confused how to do this.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
user3302358
  • 76
  • 2
  • 10

1 Answers1

1

The mifare.read_ndef() seems to expect a MIFARE Ultralight (or other Type 2 tag) containing an NDEF message. You simply can't emulate a MIFARE (Ultralight) tag with Android (see Emulate Mifare card with Android 4.4).

What you do on Android, when you use public NdefMessage CreateNdefMessage(NfcEvent e) {} (or actually SetNdefPushMessage*()), is that you define an NDEF message that should be transfered in peer-to-peer mode (using SNEP + LLCP + NFC-DEP). That's a completely different protocol stack than when you read (or emulate) a tag. Consequently, when you want to use peer-to-peer mode on Android, you will need to use a library that supports peer-to-peer mode (and SNEP) on the other end as well.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • Ok, so if I want to use this android application I need to change a library. With this android code can I perform a SNEP put operation? Is there any example of a code that I could use? – user3302358 Jan 22 '19 at 09:33
  • Hi, can you tell me what steps should I take to create this solution? On the reader side, I have implemented the solution from NXP Semiconductors. You once gave a link to walkthrough: https://github.com/hirokuma/AndroidHceSample I implement this but the reader can't reach my ndef message – user3302358 Jan 22 '19 at 14:42