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

Read NDEF after tag write

Hi,

I am having trouble reading the contents of a record after the NFC tag in the microcontroller has been written by a smartphone.

I'm using the t4t emulator. When the tag has been written the callback gets called. In the callback I use the ndef_record_parser() to parse the data, and I use the ndef_record_printout() to print the payload.

The problem is that the payload contains unreadable data. It does not contain the text that has been written to the tag.

What is the correct way of reading the contents that are written to the tag?

Thanks, Jan

Parents
  • FormerMember
    0 FormerMember

    I don't know what your code looks like, so I will just tell how it works.

    When writing to the NFC tag from another device, the initial data will be over written, and stored in the set buffer in nfc_t4t_ndef_rwpayload_set() during the initialization. In the example writable_ndef_msg, the buffer is m_ndef_msg_buf.

    Since m_ndef_msg_buf is overwritten upon a write, that is where the data to be parsed is located. (Note: the data field in the event "NFC_T4T_EVENT_NDEF_UPDATED" doesn't contain valid data. The only valid data for that event is dataLength.)

    For a Tag Type 4, the written data can be printed out the following way:

    /**
    * @brief Callback function for handling NFC events.
    */
    static void nfc_callback(void          * context,
                         nfc_t4t_event_t event,
                         const uint8_t * data,
                         size_t          dataLength,
                         uint32_t        flags)
    {
        (void)context;
    	ret_code_t ret_val;
    
        uint8_t  read_nfc_buffer[NFC_NDEF_PARSER_REQIRED_MEMO_SIZE_CALC(10)];
        uint32_t read_nfc_buffer_length = sizeof(read_nfc_buffer);		
    
        switch (event)
        {
            ....
    
            case NFC_T4T_EVENT_NDEF_UPDATED:
    				
    			NRF_LOG_INFO("NFC_T4T_EVENT_NDEF_UPDATED \r\n");
    		
                if (dataLength == 0)
                {
                    m_update_state = true;
    	            NRF_LOG_INFO("DataLength:  0 \r\n");
                }
                else if (m_update_state == true)
                {
    	            ret_val = ndef_msg_parser(read_nfc_buffer, &read_nfc_buffer_length, m_ndef_msg_buf+2, &dataLength);
    		        //APP_ERROR_CHECK(ret_val);
    			    if (ret_val != NRF_SUCCESS)
    			    {
    			        NRF_LOG_INFO("Error code: 0x%x \r\n", ret_val);
    				    NRF_LOG_INFO("Error during parsing a NDEF message.\r\n");
    			    }
    			
    			    ndef_msg_printout((nfc_ndef_msg_desc_t *) read_nfc_buffer);
                    m_update_state = false;
                    bsp_board_led_on(BSP_BOARD_LED_1);
                }
                break;
    
        default:
            break;
        }
    }
    
Reply Children
No Data
Related