POST HTTP with AT Commands

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:

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

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

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.

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

Hi All

We got it workig:

Here is the AT comands + output:

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 :)

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

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

:-)

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();

}

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

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

<?
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

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

http://yoursitename.com/gettempdatatime.php?UNIT=x2&DATE=2012/8/9&TIME=9:8:01&TI=21.6&TO=25.26

Luan:
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

<?

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.

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?

pappzoli: How can i do this?

sprintf()

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

pappzoli: Can u tell me some details?

sprintf()

You'll also need

dtostrf()

for floating point stuff.

pappzoli: i need to do something like this?

No. You're not using either of the two functions I listed. Look at the examples in the links. Your checklist should be:

Declare an array large enough to hold the float's string. Use dtostrf() to convert the float into a string Declare an array large enough to hold your entire string Use sprintf() to construct the string.

Furthermore, code should be posted using CODE tags.

char link[128];
sprintf(&link,  "AT+HTTPPARA=\"URL\",\"http://domain.hu/feldolgoz.php?sensorPressure=%f&sensorLevel=%d\"",va,vi);

Is it better?

pappzoli: Is it better?

Better, but still not correct. Why are you giving it the address of a pointer? Array's are already pointers, and sprintf() is expecting a pointer, not the pointer's reference. Arduino's modified libraries also don't include the %f format specifier, which is why I suggested using dtostrf().

i think its good

Except for the whole String object part.

why?

pappzoli: why?

http://www.gammon.com.au/forum/?id=12112