Go Down

Topic: POST HTTP with AT Commands (Read 14 times) previous topic - next topic

Luan

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: [Select]

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: [Select]

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

wolfgang42

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.

Luan

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

Luan

#3
Aug 02, 2012, 02:22 pm Last Edit: Aug 02, 2012, 02:24 pm by Luan Reason: 1
Hi All

We got it workig:

Here is the AT comands + output:

Code: [Select]

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

garreb

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

Luan

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: [Select]

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

}

abhi111

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

Luan

#7
Apr 22, 2013, 10:24 am Last Edit: Apr 22, 2013, 10:32 am by Luan Reason: 1
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: [Select]

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

Luan

#8
Apr 22, 2013, 10:31 am Last Edit: Apr 22, 2013, 10:33 am by Luan Reason: 1
To test your website or PHP code type the following in the address bar and see if it updates your SQL DB.

Code: [Select]

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

RudiAhlers


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: [Select]

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

pappzoli

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?

Arrch


pappzoli

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

Arrch

#13
Aug 14, 2013, 05:39 pm Last Edit: Aug 14, 2013, 05:41 pm by Arrch Reason: 1

Can u tell me some details?


sprintf()

You'll also need

dtostrf()

for floating point stuff.

pappzoli

Sorry I can't get how to use it, I'm a beginner in programming.  :~
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\"");
??

Go Up