Go Down

Topic: How to get substrings from char pointer array (Read 3 times) previous topic - next topic


Yes you can use the webpage XML data  into the buffer.

char buffer[]="------------------------------XML DATA-----------------------------------------"; //This is a character array buffer.

In logic you must Identify the token, FieldName, FieldValue etc.

Goodluck for your experiment..


The data returned from "http://www.google.com//ig/api?weather=London" is 1371 bytes, not counting headers.  It us unlikely you will be 100% successful with the approach of loading the whole response into a string and searching around in it with stsrstr().

I would structure this as a parser like below that uses a small buffer to recognize just one tag at a time, and then feed all the data you receive into it.  This allows you to avoid saving huge swaths of the response at once.  You just feed your data into handle_input() one character at a time and it does the rest.

Code: [Select]
char token[TOKEN_LEN];
uint8_t input_len = 0;

void handle_input(uint8_t c)
int temp;

    /* c = '<', then a new tag sequence is starting
    if (c == '<') {
        input_len = 0;

    /* c = '>', a tag sequence is complete.
     * Check if this is a specific tag
    if (c == '>') {
       token[input_len] = 0;

       if (strncmp(token, "temp_c data=\"", 13) != 0)

       temp = atoi(token + 13);

// Now what?
Serial.print("got temperature ");


    /* otherwise we have an input character
    if (input_len <= TOKEN_LEN - 1)
       token[input_len++] = c;


Thank you for the advice.
I have a feeling for me I'm  byting off more than I can chew for now.
I think I need to learn a bit more C++ before I can get my head around this.

Again, thanks for the advice.


Hey, I have same problem with reading the array - have you found a solution ?
I can call a web page, and in my serial monitor can I read that I receive the correct data from the web server, but how can "work" with my received data ?


but how can "work" with my received data ?

Collecting the data in an array is the first step. Then, define what ""work" with my received data" means.

There are plenty of examples around of parsing the data that a client sends to the Arduino server, or that an Arduino client fetches from a server.

Go Up