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

Change NFC ndef values in software

Hi,

I'm trying to edit the nfc message in software but after a while the nfc stops working.

What could I be doing wrong? This is my code, I change the value every second and update the ndef file.

#include <stdint.h>
#include <stdbool.h>
#include "app_error.h"
#include "app_scheduler.h"
#include "boards.h"
#include "nfc_t4t_lib.h"
#include "ndef_file_m.h"
#include "nfc_ndef_msg.h"
#include "nrf_delay.h"

#define APP_SCHED_MAX_EVENT_SIZE 0
#define APP_SCHED_QUEUE_SIZE     4

static uint8_t m_ndef_msg_buf[NDEF_FILE_SIZE];
static uint8_t m_ndef_msg_len;

static void scheduler_ndef_file_update(void * p_event_data, uint16_t event_size)
{
    ret_code_t err_code;

    UNUSED_PARAMETER(p_event_data);
    UNUSED_PARAMETER(event_size);

    err_code = ndef_file_update(m_ndef_msg_buf, m_ndef_msg_len + NLEN_FIELD_SIZE);
    APP_ERROR_CHECK(err_code);
}

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

    switch (event)
    {
        case NFC_T4T_EVENT_FIELD_ON:
            break;

        case NFC_T4T_EVENT_FIELD_OFF:
            break;

        case NFC_T4T_EVENT_NDEF_READ:
            break;

        case NFC_T4T_EVENT_NDEF_UPDATED:
            if (dataLength > 0)
            {
                ret_code_t err_code;

                // Schedule update of NDEF message in the flash file.
                m_ndef_msg_len = dataLength;
                err_code = app_sched_event_put(NULL, 0, scheduler_ndef_file_update);
                APP_ERROR_CHECK(err_code);
            }
            break;

        default:
            break;
    }
}

int main(void)
{
    ret_code_t err_code;

    APP_SCHED_INIT(APP_SCHED_MAX_EVENT_SIZE, APP_SCHED_QUEUE_SIZE);

    err_code = ndef_file_setup();
    APP_ERROR_CHECK(err_code);

    err_code = ndef_file_load(m_ndef_msg_buf, sizeof(m_ndef_msg_buf));
    APP_ERROR_CHECK(err_code);

    err_code = nfc_t4t_setup(nfc_callback, NULL);
    APP_ERROR_CHECK(err_code);

    err_code = nfc_t4t_ndef_rwpayload_set(m_ndef_msg_buf, sizeof(m_ndef_msg_buf));
    APP_ERROR_CHECK(err_code);

    err_code = nfc_t4t_emulation_start();
    APP_ERROR_CHECK(err_code);

    while (1)
    {
        app_sched_execute();
			
				nrf_delay_ms(1000);
			
				m_ndef_msg_buf[11] = 0x31;
			
				//update message
				err_code = app_sched_event_put(NULL, 0, scheduler_ndef_file_update);
        APP_ERROR_CHECK(err_code);
    }
}

Thanks!

Marvin

Parents Reply Children
No Data
Related