jcw/ethercard — Issue #8: Wierd result for get data
Author: Hexagon
Created: 2011-12-12 23:52:22+00:00
State: open

I don't know if i'm doing something wrong, but im getting really wierd results

[code]
void report_temp (float temp, int unit) {

// Prepare querystring
char buf[16];
char buf_full[32]; // 32 == Wierdness, 128 is working

// Construct GET payload
String s = "t=";
s = s + String(dtostrf(temp,7,3,buf));
s = s + "&u=";
s = s + String(unit);

s = s.replace(" ","");

// Convert s to char *
s.toCharArray(buf_full, sizeof(buf_full));

Serial.println(buf_full); // <--- Always looks fine wether i use 32 or 128

ether.browseUrl(PSTR(SITE_REPORT_URL), buf_full, website, callback);

}
[/code]

When i am using 32 as size for buf_full, i get a request that looks like this on server side;

[13/Dec/2011:00:11:37 +0100] "GET /temp/report.php?ºÙ\x08 HTTP/1.1" 200 19 "-" "-"

When using 128 as buffer size, i get something that makes sense

[13/Dec/2011:00:47:20 +0100] "GET /temp/report.php?t=23.250&u=0 HTTP/1.1" 200 12 "-" "-"

How is this possible? The resulting string is not more than 16 chars? And when i do Serial.println() it seems fine