Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Problem sending POST to webserver from SIM900 with AT commands

Status
Not open for further replies.

Br1

Newbie level 4
Newbie level 4
Joined
Feb 26, 2013
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,365
First of all, good day to all.

My goal is to POST variables to my webserver usign GPRS modem SIM900.
For testing purposes, SIM900 modem is connected to PC via serial port with a MAX232 in between, running 19200,8,N,1. No Flow control.
My webserver: Apache with PHP 5.
Software used: Hyperterminal, Tera Term and other terminal emulators.
Serial communication is Ok, sending and receiving characters all right.

The problem (That has been driving me mad since a week now :-x): Webserver accepts with no problems POST from regular HTML Forms and from a Firefox plugin that sends POST: Httprequester. I monitor the received headers and variables are correctly received and parsed by PHP. HOWEVER!!, webserver (or PHP) is not accepting the POST when sent from SIM900. Internet communication is done Ok as I receive the return diagnostic echos that have programed from server.
The returned text from the server is an echo of the complete POST. I read it from the SIM900 using terminal... and it is OK!!! I don't understand.

I think that the AT command sequences are Ok, and there is something wrong with the actual POSTing that the SIM900 does. But is also very likely that I'm wrong! Lol.

AT commands that I send (Configuring CR+LF as line termination):
Code:
AT+CGATT?
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","internet.ctimovil.com.ar"
AT+SAPBR=3,1,"USER","ctigprs"
AT+SAPBR=3,1,"PWD","ctigprs"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://myserveraddress/comm.php"
AT+HTTPDATA=137,5000
POST http://myserveraddress/comm.php
Content-Length: 414
Content-Type: application/x-www-form-urlencoded

var_a=444&var_b=sample+data
AT+HTTPACTION=1
AT+HTTPREAD

When entering AT commands, no errors returned.
After the AT+HTTPREAD command, I get exactly the POST sent, but no POST variables.

Code:
POST NOT RECEIVED CORRECTLY. 1. 2. 3. POST http://myserveraddress/comm.php
Content-Length: 414
Content-Type: application/x-www-form-urlencoded

var_a=444&var_b=sample+data

My PHP at webserver:

PHP:
<?php
if (isset($_POST['var_a'])) {
//Read POST data
 $var_a = $_POST['var_a'];
 $var_b = $_POST['var_b'];

echo "OK";
}
else {
//Diagnostic echoes
	echo "POST NOT RECEIVED CORRECTLY. ";
	echo "1. ".$_POST['var_a'];
	echo "2. ".$_POST['var_b'];
	echo "3. ".$HTTP_RAW_POST_DATA;
}
?>

Also tried setting the content type using AT command:
Code:
AT+SAPBR=3,1,"CONTENT","application/x-www-form-urlencoded"
But it didn't help. I don't know if this command is supported in my SIM900 firmware version: 1137B06SIM900M64

Tried as well the TCP approach (as opposed to the previous HTTP approach) using AT+CSTT, AT+CIICR, AT+CIPSTART and AT+CIPSEND. Same negative results.

I guess you must be tired and a little bit angry after reading the looonngg post. :evil: That is also how much upset I am. I need to solve this.
I will appreciate any input.

Is it the SIM900 config? Are the line ends and carraige returns not correct when entering POST data? :?:

Thank you communtity!

Best regards,

Br1
 

hello Br1,
i have not tried "POST" but i was able to use "GET" successfully to log all my variables to a server

code:

AT+CGATT?
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","internet.ctimovil.com.ar"
AT+SAPBR=3,1,"USER","ctigprs"
AT+SAPBR=3,1,"PWD","ctigprs"

AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","www.YOURDOMAIN/page.php?dat=788868856775757467484648464874"
AT+HTTPACTION=0
AT+HTTPTERM



this is the corresponding php script that gets the data "page.php"

code:

<?php

$myFile = "file.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, '');

if($_GET['dat'] == "")
{
// no username entered
echo "You did not enter a name.";
}
else
{
$stringData = $_GET['dat'] ;
fwrite($fh, "\n");
fwrite($fh, strftime('%c'));
fwrite($fh, " :");
fwrite($fh, $stringData);
// echo "Hello, " . $_GET['dat'];
fclose($fh);
}
?>




and this is 'index.php', the code that shows you the data in real time it has automatic refresh but you can do better than this using ajax.


code:
<?php

header('Refresh: 12');

// file() loads the contents of file.txt into an array, $lines
// each line in the file becomes a seperate element of the array.
$lines = file('file.txt');

// now loop through the array to print the contents of the file
echo "Logged Meter Readings:<br>";
echo "Date Time: Current Voltage Temp.";
echo '<br>';
foreach ($lines as $line)
{
echo htmlspecialchars($line) . '<br>';
}

// we can also access each line of the file seperately
//echo '3rd line of the file: "' . htmlspecialchars($lines[2]) . '"<br>';

?>
 
I am having the same problem. SIM908 says it supports POST but there is NO way to send POST data. When I send POST data I get my data returned to me. Anyone who has steps to send POST data to a web page?
 

hi ogbeni
I am working on same target. I want to send data to website using sim900 gprs. But i want to know step by step information to create website.
Thank you
 

Hi Ogbeni. This code helped me a lot. Thanks. I have successfully sent a GET request, but I am facing a problem that I only received the data once on the server. I am trying to initiate the GET request in a loop after every 10 seconds. I only receive it on first iteration. I need your help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top