Trying to put together a string for HTTP GET

Not doing something right

// Make a HTTP request:
char str0[] ="216.245.193.741/rick/push.asp";
char reada[4] = {digitalRead(1), digitalRead(2), digitalRead(3), digitalRead(4)};

char str5[] = {str0, "?ad1=", reada[0], "&ad2=", reada[1]};

//client.get(str5);

//test to see in monitor
Serial.println("String is ");
Serial.println(str5);

}

Giving me

String is
ɯµ

I must have data type problems. Hints are appreciated

There is no need to build a single string. Just send it in parts. The receiving device won't know the difference.

valA = digitalRead(pinA);
valB = digitalRead(pinB);
Serial.print("216.245.193.741/rick/push.asp");
Serial.print(valA);
Serial.print(' ');
Serial.print(valB);
// etc

I probably don't have the content right, but I think you will get the idea.

...R

char str5[] = {str0, "?ad1=", reada[0], "&ad2=", reada[1]} is an array of 4 chars. your output is 4 chars. everything is ok.

unless you need an array of 4 strings.
a constant string is const char* str0 ="216.245.193.741/rick/push.asp"
an array of constant strings is const char* str5[] = {str0, "?ad1=", "abcd", "&ad2=", "xyz"}

println can't print an array of strings. you can use sprintf to create formatted strings

char msg[100];
sprintf(msg,"%s?ad1=%d&ad2=%d", str0, digitalRead(1), digitalRead(2));
Serial.println(msg);
 char reada[4] = {digitalRead(1), digitalRead(2), digitalRead(3), digitalRead(4)};

An array of non-printable characters is not going to prove useful.

Thanks, useful info for serial println. I am concerned that the function client.get() needs one big string thus the reason trying ways to construct it.

I need to end up with
"216.245.193.741/rick/push.asp?ad1=var1&ad2=var2&ad3=var3&ad4=var4";

I can't seem to pass any vars into the string.

R

I am concerned that the function client.get()

There is no client.get() function. There is a client.print() function that can print a GET request to a server. It makes some, but not much, difference if you use

client.print("GET ");
client.print(script);
client.print("?");
client.print("ad1=");
client.print(var1);
client.println(" HTTP/1.1");

vs.

char lotsOfStuff[80];
sprintf(lotsOfStuff, "GET %s?ad1=%d HTTP/1.1", script, var1);
client.println(lotsOfStuff);

Your GET request seems to incorrectly include the server name.

I'm not sure why you are sending the IP adress in the get request.

An HTTP get request is normally done by connecting to an IP address with a TCP connection and then sending

GET /foo/bar/myfile?param1=xxx&param2=yyy HTP/1.1
header1=something
header2=something else
<CR/LF blank line goes here>

I am on a YUN. This is from the examples / bridge / http client code

// Make a HTTP request:
client.get("http://www.arduino.cc/asciilogo.txt");

If I can hit the web address with my params the asp code will do the rest.

rheine:
I am on a YUN. This is from the examples / bridge / http client code

// Make a HTTP request:
client.get("http://www.arduino.cc/asciilogo.txt");

Ok - so the 'client' object does the job of pulling apart your URL.

What you want to do then is create an empty array of char[] that will be big enough to hold your URI, initialize element zero to '\0' (to turn it into a zero-lengh string), and then use the libc string functions to append the bits of your URI into that buffer.

char buf[100];
buf[0] = '\0';
char *p = buf;

strcpy(p, "http://216.245.193.741/rick/push.asp?ad1=");
while(*p) p++;
itoa(digitalRead(1), p, 10);
while(*p) p++;
strcpy(p, "&ad2=");
itoa(digitalRead(2), p, 10);

// buf[] now contains your string.
Serial.print("The URL is ");
Serial.println(buf);

Is my answer #2 hidden or what?

PaulMurrayCbr, why so complicated string concatenation?

rheine:
I am on a YUN. This is from the examples / bridge / http client code

Why on earth are you trying to formulate a GET string on the Arduino side of a Yun when you have all that Linux computing power on the same board?

...R

Juraj:
PaulMurrayCbr, why so complicated string concatenation?

It isn't complicated.

Robin2:
Why on earth are you trying to formulate a GET string on the Arduino side of a Yun when you have all that Linux computing power on the same board?

Very good point.

A small shell script that takes some parameters would be much easier to do.

PaulMurrayCbr:
It isn't complicated.

what is wrong with sprintf?

Juraj:
what is wrong with sprintf?

There is nothing wrong with sprintf. sprintf is a good solution for this problem.