Hi Spark Community,
i have a Problem calculating the Content Length of a Post Request.
static uint16_t werte[60];
static uint8_t sec[60];
static uint8_t min[60];
static uint8_t hr[60];
static uint8_t day[60];
static uint8_t month[60];
static uint8_t year[60];
void ANALOGREAD() //Just for testing
{
for(uint8_t i = 0; i<60;i++)
{
delay(300);
werte[i] = i;
sec[i] = Time.second();
min[i] = Time.minute();
hr[i] = Time.hour();
day[i] = Time.day();
month[i] = Time.month();
year[i] = (Time.year()) % 2000;
}
}
void postRequest()
{
client.connect(LIB_DOMAIN, 80);
delay(20);
client.println("POST /hakan/index2.php HTTP/1.1");
client.println("Host: " LIB_DOMAIN);
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(contentLength());
client.println();
clientPrint2();
delay(20);
}
void clientPrint2() //s0=12&d0=14-7-15 11:45:25&s1=....
{
for(uint8_t i = 0; i < 60;i++)
{
if(i!=0)
{
client.print("&");
}
client.print("s");
client.print(i);
client.print("=");
client.print(werte[i]);
client.print("&d");
client.print(i);
client.print("=");
client.print(year[i]); // ändern
client.print("-");
client.print(month[i]);
client.print("-");
client.print(day[i]);
client.print(" ");
client.print(hr[i]);
client.print(":");
client.print(min[i]);
client.print(":");
client.print(sec[i]);
delay(20);
}
delay(1000);
postResponse();
}
uint16_t contentLength()
{
uint16_t cL = 0;
for(uint8_t i = 0; i < 60; i++)
{
char a[] = {werte[i]};
cL += sizeof(a)/sizeof(char);
char b[] = {day[i]};
cL += sizeof(b)/sizeof(char);
char c[] = {hr[i]};
cL += sizeof(c)/sizeof(char);
char d[] = {sec[i]};
cL += sizeof(d)/sizeof(char);
char e[] = {min[i]};
cL += sizeof(e)/sizeof(char);
char f[] = {month[i]};
cL += sizeof(f)/sizeof(char);
char g[] = {year[i]};
cL += sizeof(g)/sizeof(char);
cL -= 7; // Null Termination of each char[]
}
cL += (10*2)+(49*4); //(i0-9)+(i10-59)
cL += (60 * 7); // "=" "=" "-" "-" " " ":" ":"
cL += (60 *2); // s & d
cL += (60 *2)-1; // "&"
return cL;
}
0;14-7-15 12:23:48;
1;14-7-15 12:23:48;
2;14-7-15 12:23:48;
3;14-7-15 12:23:49;
4;14-7-15 12:23:49;
5;14-7-15 12:23:49;
6;14-7-15 12:23:50;
7;14-7-15 12:23:50;
8;14-7-15 12:23:50;
9;14-7-15 12:23:50;
10;14-7-15 12:23:51;
11;14-7-15 12:23:51;
12;14-7-15 12:23:51;
13;14-7-15 12:23:52;
14;14-7-15 12:23:52;
15;14-7-15 12:23:52;
16;14-7-15 12:23:53;
17;14-7-15 12:23:53;
18;14-7-15 12:23:53;
19;14-7-15 12:23:53;
20;14-7-15 12:23:54;
21;14-7-15 12:23:54;
22;14-7-15 12:23:54;
23;14-7-15 12:23:55;
24;14-7-15 12:23:55;
25;14-7-15 12:23:55;
26;14-7-15 12:23:56;
27;14-7-15 12:23:56;
28;14-7-15 12:23:56;
29;14-7-15 12:23:56;
30;14-7-15 12:23:57;
31;14-7-15 12:23:57;
32;;
;;
;;
;; an so on ...
After the Post, only half of the Post Request is cought by the Server. So i am making a mistake somewhere.
Anyone any ideas to Solve this Problem ?
Thx,
Dongamelo