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';
}
9
  • What exactly does toSerial() do? Post all of it. Commented May 12, 2020 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) {} Commented May 12, 2020 at 6:10
  • 1
    @TisteAndii I've already edited the post. Commented May 12, 2020 at 6:13
  • 1
    on the server php shows that it does not receive CONTENT-TYPE and CONTENT-LENGTH from arduino Commented May 12, 2020 at 6:15
  • 1
    @hcheung maybe you haven't enabled the POST method Commented May 12, 2020 at 8:16

1 Answer 1

1

You had to change the php file:

var_dump($_POST);

to:

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

Thank you !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.