Pages: [1]   Go Down
Author Topic: an array within an HTML GET command  (Read 1070 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an HTML line in a sketch:
client.println("GET /xml/current_obs/KVNY.xml HTTP/1.0");
I would like to put a array in for KVNY.

char* icao[]={"KVNY"};

setup() ...

loop() ...

client.println("GET /xml/current_obs/(icao[0].xml HTTP/1.0");

This addition compiles and uploads, but doesn't work.


Logged

0
Offline Offline
Tesla Member
***
Karma: 144
Posts: 9613
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might need to do something like below to get your array into the string you want to send.

client.println("GET /xml/current_obs/" + (icao[0]) + ".xml HTTP/1.0";
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, but that did not work.  It just inserted the + (icao[0]) + to the output.
Got to think about some more.
Logged

0
Offline Offline
Tesla Member
***
Karma: 144
Posts: 9613
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any particular reason why you want to use an array instead of a string?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're using cstrings, not String objects - the easiest way to do what you want would be sprintf.

Code:
char icao[]="KVNY";
// ...

char buf[strlen(icao) + 40]; // About 45 characters of buffer space
sprintf(buf, "GET /xml/current_obs/%s.xml HTTP/1.0", icao);
client.println(buf);

If you use a String object, the + operator will concatenate strings for you.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

zoomcat!

Great help. I don't think I've seen sprintf in Arduino examples, but it surely is in C.

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The information output for the GET command does not need to be output all at once.
Code:
client.print("GET /xml/current_obs/");
client.print(icao);
client.println(.xml HTTP/1.0");
will output the data in icao as part of the GET command, without the overhead of a buffer and the sprintf code.
Logged

Pages: [1]   Go Up
Jump to: