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

record_url SDK example using T4T instead of T2T?

I have an existing mature product using the T4T NFC library.  I want to add another mode that is basically the record_url  SDK example, but that example is using T2T. The record_url  example is great is very clean and simple (very few lines).  The example is a Tag with only a NDEF URL that should trigger any phone to open that page.

It seems creating a similar application using T4T is much more complicated, can anyone provide a reference for how to do that?

Another option is to link both T2T and T4T libraries. There's a clean UI event that can be used to cleanly shutdown one mode and start the other so that part is OK, but I'm not sure if you can link both libraries, also this will needlessly use up  flash.

Can you link and use both libraries in the same App?

Parents
  • I  got it working. Posting simplified code below (but note I'm using SDK 14).


    // In sdk_config.h add this
        #define NFC_NDEF_URI_MSG_ENABLED 1
        #define NFC_NDEF_MSG_ENABLED     1
        #define NFC_NDEF_RECORD_ENABLED  1
        #define NFC_NDEF_URI_REC_ENABLED 1

        #define NFC_NDEF_MSG_TAG_TYPE   4U      //otherwise default is 2 and format will be wrong
    //////////////////////////////////////////////////

    // Type 4 URI URL tag
    static const uint8_t m_url[] = "foo.com";
    static uint8_t  m_buff[128];


    static void nfc_tag_callback(void          * context,
                             nfc_t4t_event_t event,
                             const uint8_t * data,
                             size_t dataLength,
                             uint32_t flags)
    {

        switch (event)
        {
            case NFC_T4T_EVENT_FIELD_ON:    //1
                break;

            case NFC_T4T_EVENT_FIELD_OFF:   //2
                break;

            case NFC_T4T_EVENT_NDEF_READ:   //3
                break;

            default:
                break;
        }
    }

    void startTag()
    {
        uint32_t err_code;


        nfc_t4t_setup(nfc_tag_callback, NULL);


        uint32_t size=sizeof(m_buff);
        err_code = nfc_uri_msg_encode(NFC_URI_HTTPS_WWW,
            m_url,
            sizeof(m_url)-1,
            m_buff,
            &size);

        /* note: m_buff must be persistent */
        err_code =
            nfc_t4t_ndef_staticpayload_set(m_buff,sizeof(m_buff));


        nfc_t4t_emulation_start();
    }

    void stopTag(void)
    {
        nfc_t4t_emulation_stop();
        nfc_t4t_done();

    }

Reply
  • I  got it working. Posting simplified code below (but note I'm using SDK 14).


    // In sdk_config.h add this
        #define NFC_NDEF_URI_MSG_ENABLED 1
        #define NFC_NDEF_MSG_ENABLED     1
        #define NFC_NDEF_RECORD_ENABLED  1
        #define NFC_NDEF_URI_REC_ENABLED 1

        #define NFC_NDEF_MSG_TAG_TYPE   4U      //otherwise default is 2 and format will be wrong
    //////////////////////////////////////////////////

    // Type 4 URI URL tag
    static const uint8_t m_url[] = "foo.com";
    static uint8_t  m_buff[128];


    static void nfc_tag_callback(void          * context,
                             nfc_t4t_event_t event,
                             const uint8_t * data,
                             size_t dataLength,
                             uint32_t flags)
    {

        switch (event)
        {
            case NFC_T4T_EVENT_FIELD_ON:    //1
                break;

            case NFC_T4T_EVENT_FIELD_OFF:   //2
                break;

            case NFC_T4T_EVENT_NDEF_READ:   //3
                break;

            default:
                break;
        }
    }

    void startTag()
    {
        uint32_t err_code;


        nfc_t4t_setup(nfc_tag_callback, NULL);


        uint32_t size=sizeof(m_buff);
        err_code = nfc_uri_msg_encode(NFC_URI_HTTPS_WWW,
            m_url,
            sizeof(m_url)-1,
            m_buff,
            &size);

        /* note: m_buff must be persistent */
        err_code =
            nfc_t4t_ndef_staticpayload_set(m_buff,sizeof(m_buff));


        nfc_t4t_emulation_start();
    }

    void stopTag(void)
    {
        nfc_t4t_emulation_stop();
        nfc_t4t_done();

    }

Children
No Data
Related