This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NFC_T4T_EVENT_NDEF_READ event not working every time

Hello,

i am working on an app using Android to read and write an NDEF record using SDK 14 type 4 tag.

I start the process by reading the record with the following Android sequence:

Ndef ndef = Ndef.get(mTag);
ndef.connect();
NdefMessage ndefMessage = ndef.getNdefMessage();
ndef.close();

This produces an NFC_T4T_EVENT_NDEF_READ event on the Nordic side as expected.

After this, i write a record to the NRF52. The record is received. This produces an NFC_T4T_EVENT_NDEF_UPDATED event as expected.

After this, i update the record on the NRF52. Then i read the record with the exact same sequence as before. This time, no NFC_T4T_EVENT_NDEF_READ event is produced, even though my debugs in hal_nfc_t4t.c clearly show, that the record is read and sent properly to the Android device.

Is this some known feature or bug? It seems that only one NFC_T4T_EVENT_NDEF_READ event is produced per session when using Android Ndef library. After the NRF52 NFC interface has been reset, i can get one event. The record read works just fine, and the Android SW receives the correct data. Only the event is missing, which i need for my control flow.

Has anyone else encountered this problem, and found a solution or at least a workaround?

BR, tommi

  • The event seems to be not related to the NDEF read, as the event is produced whenever i just put the NRF52 to the Android device NFC field.

    The comment for the event states:

    /**<
         * A Read operation happened on last byte of NDEF-Data.
         */
    

    which i naively assumed as "last byte of NDEF record", i.e. an event would be produced every time the NDEF message is read from the NRF52. Instead it seems that the event is produced when reading e.g. the capability container or such. I am having little luck trying to get the Android app to do whatever it does to produce the event programmatically, i.e. writing a line of code that would do the trick.

    Could someone from Nordic comment on how the event is produced, as it is a part of a static library to which i have no access. The comment is vague and clearly can be misinterpreted.

  • Well, you are right that the NFC_T4T_EVENT_NDEF_READ event is produced only once per session when the last byte of NDEF message is read (the tag needs to reenter the NFC field to start the new session). We will try to improve the documentation in the next releases, because it seems to be not clear enough.

  • Thank you for your answer. This makes it clear that the event is not intended to work as the NFC_T4T_EVENT_NDEF_UPDATED event, which is produced every time the contents of a record is updated.

    Do you have any intention of making an event, that is produced when the record contents have been read, in future SDK releases? It would be helpful to know when the remote has updated the message, and i don't think it would be too hard to implement.

    I will proceed by trying to make a workaround on the smartphone for now.

    BR, tommi

  • Also, i am kind of curious what is meant by " last byte of NDEF message", if not the last byte that Ndef.getMessage() -function in Android SDK reads?

  • I am not that familiar with Android SDK, but this is probably the last byte that Ndef.getMessage() reads.

    You can take a look at the writable_ndef_msg example and its default NDEF message generation (copypasted code block):

    uint32_t size = sizeof(m_ndef_msg_buf);
    err_code = ndef_file_default_message(m_ndef_msg_buf, &size);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("The last byte of NDEF message: 0x%02X", m_ndef_msg_buf[size-1]);
    

    I added the last line to clarify what is the last byte from the nordic NFC library perspective (so you can compare with Android output). Of course, the different NDEF message may change the position of the last byte.

Related