2022-04-26 01:54 PM
Hi
I am trying to create an application using arduino which will read 4 NDEF text messages where will be stored data needed to establish Wi-Fi connection (host, ssid, password, token).
I did try to run example from stduion ST25 library and thats work fine but only for URL NDEF.
Do you have any working example to show how to read (not need to write) 4 different text NDEF and use those data as I described above?
I would be very gratefull for any help.
thank you!
Solved! Go to Solution.
2022-06-08 09:05 AM
Hi @Community member,
If by updating this value, this allow you to obtain only 2 bytes more, it means for me that you have not enough memory available in your system. You can have some information with the compiler to know more about memory space used by your code.
Another thing to check, that could result in a limitation of bytes to read, is if your i2c read function is limited by a timeout. A read of 42 bytes can spent around 1ms for a speed set to 400kbit/s on I2C.
Hope this can help you.
Kind Regards.
2022-04-26 11:55 PM
Hi RMako.2,
I assume you will want to prepare a Wifi pairing message. It is one of the types defined by NFC Forum. You can find an implementation inside ST25 NFC Lib. Inside you can find Middlewares/ST/NDEF with ndef_type_wifi.c,h.
Implementations for using it can be found in the various demos, especially the ndef_rw and the bluetooth_pairing for the ST25R3916.
To my knowledge this has not been ported on stm32duino but you may want to check on their forum. Anyhow I would not expect any problems using the NDEF middleware on stm32duino.
Best Regards, Ulysses
2022-04-27 03:13 PM
Hi
thank you for anwser
I went frough demos which you mention but unfortuanately in ndef_rw did not find wifi example
below is my code for wifi and URL - URL is working fine but wifi is ending by foult
int ST25DV::readWIFI(String *s)
{
uint16_t ret;
sWifiTokenInfo wifi;
sRecordInfo_t recordInfo;
ret = NDEF_ReadNDEF(NDEF_Buffer);
if (ret) {
return ret;
}
ret = NDEF_IdentifyBuffer(&recordInfo, NDEF_Buffer);
if (ret) {
return ret;
}
ret = NDEF_ReadWifiToken(&recordInfo, &wifi);
if (ret) {
return ret;
}
*s = String(wifi.NetworkKey) + String(wifi.NetworkSSID);
return 0;
}
int ST25DV::readURI(String *s)
{
uint16_t ret;
sURI_Info uri = {"", "", ""};
sRecordInfo_t recordInfo;
ret = NDEF_ReadNDEF(NDEF_Buffer);
if (ret) {
return ret;
}
ret = NDEF_IdentifyBuffer(&recordInfo, NDEF_Buffer);
if (ret) {
return ret;
}
ret = NDEF_ReadURI(&recordInfo, &uri);
if (ret) {
return ret;
}
*s = String(uri.protocol) + String(uri.URI_Message);
return 0;
}
could you tell me what I am doing wrong?
thank you, Robert
2022-04-28 01:22 AM
Hi Robert,
please describe a bit more what you are doing (e.g. which tag with which content) and also what exactly you mean by "wifi is ending by foult".
BR, Ulrich
2022-04-28 01:50 AM
Hi RMako.2,
The Wifi type defined by the NFC Forum is available in Middlewares/ST/NDEF, see ndef_type_wifi.h and ndef_type_wifi.c. The ST25 NFC Lib provides a bluetooth_pairing demo for ST25R3916 (in the folder X-NUCLEO-NFC06A1), that can be used as a starting point to implement Wifi pairing.
Replace the function demoEncodeBluetoothRecord() with demoEncodeWifiRecord(), as shown in this example:
ReturnCode demoEncodeWifiRecord(uint8_t *buffer, uint32_t length)
{
ndefRecord record;
ndefType ndefWifi;
ReturnCode err;
if (buffer == NULL)
{
return ERR_PARAM;
}
uint8_t ssid[] = { 0x01, 0x02, 0x03, 0x04 };
ndefConstBuffer bufNetworkSSID = { ssid, sizeof(ssid) };
uint8_t key[] = { 0x05, 0x06, 0x07, 0x08 };
ndefConstBuffer bufNetworkKey = { key, sizeof(key) };
ndefTypeWifi wifiConfig = {
.bufNetworkSSID = bufNetworkSSID,
.bufNetworkKey = bufNetworkKey,
.authentication = NDEF_WIFI_AUTHENTICATION_WPAPSK,
.encryption = NDEF_WIFI_ENCRYPTION_TKIP
};
err = ndefWifiInit(&ndefWifi, &wifiConfig);
if (err != ERR_NONE)
{
return err;
}
err = ndefTypeToRecord(&ndefWifi, &record);
if (err != ERR_NONE)
{
return err;
}
err = ndefRecordDump(&record, true);
if (err != ERR_NONE)
{
return err;
}
/* Encode the record starting after the first two bytes that are saved
to store the NDEF file length */
ndefBuffer bufRecord = { &buffer[2], length - 2 };
err = ndefRecordEncode(&record, &bufRecord);
if (err != ERR_NONE)
{
return err;
}
/* Store the NDEF file length on the two first bytes */
buffer[0] = bufRecord.length >> 8;
buffer[1] = bufRecord.length & 0xFF;
return err;
}
Pay attention to turn on Wifi support in ndef_config_custom.h:
#define NDEF_TYPE_WIFI_SUPPORT true
This will create a Wifi pairing record.
I hope it will help, please let me know if you face any issue.
Best regards,
Jasper
2022-05-08 02:15 PM
Hello
Thank you for all your support.
I have suceed to read and wright wifi, text and URL NDEF but problem is that I can read only one of them
Program is working fine if I have got only one NDEF in memory for example wifi - then readung is ok, but if I have got 3 (each different type) program is crash and do not read anything.
Can you suggest what is wrong?
In this situation cannot read - I need to read all of them
When there is only one NDF - can read without any problem
sRecordInfo_t record;
NDEF_ReadNDEF(NDEF_Buffer);
NDEF_IdentifyBuffer(&record, NDEF_Buffer);
NDEF_ParseSP(&record *pRecordStruct);
// READ TEXT NDEF
NDEF_Text_info_t Text;
NDEF_ReadText( &record, &Text );
text_read = String(Text.text);
// READ URL NDEF
sURI_Info uri = {"", "", ""};
NDEF_ReadURI(&record, &uri);
uri_read = String(uri.protocol) + String(uri.URI_Message);
// READ WIFI NDEF
sWifiTokenInfo wps;
NDEF_ReadWifiToken(&record, &wps);
wifi_read_ssid = String(wps.NetworkSSID);
wifi_read_pass = String(wps.NetworkKey);
2022-05-10 05:57 AM
Hi,
can you share more details about your HW setup:
Thanks in advance
Rgds
BT
2022-05-12 01:06 AM
Hi @Community member,
If i understand well, you are using package from arduino mbed which is using older NDEF library than the one available in ST25 NFC Lib (I think that this last one is not available for arduino mbed).
I've listed some points that may fix some issues you encounter.
Here is an example that might help you:
sRecordInfo_t record[3];
uint32_t recordlength;
uint8_t *pNDEFtmp;
NDEF_ReadNDEF(NDEF_Buffer);
pNDEFtmp = NDEF_Buffer;
NDEF_IdentifyBuffer(&record[0], pNDEFtmp);
recordlength = NDEF_GetRecordLength( &record[0] );
pNDEFtmp += recordlength;
NDEF_IdentifyBuffer(&record[1], pNDEFtmp);
recordlength = NDEF_GetRecordLength( &record[1] );
pNDEFtmp += recordlength;
NDEF_IdentifyBuffer(&record[2], pNDEFtmp);
// READ WIFI NDEF
sWifiTokenInfo wps;
NDEF_ReadWifiToken(&record[0], &wps);
wifi_read_ssid = String(wps.NetworkSSID);
wifi_read_pass = String(wps.NetworkKey);
// READ URL NDEF
sURI_Info uri = {"", "", ""};
NDEF_ReadURI(&record[1], &uri);
uri_read = String(uri.protocol) + String(uri.URI_Message);
// READ TEXT NDEF
NDEF_Text_info_t Text;
NDEF_ReadText( &record[2], &Text );
text_read = String(Text.text);
Hope this will help you.
Kind Regards.
2022-05-21 02:55 PM
thank you that helps a lot, but stil it do not work as I want.
All is ok when I have got shor maeeage as below
but if I add a longger message data are not read correctly
I tried to manipulate with NDEFBuffer size and with calculation of buffer size but I stucked
Can you suggest something (Arduino has not debbug capability so it is hard to find what is wrong...)
thank you
2022-05-23 12:52 AM
Hi @Community member,
I'm not sure to understand well what you are trying to do. Could you give us more details about the step you are doing?
Is the message you are editing an NDEF Wifi or an NDEF Text?
And what tools do you use for that?
Could you give us the raw Tag memory contents to see what you are trying to decode?
kind regards.