I've been trying to post data to server for sometime now. Even though I am getting OK response, data is not posted to the server.
Here's my Code:
#include <SoftwareSerial.h>
SoftwareSerial myGsm(7,8);
unsigned char ctrl_z = 26;
void setup()
{
myGsm.begin(115200);
Serial.begin(9600);
delay(500);
myGsm.println("AT+CIPSHUT\r"); //RESPONSE= OK
delay(1000);
myGsm.println("AT+CIPMUX=0\r"); //RESPONSE= OK
delay(2000);
myGsm.println("AT+CGATT=1\r"); //RESPONSE= OK
delay(1000);
myGsm.println("AT+CSTT="internet","",""\r"); //RESPONSE= OK
delay(5000);
myGsm.println("AT+CIICR\r"); //RESPONSE= OK
delay(5000);
myGsm.println("AT+CIFSR\r"); //RESPONSE= Returns an IP
delay(2000);
myGsm.println("AT+CIPSTART="TCP","159.203.180.107", 80\r"); //RESPONSE= CONNECTED OK
delay(3000);
myGsm.println("AT+CIPSEND\r"); //RESPONSE= >
delay(500);
myGsm.println("POST http://159.203.180.107/Code/ HTTP/1.1");
delay(500);
myGsm.println("Host: 159.203.180.107");
delay(500);
myGsm.println("Content-Type: application/json");
delay(500);
myGsm.println("Content-Length: 25\r\n");
delay(500);
myGsm.println("{"Celsius":"TEMPERATURE"}");
delay(500);
myGsm.write(ctrl_z);
delay(10000);
/*
After sending all these instructions, i get the following response,
OK
HTTP/1.1 200 OK
Friday December, 22
+TCPCLOSE=0
OK
*/
myGsm.println("AT+CIPCLOSE"); //RESPONSE= OK
delay(1000);
myGsm.println("AT+CIPSHUT"); //RESPONSE= OK
delay(1000);
}
void loop()
{
}
So, as you can see, I get 200 OK response after sending the data, but in the server the data is not written into the file. Existing content in the file is erased, but new data is not written in that file.
Here's my php file in the server,
<?php echo ""; print_r($_REQUEST); file_put_contents("data.txt", $_REQUEST); die(" DONE!"); ?>So what could be the problem? Is there anything wrong with the way I am posting data? Please help.