Pages: [1] 2 3   Go Down
Author Topic: POST HTTP with AT Commands  (Read 7929 times)
0 Members and 1 Guest are viewing this topic.
South Africa
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All

Hope you are doing well

I am trying to post an HTTP URL with data to a website.
I tested it first on Cosm and it works on Cosm, but I want to emulate an entry in the address bar of IE.

If I type the following http://www.mysite.com/test/gettempdata.php?TI=12.1&TO=22.2&TR=33.3 in to the address bar of internet explorer it updates the MySQL DB and shows the DATA on the page.

How do I do the same with AT commands?
I am not sure if there need to be extra ""

I am using a SIM900 with Software Serial witch has a 64 Byte buffer.

I have tried the following:
Code:
AT+SAPBR=3,1,"APN","internet"
OK

AT+CIFSR
41.18.131.13

AT+CIPSPRT=0
OK

AT+CIPSTART="TCP","http:/www.mysite.com","80"
OK

CONNECT OK

AT+CIPSEND
http:/www.mysite.com/test/gettempdata.php?TI=25.5&TO=20.9&TR=16.7
SEND OK

AT+CIPCLOSE
AT+CIPSHUT=0

CLOSE OK
and

Code:
AT+CSQ
AT+CGATT?
AT+SAPBR=3,1,"CONTYPE","GPRS"

+CSQ: 12,0
AT+SAPBR=3,1,"APN","internet"
OK

AT+HTTPPARA="URL","http:/www.mysite.com/test/gettempdata.php?TI=25.5&TO=20.9&TR=16.7"
OK

AT+HTTPACTION=0
OK

+HTTPACTION:0,603,0
AT+HTTPREAD
OK

When I use HTTPPARA I do not get  response, if I use HTTPPARA with www.google.com I get a response when I run HTTPREAD

Any help would be appreciated.
Please let me know if I need to post the code as well.

Thank you in advanced

Regards

Luan
Logged

Earth (I think)
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Based on a quick reading of the datasheet, I don't think the SIM900 supports HTTP. You'll have to establish a TCP connection and then manually negotiate the HTTP.
Logged


South Africa
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Wolfgang

Thank you for the reply.

Do any one of you know where I can find an example on the server side to accept POSTs with PHP, similar than Cosm.
I want to store the data on my own site, Cosm only keeps data for 3 months.

Thank you

In advanced

ttfn

Luan
Logged

South Africa
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All

We got it workig:

Here is the AT comands + output:

Code:
AT+SAPBR=3,1,"APN","internet"
OK

AT+CIFSR
41.15.5.196

AT+CIPSPRT=0
OK

AT+CIPSTART="TCP","www.Mysite.com","80"
OK

CONNEC

AT+CIPSEND
PUT /test/gettempdata.php?TI=19.12&TO=21.75&TR=32.63 HTTP/1.1
Host: www.Mysite.com
Connection: keep-alive


AT+CIPCLOSE
AT+CIPSHUT=0

CLOSE OK


Thank you  smiley
« Last Edit: August 02, 2012, 07:24:23 am by Luan » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Can you please post some code in order to execute this AT command

AT+CIPSEND
PUT /test/gettempdata.php?TI=19.12&TO=21.75&TR=32.63 HTTP/1.1
Host: www.Mysite.com
Connection: keep-alive


BR
Logged

South Africa
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

As requested here is the code on the Arduino
I chanced the code from a Pachube example.

It still needs to be cleaned up and tested a few times.
 

Have a great day

:-)

Code:
void Send2Pachube()
{
  mySerial.println("AT+CGATT?");   //Attach or Detach from GPRS Service (Result  1 = Attach , 2 = Detached )
  delay(300);
  ShowSerialData();
 
  //mySerial.println("AT+CIPMUX=0");
  //delay(300);
  //ShowSerialData();
 
  //mySerial.println("AT+CIPMODE=0");
  //delay(300);
  //ShowSerialData();
 
  mySerial.println("AT+CIPSHUT=0");  //Close TCP Connection
  delay(300);
  ShowSerialData();
 
 
  //mySerial.println("AT+CSTT=\"internet\"");//start task and setting the APN,
  //delay(1000);
  //ShowSerialData();
 
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"internet\"");//setting the APN, the second need you fill in your local apn server
  delay(1000);
  ShowSerialData();
 
  //mySerial.println("AT+CIICR");//bring up wireless connection
  //delay(300);
  //ShowSerialData();
 
  //mySerial.println("AT+CIFSR");//get local IP adress
  //delay(2000);
  //ShowSerialData();
 
  mySerial.println("AT+CIPSPRT=0");
  delay(3000);
  ShowSerialData();
 
  mySerial.println("AT+CIPSTART=\"TCP\",\"www.mysite.com\",\"80\"");//start up the connection

  delay(2000);
  ShowSerialData();
  Serial.println();
  mySerial.println("AT+CIPSEND");//begin send data to remote server
  delay(4500);
  ShowSerialData();
 


  mySerial.print("PUT /test/gettempdatatime.php?");//here is the feed you apply from pachube
  delay(500);
  ShowSerialData();
 
  mySerial.print("TI=");   //DATA feed name
  mySerial.print(GetAVG_TempOnOnePin( A0 ));   //DATA to send
  delay(10);
  ShowSerialData();
 
  mySerial.print("&TO=");   //DATA feed name
  mySerial.print(GetAVG_TempOnOnePin( A1 ));   //DATA to send
  delay(10);
  ShowSerialData();
 
  mySerial.print("&TR=");   //DATA feed name
  mySerial.print(GetAVG_TempOnOnePin( A2 ));   //DATA to send
  delay(10);
  ShowSerialData();
 
  mySerial.print(" HTTP/1.1\r\n");
  delay(500);
  ShowSerialData();
 
  mySerial.print("Host: www.mysite.com\r\n");
  delay(500);
  ShowSerialData();
 

  //mySerial.print("Connection: keep-alive");  //working
  mySerial.print("Connection: close");         //working as well
  mySerial.print("\r\n");
  mySerial.print("\r\n");
  //mySerial.println();
  delay(500);
  ShowSerialData();


  //mySerial.println((char)26);//sending
  mySerial.print(0x1A,BYTE);
  delay(500);//waitting for reply, important! the time is base on the condition of internet
  mySerial.println();
  ShowSerialData();
 
  mySerial.println("AT+CIPCLOSE");//close the connection
  delay(100);
  ShowSerialData();
 
  mySerial.println("AT+CIPSHUT=0");
  delay(100);
  ShowSerialData();
 
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i m workking on a project to send temperature from microcontroller to site , i have created two web pages ,

http://ec4th.jelastic.servint.net/Se...temp&value=100 (here 100 or any value is temperature that is to be updated by module or send by module)




ONLY problem i m facing is to how to POST value to the link .(which can be any value ex.100 )

plz write the whole code from AT+CIPSTART
Logged

South Africa
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi abhi111

All the Arduino code needed to post data is on the previous message at « Reply #5 on: 2013-01-05, 16:40:37 »


Below is my PHP code
Code:
<?
require("dbcon.php");


$sql = 'INSERT into `TempInfo`  (`UNIT_NAME`, `DATE`, `TIME`, `TEMP_IN`, `TEMP_OUT` )
        
        
        VALUES (\''.$_GET['UNIT'].'\',\''.$_GET['DATE'].'\',\''.$_GET['TIME'].'\',\''.$_GET['TI'].'\',\''.$_GET['TO'].'\',\')';

echo $sql;
$result = mysql_query($sql);
?>

I hope this helps
Good luck

Regards

Luan
« Last Edit: April 22, 2013, 03:32:36 am by Luan » Logged

South Africa
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To test your website or PHP code type the following in the address bar and see if it updates your SQL DB.

Code:
http://yoursitename.com/gettempdatatime.php?UNIT=x2&DATE=2012/8/9&TIME=9:8:01&TI=21.6&TO=25.26
« Last Edit: April 22, 2013, 03:33:13 am by Luan » Logged

Johannesburg, South Africa
Offline Offline
Full Member
***
Karma: 0
Posts: 120
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi abhi111

All the Arduino code needed to post data is on the previous message at « Reply #5 on: 2013-01-05, 16:40:37 »


Below is my PHP code
Code:
<?
require("dbcon.php");


$sql = 'INSERT into `TempInfo`  (`UNIT_NAME`, `DATE`, `TIME`, `TEMP_IN`, `TEMP_OUT` )
        
        
        VALUES (\''.$_GET['UNIT'].'\',\''.$_GET['DATE'].'\',\''.$_GET['TIME'].'\',\''.$_GET['TI'].'\',\''.$_GET['TO'].'\',\')';

echo $sql;
$result = mysql_query($sql);
?>

I hope this helps
Good luck

Regards

Luan

This isn't very secure. You should "sanitize" the input and also limit what can be typed in.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
New in Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody!
AT+HTTPPARA="URL","http://domain.hu/feldolgoz.php?sensorPressure=0.13&sensorLevel=233&sensorDate=20130814032310"

I got this. It's working.
But i want to put variable's data in place of bold value.
How can i do this?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How can i do this?

sprintf()
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
New in Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sprintf() okay.
Can u tell me some details?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can u tell me some details?

sprintf()

You'll also need

dtostrf()

for floating point stuff.
« Last Edit: August 14, 2013, 10:41:25 am by Arrch » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
New in Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I can't get how to use it, I'm a beginner in programming.  smiley-confuse
i have:
float va = 0.11;
int vi = 112;
i need to do something like this?
Serial.println("AT+HTTPPARA=\"URL\",\"http://domain.hu/feldolgoz.php?SensorPressure=sprintf(va)&sensorLevel=sprintf(vi)&sensorDate=20130814032310\"");
??
Logged

Pages: [1] 2 3   Go Up
Jump to: