0

I am working on a IOT project using MSP430F5529LP and CC3100Boost. The hardware is successfully connecting to the cloud and exchanging data. The response to the IOT devices is XML based. I am trying to parse the data. The following printf("\n%.*s\n", pch2-pch1-8, pch1 +8); extracts the data and prints to the console. Now in need to save this data to a variable. Here is my code snippet. The answer might be obvious, unfortunately I am failing to see it.

_i8  * databuffer;
char * pch0;
char * pch1;
char * pch2;
char  data[7];

pch0 = strstr((char *)dataBuffer,"textResponse");
pch1 = strstr(pch0,"<text_1>");
pch2 = strstr(pch1,"</text_1>");
printf("\n%.*s\n", pch2-pch1-8, pch1 +8);

References:

kfx
  • 8,136
  • 3
  • 28
  • 52
Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
  • Please note that it's a bad idea to use stdio.h on low-end microcontrollers, since it is very resource-heavy. I would guess it blows away roughly 5% of the MCU resources (RAM+flash) on a MSP430F5529. Typically it eats up somewhere around 1-2kb of RAM and 2-4kb of flash on a 16 bitter. – Lundin Oct 05 '17 at 14:39
  • 1
    @Lundin, This is a proof of concept design. But if one were to achieve the same how would you do it without using stdio.h. Is it typical to process each byte instead of using the library. – Mahendra Gunawardena Oct 05 '17 at 14:44
  • 1
    It is fairly easy to write a function that sends characters to an UART or whatever stdout corresponds to on your MCU. We're talking of a function of < 100 bytes code size, instead of >2kb, for doing exactly the same thing. In addition, stdio.h is notorious for the lack of type safety. – Lundin Oct 05 '17 at 14:51
  • @Lundin, Very helpful comment. Could you be kind enough to point me to an link or similar stackoverflow question. – Mahendra Gunawardena Oct 05 '17 at 14:58
  • I would guess you can find plenty by digging through TI MSP430 app notes and example code. – Lundin Oct 05 '17 at 15:00
  • @Lundin Thank you, I will look through the app notes – Mahendra Gunawardena Oct 05 '17 at 15:02

1 Answers1

1
  1. Ensure that the data received is valid and of a length that will fit.
  2. Print it to a string using sprintf() or equivalent function.
  3. Print this string to the console with puts(the_string).
Lundin
  • 195,001
  • 40
  • 254
  • 396