0

I am currently trying to establish a connection between my gsm sim900A to one of my test server. The connection seems pretty good so far, though I'm a little bit confused why there are no values retrieved by my php file. Even so, the insert query works although it insert empty value into the database. So my question is how to retrieve it properly? I already change the method in php script to POST, both of it doesn't return any good signs.

Arduino Code:

void postData()
{
  sim900a.println("AT+HTTPINIT");
  delay(1000);
  printSerialData();

  sim900a.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);
  printSerialData();

  sim900a.println("AT+HTTPPARA=\"URL\",\"test.my/demo/writedata.php\"");
  delay(1000);
  printSerialData();

  sim900a.println("AT+HTTPDATA=12,10000");
  delay(1000);
  printSerialData();

  sim900a.println("strBoton=999");
  delay(1000);
  printSerialData();

  sim900a.println("AT+HTTPACTION=1");
  delay(1000);
  printSerialData();

  sim900a.println("AT+HTTPREAD");
  delay(1000);
  printSerialData();

  sim900a.println("AT+HTTPTERM");
  delay(1000);
  printSerialData();
}

PHP Code:

<?php
$servername = "test.my";
$username = "****";
$password = "****";
$dbname = "test";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$Boton = $_GET["strBoton"];

$sql = "INSERT INTO test VALUES ('$Boton')";   

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>

Output:

AT+HTTPINIT
OK

AT+HTTPPARA="CID",1
OK

AT+HTTPPARA="URL","test.my/demo/writedata.php"
OK

AT+HTTPDATA=12,10000
DOWNLOAD
OK

AT+HTTPACTION=1
OK

AT+HTTPREAD
OK

AT+HTTPTERM
+CME ERROR: operation not allowed

AT+SAPBR=0,1
OK

1 Answer 1

0

I am not sure but, in this tutorial at page 8, it does almost the same code pattern like yours. You might want to check it. Sorry but I don't know PHP, I can't help you with it.

But I am confused with AT+HTTPACTION, since AT+HTTPACTION=0 is the read and AT+HTTPACTION=1 is the post. Check the tutorial and optimize your commands.

Also check this one. It writes WAIT=6 after AT+HTTPREAD before terminating it.

5
  • my references are both the link that u provide in the first paragraph and this one, electronics.stackexchange.com/questions/231224/… . I am still learning how to arduino by the way so i'm having a hard time swallowing the flow of the codes.
    – Asyraf
    Apr 14, 2018 at 21:31
  • i will try to modify the codes and differentiate between AT+HTTPACTION=0 and 1 for now, as for the WAIT=6, I believe that is the delay time after the execution. Thanks for reminding me.
    – Asyraf
    Apr 14, 2018 at 21:34
  • I will check the link you send. I will command on it if anything necessary. Thanks for the link by the way.
    – HVK
    Apr 14, 2018 at 22:11
  • I'll change it to AT+HTTPACTION=0 and remove certain lines of codes and it works! Thank you sir. :)
    – Asyraf
    Apr 15, 2018 at 17:07
  • Your welcome, always happy to help a fellow ;-)
    – HVK
    Apr 15, 2018 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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