send_data2web(IN char *temp,IN char *hum)
{
char data2send1 = temp;
char data2send2 = hum;
String PostData="sample={"fittingId":1,";
unsigned char i;
for(i=1;i<3;i++)
{
PostData=PostData+""channel-";
PostData=String(PostData+i);
PostData=PostData+"":";
PostData=String(PostData + String(data2send+i);
if(i!=5)
PostData=PostData+",";
}
PostData=PostData+"}";
byte sd = stash.create();
stash.println(PostData);
stash.save();
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
if (client.connect(website, 80)) //这个如何判断是不是连上我的服务器
{
Serial.println("\nconnected...");
Serial.println("ARDUINO: forming HTTP request message");
client.println("POST /UNIControl/PhpPost.php HTTP/1.1"); //setting PHP
client.println("From: Arduino_room1 ");
client.println("POST /tinyFittings/index.php HTTP/1.1");
client.println("Host: 192.168.2.42");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("User-Agent: HTTPTool/1.0");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print ("Content-Length:");
client.println(DatatoSend.length());
client.println("Connection: close");
client.println(DatatoSend);
client.println();
Serial.println("ARDUINO: HTTP message sent");
delay(3000);
if(client.available())
{
Serial.println("ARDUINO: HTTP message received");
Serial.println("ARDUINO: printing received headers and script response...\n");
while(client.available())
{
char c = client.read();
Serial.print(c);
}
}
else
{
Serial.println("ARDUINO: no response received / no response received in time");
}
client.stop();
}
else
{
Serial.println("connection failure");
}
delay(2000);
}