Loading...
Pages: [1]   Go Down
Author Topic: an array within an HTML GET command  (Read 617 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 45
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: 50
Posts: 6532
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

Why I like my 2005 rio yellow Honda S2000 with the top down, and more!
GOOGLE ADVANCED FORUM SEARCH BELOW!  
Go to:  http://www.google.com/advanced_search?hl=en
put in key search words,
use site or domain:  http://arduino.cc/forum
or in a google search box put key words site:http://arduino.cc/forum

Offline Offline
Newbie
*
Karma: 0
Posts: 45
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: 50
Posts: 6532
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

Why I like my 2005 rio yellow Honda S2000 with the top down, and more!
GOOGLE ADVANCED FORUM SEARCH BELOW!  
Go to:  http://www.google.com/advanced_search?hl=en
put in key search words,
use site or domain:  http://arduino.cc/forum
or in a google search box put key words site:http://arduino.cc/forum

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: 45
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: 311
Posts: 35470
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
Print
 
Jump to: