1

Why is the server side of php not loading any data from arduino? What did I do wrong?

  String reading="{\"latitude\": 12.983027,  \"longitude\": 80.2594}";
  mySerial.println("AT+HTTPINIT"); 
  toSerial(1000);

  mySerial.println("AT+HTTPPARA=\"CID\",1"); 
  toSerial(1000);

  mySerial.println("AT+HTTPPARA=\"URL\",\"http://gerro.usermd.net/updateData.php\"");
  toSerial(1000);

  mySerial.println("AT+HTTPPARA=\"CONTENT\", \"application/json\"");
  toSerial(1000);

  mySerial.println("AT+HTTPDATA=" + String(reading.length()) + ",100000");
  toSerial(5000);

  mySerial.println(reading);
  toSerial(1000);

  mySerial.println("AT+HTTPACTION=1"); 
  toSerial(15000);

  mySerial.println("AT+HTTPREAD"); 
  toSerial(1000);

  mySerial.println("AT+HTTPTERM"); 
  toSerial(500);

Result:

AT+HTTPINIT

OK
AT+HTTPPARA="CID",1

OK
AT+HTTPPARA="URL","http://gerro.usermd.net/updateData.php"

OAT+HTTPPARA="CONTENT", "application/json"

OK
AT+HTTPDATA=46,100000

DOWNLOAD

OK
AT+HTTPACTION=1

OK

+HTTPACTION:1,200,55
AT+HTTPREAD

+HTTPREAD:55
array(0) {
}
array(0) {
}
nic ciekAT+HTTPTERM

OK

EDITING

void toSerial(int delay_ms)
  {
    delay(delay_ms);

    while(mySerial.available()) 
    {
       Serial.write(mySerial.read());
    }
  }

PHP

<?php
var_dump($_POST);
if (isset($_POST['latitude']) && isset($_POST['longitude']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
//code
} else {
echo 'nic';
}
  • What exactly does toSerial() do? Post all of it. – SoreDakeNoKoto May 12 at 1:08
  • 1
    @hcheung as it tests with postman it all works and returns data from $ _POST. I think you tested it badly. In the php file there is var_dump ($ _ POST) and hence the result array (0) {} – wgerro May 12 at 6:10
  • 1
    @TisteAndii I've already edited the post. – wgerro May 12 at 6:13
  • 1
    on the server php shows that it does not receive CONTENT-TYPE and CONTENT-LENGTH from arduino – wgerro May 12 at 6:15
  • 1
    @hcheung maybe you haven't enabled the POST method – wgerro May 12 at 8:16
1

You had to change the php file:

var_dump($_POST);

to:

echo print_r(json_decode(file_get_contents("php://input")));

Thank you !

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.