cancel
Showing results for 
Search instead for 
Did you mean: 

temperature sensor NDEF

Schuyler
Senior

I have programmed the temperature sensor, but it seems that it has not been successful, the NDEF reading result is shown in the figure, what should I do?

if( NfcType5_NDEFDetection( ) != NDEF_OK )

 {

  CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;

  CCFileStruct.Version = NFCT5_VERSION_V1_0;

  CCFileStruct.MemorySize = ( ST25DVXXKC_MAX_SIZE / 8 ) & 0xFF;

  CCFileStruct.TT5Tag = 0x05;

  /* Init of the Type Tag 5 component (M24LR) */

  while( NfcType5_TT5Init( ) != NFCTAG_OK );

 }

 /* Init done */

 NFC07A1_LED_Off( GREEN_LED );

 HAL_Delay( 300 );

 NFC07A1_LED_Off( BLUE_LED );

 HAL_Delay( 300 );

 NFC07A1_LED_Off( YELLOW_LED );

 HAL_Delay( 300 );

 /* write text message to EEPROM */

 K_Temperature= MAX6675_ReadTemperature(); //读�?�热电�?�温度值

 HAL_Delay(1000);

 // 将浮点数转�?�为字符串

 char temp_str[20];

 sprintf(temp_str, "%f", K_Temperature);

 // 将字符串转�?�为无符�?�8�?整数数组

 uint8_t temp_data[strlen(temp_str)];

 memcpy(temp_data, temp_str, strlen(temp_str));

 // 写入NDEF消�?�

 NDEF_WriteNDEF(strlen(temp_str), temp_data);

  //读�?�NDEF消�?�

  NDEF_ReadNDEF(temp_data);

 /* Set the LED3 on to indicate Programing done */

 NFC07A1_LED_On( YELLOW_LED );

}


_legacyfs_online_stmicro_images_0693W00000bidNeQAI.png

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

as already explained in a previous post:

when the NDEF TEXT message is properly formatted, Android displays the text (i.e. decodes the NDEF and extracts the payload). If using the ST25 NFC Tap app, the NDEF tab display "Text record"; the content of the record is displayed when pressing on the "Text record" field.

This is the way you should check.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

13 REPLIES 13
Brian TIDAL
ST Employee

Hi

I see several issues in your code:

  1. the input parameter of NDEF_WriteNDEF is supposed to be a formatted NDEF buffer whereas temp_data is not a NDEF buffer. If you want to write a TEXT record, make sure to use the NDEF_WriteText API.
  2. obviously MAX6675_ReadTemperature returns 0. You should debug this API
  3. memcpy(temp_data, temp_str, strlen(temp_str)) seems to be useless. Why don't using temp_str direclty?

I would also remind that this community has ground rules so please make sure to avoid to duplicate your posts.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,@Brian TIDAL_O​ 

I understand your mean, but the NDEF_WriteText function can only implement text repetition. I need to read the temperature data instead of the text,so I use NDEF_WriteNDEF and NDEF_ReadNDEF. Please give me some concrete suggestions.

Brian TIDAL
ST Employee

Hi

since you have converted the float temperature value to a string (see  sprintf(temp_str, "%f", K_Temperature); in your code), what you have to write to the tag is a text. Therefore, NDEF_WriteNDEF is not the proper API except if you want to format the record by yourself. So, I would again suggest to use NDEF_WriteText API.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,@Brian TIDAL_O​ 

I am a beginner,so can you give me more information about NDEF_WriteText API?I read out the memory through the following code as shown in the image,but I don't know why is it displayed like this?I need your help�?Thanks

while (1)

 {

  /* USER CODE END WHILE */

 /* write text message to EEPROM */

  K_Temperature= MAX6675_ReadTemperature(); //读�?�热电�?�温度值

  HAL_Delay(1000);

  // 将浮点数转�?�为字符串

  char temp_str[20];

  sprintf(temp_str, "%f", K_Temperature);

  // 将字符串转�?�为无符�?�8�?整数数组

  uint8_t temp_data[strlen(temp_str)];

  memcpy(temp_data, temp_str, strlen(temp_str));

  // 写入NDEF消�?�

  NDEF_WriteNDEF(strlen(temp_str), temp_data);

   /* Extract record info */

   sRecordInfo_t record;

   NDEF_ReadNDEF(temp_data);

   /* Extract record info */

   NDEF_IdentifyBuffer(&record,temp_data);

   if (strcmp((char*)record.Type, (char*)URL_TYPE) == 0)

   {

    /* Extract URI from NDEF Message */

    char uri[record.PayloadLength];

    memcpy(uri, record.PayloadBufferAdd, record.PayloadLength);

    /* Parse URI to get temperature value */

    sscanf(uri, "Temperature=%f", &K_Temperature);

   }

  /* Set the LED3 on to indicate Programing done */

  NFC07A1_LED_On( YELLOW_LED );

 MX_NFC7_Process();

  /* USER CODE BEGIN 3 */

 }


_legacyfs_online_stmicro_images_0693W00000big8IQAQ.png

Brian TIDAL
ST Employee

Hi,

in a nutshell, an NDEF message is a set of NDEF records. Each NDEF record carries a payload identified by a payload type (e.g. TEXT, URI, etc.).

NDEF_WriteNDEF is designed to write a buffer containing an NDEF formatted message. In your case, the content of NDEF_WriteNDEF buffer is not an NDEF message but the payload with the temperature value as a text. As the temperature value is a text, the proper API to be used is NDEF_WriteText (see description inside lib_NDEF_text.c). NDEF_WriteText encodes the payload into a TEXT record and then writes this NDEF buffer thanks to NDEF_WriteNDEF.

What you currently have in the tag memory is:

block 00: E1 40 40 05: Capability Container

block 01: 03 0B 31 30: NDEF TLV (T=03h, L=0Bh, V= 31 30 39 32 2E 32 35 30 30 30 30 etc.)

...

block 04: xx FE xx xx : Terminator TLV

Here the V-field (31 30 39 32 2E 32 35 30 30 30 30) is the payload whereas it should be the encoded TEXT message. If you use NDEF_WriteText, the V-field will have the proper TEXT message format

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,@Brian TIDAL_O​ 

According to your words, I have got the temperature data correctly,So I just have to watch the V-field to get the temperature data,Is that so?

Brian TIDAL
ST Employee

Hi,

when the NDEF TEXT message is properly formatted, Android displays the text (i.e. decodes the NDEF and extracts the payload). If using the ST25 NFC Tap app, the NDEF tab display "Text record"; the content of the record is displayed when pressing on the "Text record" field.

The memory content will be:

block 00: E1 40 40 05: Capability Container

block 01: 03 11 D1 01: NDEF TLV (T=03h, L=11h,

block 02: 0D 54 02 66 V=D1 01 0D 54 02 66 72 31 30 39 32 2E 32 35 30 30 30)

block 03: 72 31 30 39

block 04: 32 2E 32 35

block 05: 30 30 30 FE: xx xx xx FE Terminator TLV

V-field decoded:

D1 01 0D 54 02 66 72 31 30 39 32 2E 32 35 30 30 30
D1                           Record header, TNF=001 
   01                        Type Length
      0D                     Payload length
         54                  Type: T (Text)
            02 66 72 31 30 39 32 2E 32 35 30 30 30  
            02 66 72       Text lang = en
                     31 30 39 32 2E 32 35 30 30 30 
                                 Text = 1092.25000

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
Senior

Hi,@Brian TIDAL_O 

I have understood  V-field decoded correctly,but I have another question,why do I get more than 1,000 temperature figures? Is there a problem with the data conversion?

Hi,

the 12-bit temperature value is returned as bits[14:3] of the 16-bit SO output of the thermocouple to digital converter device (see datasheet of this device). As each step correspond to (1/4)°C, it is unlikely that the output value of this 12-bits value is greater that 1024 (1/4 * 2^12). Actually the datasheet states " A sequence of all ones means the thermocouple reading is +1023.75°C." which is the max possible value.

Therefore, having 1092.25 is likely a data conversion issue in your code.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.