0

I am using SIM800c gsm module to send data to php server

These are the commands i am trying to send data

AT
AT+CPIN?
AT+CREG?
AT+CGATT?
AT+CSQ
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","airtelgprs.com"
AT+SAPBR=1,1
AT+SAPBR=2,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://axxxxxxxxxx.000webhostapp.com/conn.php"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=14,20000
{"name":"abc"}
AT+HTTPACTION=1
AT+HTTPREAD
AT+HTTPTERM 
AT+SAPBR=0,1 

And my php code is:

<?php
$servername = "localhost";
$username = "xxxxxx";
$password = "xxxxxxx";
$dbname = "xxxxxxxxx";


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else{

}

$name=$_POST['data'];
$sql = "INSERT INTO info (inform)
VALUES ('$name')";

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

$conn->close();


?>   

When i am using these codes to send data, I can find a entry in my php server but no data abc is not visible.

I have tried GET method to send data where i put my data in the url

like this:

AT+HTTPPARA="URL","http://axxxxxxxxx.000webhostapp.com/conn.php?data=abc"

Using GET method shows the data perfectly.

Any ideas how to send it using POST????

Any help will be appreciated.

Thanks in advance

Devjeet Mandal
  • 345
  • 1
  • 4
  • 23
  • What have you tried to resolve the problem? Where are you stuck? Also, be warned that your code is widely open for SQL injection - please have a look at prepared statements to avoid getting hacked – Nico Haase Mar 02 '22 at 09:48

2 Answers2

0

I think you should have AT+HTTPACTION=1 instead of AT+HTTPACTION=0

And have

AT+HTTPPARA="CONTENT","application/json" 
AT+HTTPDATA=14,10000

Then

{"name":"abc"}
PierreN
  • 968
  • 4
  • 11
  • sorry that was a typo. I have tried `HTTPACTION=1`. I have edited it – Devjeet Mandal Jul 09 '18 at 20:03
  • You can debug the data you are receiving with posting the data to a http://postb.in/ URL you create, for instance http://postb.in/b/JzwRJJFL – PierreN Jul 09 '18 at 20:26
  • Why have you put DOWNLOAD on the httpdata line? – PierreN Jul 09 '18 at 20:39
  • Sorry Sir, I was not available for few days. Just now i tried whatever you suggested. First i used my php web server it is not working. It is receiving the data but not showing the actual data in web page. Then i used postb.in and there also i can see some data is received but actual data `abc` is not shown. – Devjeet Mandal Jul 14 '18 at 17:02
  • I am editing the question as per the last send data. please suggest where i am going wrong – Devjeet Mandal Jul 14 '18 at 17:03
0

at+sapbr=3,1,"Contype","GPRS";

OK at+sapbr=3,1,"APN","internet"

OK at+sapbr=1,1

OK at+sapbr=2,1

+SAPBR: 1,1,"ip"

OK

at+httpinit

OK

at+httppara="CONTENT","text/plain; charset=UTF-8"

OK

at+httppara="CID",1

OK

at+httppara="URL","http://your url"

OK

at+httpaction=0";

OK +HTTPACTION: 0,200,20

this worked for me

  • Please add some explanation to your answer such that others can learn from it – Nico Haase Mar 02 '22 at 09:48
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 02 '22 at 11:03