RUI3 (RAK Unified Interface 3) - RAK4631
Nfc

Functions

void init (bool wakeup, bool atMode, rak_nfc_t4t_callback callback)
 
void send (RAK_NFC_RECORD_TYPE record_type, const uint8_t *payload1, uint32_t size1, const uint8_t *payload2, uint32_t size2)
 
void close ()
 

Detailed Description

Function Documentation

◆ init()

void init ( bool  wakeup,
bool  atMode,
rak_nfc_t4t_callback  callback 
)
Description
The initialization of NFC
Syntax
api.nfc.init(wakeup, atMode, callback)
Parameters
wakeupThe bool is whether to use an interrupt to wake from sleep and passing a callback function with different states
atModewhether to use AT-Commnad over NFC(the tag will be changed to result of the command)
callbackthe callback funcation for nfc
Returns
void
Example
static void nfc_t4t_callback(void * p_context, RAK_NFC_T4T_EVENT event, const uint8_t * p_data, size_t data_length, uint32_t flags)
{
    (void)p_context;
}

void setup()
{
    static const uint8_t language[] = {'e', 'n'};
    static const uint8_t paylaod[] = {'H', 'e', 'l', 'l', 'o', ' ', 'N', 'F','C'}

    api.nfc.init(true, false, nfc_t4t_callback);
    api.nfc_send(TXT, language, sizeof(language), paylaod, sizeof(payload));
}

void loop()
{
    api.system.sleep.all(30000);
}

◆ send()

void send ( RAK_NFC_RECORD_TYPE  record_type,
const uint8_t *  payload1,
uint32_t  size1,
const uint8_t *  payload2,
uint32_t  size2 
)
Description
This api allows to send TXT,URI or APP message as a NFC tag
Note
There are three types of NFC message TXT, URI and APP. Ecah paramters of the types has diffenent meaning.
Please follow the Syntax to use this API.
Syntax
api.nfc.send(TXT, language, language_size, txt_payload, txt_size)
api.nfc.send(APP, ,android_package_name android_size, windows_application_id, windows_size)
api.nfc.send(URL, RAK_NFC_URI_ID, url_payload, url_size)
Parameters
typethe message is a TXT, URI or APP message
languagelanguage of TXT message (must be 2 bytes)
language_sizesize of language (must be 2)
payloadpaylaod of TXT message (1~244 bytes)
paylaod_sizesize of TXT message (1~244)
android_package_nameandroid package name
android_sizesize of android of android package name
windows_application_idwindows applicaiton id
windows_sizesize of windows application id
RAK_NFC_URI_IDEnum of URI ID
url_payloadurl of a URI message (1~246bytes)
url_sizesize of the url (1~246)
Returns
void
Example
static void nfc_t4t_callback(void * p_context, RAK_NFC_T4T_EVENT event, const uint8_t * p_data, size_t data_length, uint32_t flags)
{
    (void)p_context;
}

void setup()
{
    static const uint8_t language[] = {'e', 'n'};
    static const uint8_t paylaod[] = {'H', 'e', 'l', 'l', 'o', ' ', 'N', 'F','C'}

    api.nfc.init(true, false, nfc_t4t_callback);
    api.nfc_send(TXT, language, sizeof(language), paylaod, sizeof(payload));
}

void loop()
{
    api.system.sleep.all(30000);
}

◆ close()

void close ( )
Description
This api will disable nfc and any interrupts created for it
Syntax
api.nfc.close()
Returns
void
Example
static void nfc_t4t_callback(void * p_context, RAK_NFC_T4T_EVENT event, const uint8_t * p_data, size_t data_length, uint32_t flags)
{
    (void)p_context;
}

void setup()
{
    static const uint8_t language[] = {'e', 'n'};
    static const uint8_t paylaod[] = {'H', 'e', 'l', 'l', 'o', ' ', 'N', 'F','C'}

    api.nfc.init(true, false, nfc_t4t_callback);
    api.nfc_send(TXT, language, sizeof(language), paylaod, sizeof(payload));
}

void loop()
{
    if(millis() > 60000) 
        api.nfc.close();
    api.system.sleep.all(30000);
}