Easy question: Passing variables to function

Hello all,
I've just purchased EtherCard option for my Arduino Uno and it works just great.
What I need to do is passing several variables to the server (php script) using GET method.

At the moment I use this test code to generate random V1 values and pass it each minute to push_data.php

  int mV1 = random(10, 20);
  char V1[10];
  itoa (mV1, V1, 10);

if (millis() > timer) {
    timer = millis() + 60000;
    ether.browseUrl(PSTR("/push_data.php?ID=1&Key=123456&Status=OK&V2=5&Vall=35&V1="), V1, website, my_callback);
  }

And it works great.

What I am unable to do is make ether.browser(PSTR()) work something like that (as I neet to submit more variables):

ether.browseUrl(PSTR("/push_data.php?ID=" + ID + "1&Key=" + Key + "&Status=" + Status + "&V2=" + V2 + "&Vall=" + Vall + "&V1=" + V1), "Null", website, my_callback);

What I am doing wrong? Im not good at programming, but this is quite simple task.. Thank You guys.

You can't concatenate C strings like that, with the + operator.
You can use strcat or sprintf to achieve what you want.

Oh, thank You for the answer.
Simply changed code to

if (millis() > timer) {
    timer = millis() + 60000;
    sprintf(buffer, "&Status=OK&V1=%d&V2=%d&Vall=%d", V1, V2, Vall);
    ether.browseUrl(PSTR("/push_data.php?ID=1&Key=123456"), buffer, website, my_callback);
  }

And it works great!

Coul You please help me out with another related thing...
I post this to server i get my_callback full of info that I dont need. But some info would be good to display on my OLED screen.

The function my_callback is there:

// called when the client request is complete
static void my_callback(byte status, word off, word len) {
    Ethernet::buffer[off+300] = 0;
    Serial.write((const char*) Ethernet::buffer + off);
}

And result is this:

HTTP/1.1 200 OK
Date: Wed, 10 Oct 2012 13:28:13 GMT
Server: Apache
Connection: close
Content-Type: text/html

#DEVOK, 16:28:13 #STSET, 16:28:13 #DASET, 16:28:13

All in need is just system messages with time after "#".
How can I trim the result to remove everything else.

Thanks!:slight_smile:

ps- thats the last stupid question from me:) I promise:)

All in need is just system messages with time after "#".
How can I trim the result to remove everything else.

The data that you are Serial.write()ing is stored in a buffer - Ethernet::buffer.
Use strtok() to get a pointer to the string up to the first # (hint - the delimiter argument will be "#"). Then, call strtok() again, with a different delimiter string ("\0"), to get the rest of the data (the "DEVOK, 16:28:13 #STSET, 16:28:13 #DASET, 16:28:13" part).

Copy that data to another buffer, and you can use strtok() again on that buffer to get just the parts you want.

Copy that data to another buffer,

Why bother with another buffer?
Just write from the pointer that strtok returns - the rest of the string is already null-terminated, isn't it?

Why bother with another buffer?

The second token would be "DEVOK, 16:28:13 #STSET, 16:28:13 #DASET, 16:28:13". If you want to extract just the 1st time from that, you need to make a copy of it. Calling strtok() with a pointer to internal data stored by the strtok() function is not a good idea. The internal data will be destroyed as soon as strtok() detects that the input argument is not NULL, rendering the pointer useless.

Thank You, guys, it worked perfectly for me:)