Arduino GET data

I have an example web client that can connect to a predefined website .. but how do I configure this to input variables?

ie here :

   // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET /Admin/Update.php?page=update&key=17&name=Test&temp=15&light=99 HTTP/1.1");
    client.println("Host: www.test.com");
    client.println("Connection: close");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }

instead of using predefined values for temp and light ... I want to use variables temp and light .. but if I just type the name there then it sends just the name and not the variable value.

instead of using predefined values for temp and light ... I want to use variables temp and light .. but if I just type the name there then it sends just the name and not the variable value.

See those double quotes on the ends? They mean send everything from here to here AS IS. Since that's not what you want, you need to re-enroll in CS100, and learn about sprintf().

I use sprintf. Yours should look something like this:

char outBuffer[100];
int myKey = 17;
char myName = "Test";
int myTemp = 15;
int myLight = 99;

sprintf(outBuffer,"GET /Admin/Update.php?page=update&key=%u&name=%s&temp=%u&light=%u HTTP/1.1",myKey,myName,myTemp,myLight);
client.println(outBuffer);

Insure outBuffer is large enough to hold all that.

    client.print ("GET /Admin/Update.php?page=update&key=17&name=");
    client.print (name);
    client.print ("&temp=");
    client.print (temp);
    client.print ("&light=99 HTTP/1.1");

That is a five packet send. That is 48 bytes of overhead per packet. Mine is one packet. Some servers have problems with that. And that last should be a client.println().

His original line didn't have println, although you are probably right there. :slight_smile:

I'm offering that as an alternative if you didn't want to spend 100 bytes of RAM on a temporary buffer.

I got the variables wrong, he wanted temp and light, not name and temp, but the general idea is the same.

@Nick: I got the point. I was offering a reason to spend the 100 bytes of SRAM instead of sending a bunch of packets. Most servers do not have a problem with receiving the GET line in multiple packets, but some do, and I'm not sure which.

Thanks that helps a lot. Should I put my client code in a seperate function and then call it each time I want to upload variables? Then I can stick all my sensor functions within the void loop with a delay at the end.

Then I can stick all my sensor functions within the void loop with a delay at the end.

No don't do that. Look at the blink without delay example.

PaulS:

Then I can stick all my sensor functions within the void loop with a delay at the end.

No don't do that. Look at the blink without delay example.

...or look at my client code with the new "wait 30 seconds without delay()" code. :wink:
http://playground.arduino.cc/Code/WebClient
The timeout feature still uses delay(1), but the loop uses millis() now.

If I output just a number in php can my arduino read it directly or do I still have to use find string?

Carlo060:
If I output just a number in php can my arduino read it directly or do I still have to use find string?

If you output just a number, it should be the first line after the header. Read until the blank line, and the next line should be your number.

Hi take a look at my project i think can help you

http://www.dataino.it/help/document.php
http://www.dataino.it/help/document_data.php
http://www.dataino.it/help/document_tutorial.php?id=5

Ciao