Vous êtes sur la page 1sur 19

9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

 ravi@valetron.com (mailto:ravi@valetron.com)

(/)  

SIM900 GPRS HTTP AT Commands - Jump to


SIM900/SIM800 HTTP POST request
 Ravi Pujar  28 January 2018

SIM900 GPRS HTTP AT Commands (/embedded/194-sim900-gprs-http-at-commands?


showall=&start=0)

Jump to SIM900/SIM800 HTTP POST request (/embedded/194-sim900-gprs-http-at-


commands?showall=&start=1)

All Pages (/embedded/194-sim900-gprs-http-at-commands?showall=1&start=0)

Page 2 of 2

 Uploading a file to the server using HTTP POST

We will upload a file to the server using HTTP POST multipart/form-data method. You can
search in google for more information on multipart/form-data method of sending data in
HTTP POST. In this method the POST variables are sent between demarcation strings called
boundary.
The server will be told before what boundary will demarcate our data in the HTTP header. In
our case below our Boundary string is  ----WebKitFormBoundaryvZ0ZHShNAcBABWFy.
Here we are using the Henry's HTTP POST Dumping server available at the
url http://www.posttestserver.com/ (http://www.posttestserver.com/) .

The URL where you need to POST the variables is http://posttestserver.com/post.php


(http://posttestserver.com/post.php).

Whatever data you post at this url is available at the url http://posttestserver.com/data


(http://posttestserver.com/post.php) .

Lets get started and when we are already allocated a IP address, now we can proceed
by enabling the HTTP mode
AT+HTTPINIT

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 1/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

OK

OPTIONAL,  ONLY IF URL is HTTPS or SSL enabled: Also Remove the http:// part in the
HTTPPARA="URL",xxxx command
AT+HTTPSSL=1
OK

 
Start by setting up the HTTP bearer profile identifier
AT+HTTPPARA="CID",1
OK
 
Set the url to the address of the webpage you want to post to
AT+HTTPPARA="URL","http://posttestserver.com/post.php"
OK
 
Set the Content as multipart/form-data type of HTTP POST and also set the boundary value
AT+HTTPPARA="CONTENT","multipart/form-data; boundary=----
WebKitFormBoundaryvZ0ZHShNAcBABWFy"
OK 
 
Tell the module that you will be sending 192 bytes of data and it can timeout after 10 seconds of inactivity. After this command you
get the DOWNLOAD URC then you can type in 192 bytes of data within 10 seconds. The typed data is filled in a local buffer of the
module and is not yet posted to the server. In the post body is the multi part form data which contains the necessary headers and
data to post a file with name data.txt with 10 bytes of data Hello Ravi
AT+HTTPDATA=192,10000
OK
DOWNLOAD
 
------WebKitFormBoundaryvZ0ZHShNAcBABWFy
Content-Disposition: form-data; name="fileToUpload"; filename="data.txt"
Content-Type: text/plain
 
Hello Ravi
 
------WebKitFormBoundaryvZ0ZHShNAcBABWFy
OK
 
Execute the HTTP POST command so that the buffer contents are POST to the server
AT+HTTPACTION=1
OK
 

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 2/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

This URC means that the data was successfully posted to the server and a received a data of 141 bytes which is the server
response to your HTTP POST
+HTTPACTION:1,200,141
 
The below command tells the module that we want to read the received data
AT+HTTPREAD
The below is the data received from the server
+HTTPREAD:141
Successfully dumped 0 post variables.
View it at http://www.posttestserver.com/data/2015/10/07/07.41.291690063480
Post body was 0 chars long.
OK
 
After this you can see the uploaded file at the above URL. Note: The data length to be
uploaded is very strict here and needs to be carefully calculated. So i wrote the below script
which can be RUN on Windows and Linux using GCC. Also make sure you set the correct
COM port in Windows and right tty/USBx device in Linux You can modify according to your
use. Watch the video above to get more idea. This code also needs the RS232.c Library  which
you can find here >> Serial Port programming in Linux using C - Working code
(/embedded/189-serial-port-programming-in-linux-using-c-working-code) 

 
demo_tx.c

(https://www.raviyp.com/plugins/content/highlight_code/highlight/vista_p

#include <stdlib.h> #include <stdio.h> #ifdef _WIN32 #include <Windows.h> #else #inclu

This is applicable to SIM900/SIM900A/SIM900D and SIM800 GSM module also. 

Watch this video if you want to see the live demo (https://youtu.be/QsNcfxc8YSA),

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 3/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

(https://youtu.be/QsNcfxc8YSA)

Hope it helps someone. 

Also see:

SIM900 DTMF commands (/embedded/191-sim900-dtmf-commands)


SIM900 & SIM908 GSM module - Autobaud rate [Solution] (/embedded/183-sim900-
sim908-gsm-module-autobaud-solution)
SIM900 SMS and Call Commands (/embedded/182-sim900-sms-call-commands)
SIM900 / SIM800 USSD Code AT Commands - Working example (/embedded/190-sim900-
sim800-ussd-code-at-commands-working-example)

ZTEX FPGA Boards


with EZ-USB FX2 and FX3
Easy-to-use, Open Source, USB 3.0 or 2.0, RAM, Flash, a lot of GPIO's

ztex.de OPEN

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 4/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

<< Prev (/embedded/194-sim900-gprs-http-at-commands?showall=&start=0) Next

67 Comments Embedded World 


1 Login

Sort by Best
 Recommend ⤤ Share

Join the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

divum • 2 years ago


Hi Ravi ,

How can i check the Device flash size.

I am using SIM900A ,HTTP commands are working fine But


HTTPS is not working..My device flash size is 32MB...Please
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 5/19
9/2/2018
g y Jump to SIM900/SIM800 HTTP POST request - Page 2
kindly let me know the solution....
19 △ ▽ • Reply • Share ›

Muzzamil Shahid • 2 years ago


hi ravi!
kindly guide me how to read (GET) and upload values (POST)
using HTTP AT commands in JSON format?
kindly mention it in proper sequence?
4△ ▽ • Reply • Share ›

Udita Dua > Muzzamil Shahid • 7 months ago


hey, even i have the same question. could you find how
to do that ?
△ ▽ • Reply • Share ›

Ravi Pujar Mod > Udita Dua • 6 months ago


Hi Udit,
Please post your tech queries here.
http://www.embeddedadvice.com/
We can discuss
△ ▽ • Reply • Share ›

nada shata > Ravi Pujar • 2 months ago


i have the same question too,is there a
post explaining that sequence?
△ ▽ • Reply • Share ›

Bunny • a year ago


Hello Ravi,

Am sending the data to the URL from my logger using SIM900


module with POST method. But as on the server side, the data
is receiving in binary format.

How can i send data in text fomat? so on the server side no


need to encode the data.

And thanks for your blog. Very helpful.


2△ ▽ • Reply • Share ›

Ravi Pujar Mod > Bunny • a year ago

Hi Venkat,
Thank you :)
By default it will be in text or ascii format unless you
encode it.
I dont understand where the data is getting converted to
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 6/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2
binary. Could you please explain more?
△ ▽ • Reply • Share ›

Bunny > Ravi Pujar • a year ago


Thanks for your reply.

I have using sprintf to make buffer with the


variables i have to send. An d those buffer is
posted to server. As sever part located in some
other location. The person handling the server,
reverted me as the data receiving in binary
format.

Please find the below code.

sprintf(_buffer, "#;%s;%d-%d-
%d;%d:%d;%f;%f",imei,(uint16_t)rtc.year,
(uint16_t)rtc.month,(uint16_t)rtc.date,
(uint16_t)rtc.hour,(uint16_t)rtc.min,temp,humid);

HTTP_Post(_buffer, responseLength);

FYI, am using my embedded device as a logger


and posting the data.
Format is
#;<imei>;<date>;<time>;<temp>;<humid>
△ ▽ • Reply • Share ›

Amarendra Ranade • 15 days ago


Hello..
I am trying to post using same method as you have mentioned.
After HTTPACTION=1 command, I am getting error 500 (internal
Server Error). What can be the issue ?

Below is the Request Body. Is there any issue in this part ?

---------------------------acebdf13572468
Content-Disposition: form-data; name="fieldNameHere";
filename="nogithub.txt"
Content-Type: text/plain

QWERTY

---------------------------acebdf13572468--

Awaiting your reply. Thanks in Advance.


△ ▽ • Reply • Share ›

Gayatri Vedula • 4 months ago

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 7/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

i m getting this while working on http requests using gsm 900a


AT+HTTPINIT
ERROR
can you suggest me in resolving the error
△ ▽ • Reply • Share ›

Shreevatsa Acharya > Gayatri Vedula • a month ago


hey , even i am getting the same error, did you find a
solution or why the error?
△ ▽ • Reply • Share ›

mohammad • 4 months ago


Hi Ravi
topic is very useful for me .
I have a problem with URL length , my URL is too long . when i
use "AT+HTTPPARA" it respond with ERROR .
the URL length is about 1000 chars .
How can i fix this problem ?
△ ▽ • Reply • Share ›

usmanhaider • 5 months ago


it gives 401 error
△ ▽ • Reply • Share ›

usmanhaider • 5 months ago


i gives 401 error
△ ▽ • Reply • Share ›

naresh puli • 6 months ago


Hello,
how we write data to the server using http commands using GET
Method

after connection establish, please suggest me


△ ▽ • Reply • Share ›

Ravi Pujar Mod > naresh puli • 6 months ago

Hi Naresh,
Please post your tech queries here.
http://www.embeddedadvice.com/
We can discuss
△ ▽ • Reply • Share ›

bhaskar ch • 6 months ago


hi Ravi, i am new to WEB server application. need to send data
to web server through GSM(SIM808). i dont have any url(web
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 8/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2
g ( ) y (
service) for testing get/post method. how can i get URL for
sending data
△ ▽ • Reply • Share ›

Ravi Pujar Mod > bhaskar ch • 6 months ago


Hi Bhaskar,
Please post your tech queries here.
http://www.embeddedadvice.com/
We can discuss
△ ▽ • Reply • Share ›

manisrinivas srungavarapu • 7 months ago


hi ravi ,
your blogs very good and helpful.we are getting response like
0,200,677 something like this from httpaction ,but how can i
store the value 200 in some variable ,200 means http connection
is fine.thank you
△ ▽ • Reply • Share ›

Ravi Pujar Mod > manisrinivas srungavarapu


• 7 months ago
Hi, Please post tech queries here.
http://www.embeddedadvice.com/
We can discuss
△ ▽ • Reply • Share ›

Egauss Egauss • 8 months ago


Hi Ravi, i have sim808 and looking for advice how to GET http
headers have you got any solution?
△ ▽ • Reply • Share ›

Daniel • 9 months ago


Hello Ravi,
Is it also possible to upload a csv file to webserver as you did
with txt file?
What is the maximum size of csv file that can be sent using
HTTP Post with sim900? I think there is a limitation caused the
buffer of the sim900, right?

Best regards, Daniel


△ ▽ • Reply • Share ›

Ravi Pujar Mod > Daniel • 9 months ago

Hi Daniel,
Please post tech queries here,
http://www.embeddedadvice.com/
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 9/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

We can discuss.
△ ▽ • Reply • Share ›

Bunny • 9 months ago


Hi Ravi,

How to get a timestamp fro a server? Is there HTTP command


request to get the time and date?
△ ▽ • Reply • Share ›

Ravi Pujar Mod > Bunny • 9 months ago

Hi Venkat,

Could you please post your query here.


http://www.embeddedadvice.com/
We can discuss further.

Regards,
Ravi
△ ▽ • Reply • Share ›

Sayajin_Slayer • 9 months ago


hello, can you help me? i just can't figure this out
check my code
#include <softwareserial.h>
#include <tinygps.h>
#include <wire.h>
#include <ds1307new.h>

#define pinPowerSIM900 9

TinyGPS gps;
SoftwareSerial sGPS(10,9);

float flat, flon;


float previousFLat = 0.0;
float previousFLon = 0.0;

void setup() {
pinMode(pinPowerSIM900, OUTPUT);
digitalWrite(pinPowerSIM900,LOW);
see more

△ ▽ • Reply • Share ›

Tejas Arlimatti • a year ago


Thank you, very helpful
△ ▽ • Reply • Share ›
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 10/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

Tumza • a year ago


Can you send instead of reading?
△ ▽ • Reply • Share ›

sameer ahamad • a year ago


Dear Ravi,
my self Sameer ,
i was connecting gsm/gprs sim 900a module to raspberry pi2 but
iam unable to post the data from Raspberrypi2 using HTTP AT
commands but the data posting in the server as emty ,how we
have to send the data as variables in python by Using HTTP
commands could you please provide me with more details,
△ ▽ • Reply • Share ›

Ravi Pujar Mod > sameer ahamad • a year ago


Hi Sameer,
I have not used Raspberry pi and python so far. I cant
help much on that. But if you are getting OK responses
from SIM900A then communication should be just fine.
You should enter correct data length for proper packet
delivery in HTTPDATA command.
△ ▽ • Reply • Share ›

sameer ahamad > Ravi Pujar • a year ago


Dear Ravi,
i was connecting gsm/gprs sim 900a module to
raspberry pi2 but iam post the data from
Raspberrypi2 using HTTP AT commands but the
data posting in the server as emty ,
1)how we have to send the data as variables in
python by Using HTTP commands ,can you send
the exact syntax of URL HTTP Post in variable
2)in here HTTPget and post method was can be
work simultaneously when we establish the
connection of GPRS is that necessary to run the
hole commands are simply use HTTPPARA to
transfer the data 3)how to get the imei number
sim900 in a variable
can u send the arduino coding
could you please provide me with more details,
△ ▽ • Reply • Share ›

Ravi Pujar Mod > sameer ahamad


• a year ago
Dear Sameer,
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 11/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

As i said i have no idea on python. Never


used it.
The only code i have is as shown above. It
works on Linux.
You can modify it to python or arduino as it
is simple c program.
You can get IMEI number using the
command AT+CGSN
HTTPPARA is only used to set the
parameters and HTTPDATA is used to set
the data part. The data is sent only when
you execute AT+HTTPACTION command.
Hope it helps.
△ ▽ • Reply • Share ›

sameer ahamad > Ravi Pujar


• a year ago
Dear Ravi,
i have trying to post data using coolterm
win software but iam getting error in that
can u tell me what means of this
1.AT+HTTPPARA="CONTENT","multipart/fo
data; boundary=----
WebKitFormBoundaryvZ0ZHShNAcBABWF
2.AT+HTTPDATA=192,10000 i was totally
struck in this issue

see more

△ ▽ • Reply • Share ›

Ravi Pujar Mod > sameer ahamad


• a year ago
+SAPBR DEACT means your network
internet got disconnected. Use good
network SIM like Airtel or Vodafone. Idea
and Docomo and others wont work
properly.
You need to enter data within 10 seconds
there or it will get timeout
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 12/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2
there or it will get timeout
△ ▽ • Reply • Share ›

sameer ahamad > Ravi Pujar


• a year ago
Dear Ravi sir,
i have doubt about is that any sim 900
gsm/gprs module to setup the GPRS
connection time gap need between one AT
Commands other in Ardunio , is that really
required are not, clarify to me for this issue
△ ▽ • Reply • Share ›

sameer ahamad > Ravi Pujar


• a year ago
Dear Ravi sir,
which HTTP AT commands pass the
variable data of particular column
database in My Sql server
is that HTTPPARA are HTTPDATA,
AT+HTTPPARA="CONTENT","vr=1234" i
was unable send data to the database
△ ▽ • Reply • Share ›

ashok • a year ago


Hi Ravi,
I am Using maestro 100 lite gsm/gprs device in my project.
In hyper terminal AT+SAPBR=3,1,"CONTYPE","GPRS" it's
giving error response.
Please help me about the problem.

Thanks in advance.
△ ▽ • Reply • Share ›

amin • a year ago


hi ravi.
i get ok for all command but not for AT+HTTPACTION=0
it returns +HTTPACTION: 0,601,0
how should i fix it?

this is all my code :

AT+SAPBR=3,1,"Contype","GPRS"

AT+SAPBR=3,1,"APN","mtnirancell"

AT+SAPBR=1,1

AT+SAPBR=2,1
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 13/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

AT+SAPBR=0,1

//get

AT+HTTPINIT

AT+HTTPPARA = "CID",1

AT+HTTPPARA="URL","www.sim.com"

AT+HTTPACTION=0

AT+HTTPREAD

AT+HTTPTERM
△ ▽ • Reply • Share ›

Amin Hajihosseinlu • a year ago


Hi Ravi,

Thank you in advanced for your great tutorial.


After a week of troubleshooting I am going to ask for your help. I
am pretty newbie in wireless networks and gsm modules.

I follow the instructions; everything works very well and I get a


valid IP address.
After sending the command "AT+HTTPACTION=0" to read
random string from a website (e.g. https://www.google.ca), either
I receive the 601 error or the module restarts. (See the code
below)

_______________________________________________
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+SAPBR=3,1,"APN","internet.com"
see more

△ ▽ • Reply • Share ›

Ankit Kekre • a year ago


Hii Ravi!
Your post has been a great help. although I have ran into some
trouble while using this method for posting some data to the
above mentioned site using Arduino.
The problem is that i don't exactly have a text file to post. Just
some text and values. Can you please tell me some method to
do that? Thanx in advance.
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 14/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

△ ▽ • Reply • Share ›

Ankit Kekre > Ankit Kekre • a year ago


Ok I got it. After a lot of searching, I used the
application/x-www-form-urlencoded to send the data as
URL parameters
△ ▽ • Reply • Share ›

gowtham bieber • a year ago


Hi I,m gowtham and i'm getting error while using the above post
commands
AT+SAPBR=3,1,"APN","aircelgprs.pr"
OK
AT+SAPBR=1,1
OK
AT+SAPBR=1,1
ERROR
AT+SAPBR=2,1
+SAPBR: 1,1,"100.68.229.191"

OK
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="URL","http://posttestserver.com/p..."
OK
AT+HTTPPARA="CONTENT","multipart/form-data; boundary=---
-WebKitFormBoundaryvZ0ZH
ShNAcBABWFy"
OK
AT+HTTPDATA=192,10000
DOWNLOAD

ERROR
△ ▽ • Reply • Share ›

Deepanshu Biyani • a year ago


i am getting error in these commands,

Start by setting up the HTTP bearer profile identifier


AT+HTTPPARA="CID",1
ERROR

Set the url to the address of the webpage you want to post to
AT+HTTPPARA="URL","http://posttestserver.com/p..."
ERROR
https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 15/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

△ ▽ • Reply • Share ›

Chitraveer Akhil • 2 years ago


Hi, I'm trying to post data from Arduino to the server using AT
commands.. I used HTTP connections.. But the data is not send
to the server.. Please check my code..

AT+CGATT=1

OK
AT+SAPBR=3,1,"Contype","GPRS"

OK
AT+SAPBR=3,1,"APN","airtelgprs.com"

OK
AT+SAPBR=1,1

OK
AT+SAPBR=2,1

+SAPBR: 1,1,"100.100.97.117"

see more

△ ▽ • Reply • Share ›

back to top

 Facebook (http://www.facebook.com/sharer.php?u=https://www.raviyp.com/embedded/194-
sim900-gprs-http-at-commands)

 Twitter (http://twitter.com/share?url=https://www.raviyp.com/embedded/194-sim900-gprs-http-
at-commands&text=SIM900%20GPRS%20HTTP%20AT%20Commands%20-
%20Jump%20to%20SIM900/SIM800%20HTTP%20POST%20request)

 (https://plus.google.com/share?url=https://www.raviyp.com/embedded/194-sim900-gprs-http-at-
commands)

 (http://www.linkedin.com/shareArticle?mini=true&url=https://www.raviyp.com/embedded/194-
sim900-gprs-http-at-commands)

 

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 16/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

About the Author


Ravi Pujar
(https://plus.google.com/102969188306424582103)
is the author of this blog and is an
Embedded systems design engineer by
profession & Founder @ Valetron
Systems Pvt Ltd
(http://www.valetron.com)

(https://plus.google.com/102969188306424582103)

Email:ravi@valetron.com
(mailto:ravi@valetron.com)

Find us on Google+
(https://plus.google.com/104907583360502363516)
HIRE ME FOR YOUR PROJECT AS A
FREELANCER
Ravi Pujar

YouTube 2K

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 17/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

Enter your Email Address

Subscribe

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 18/19
9/2/2018 Jump to SIM900/SIM800 HTTP POST request - Page 2

Embedded World
7.1K likes

Like Page

Be the first of your friends to like this

© 2017 Valetron Systems Pvt Ltd. All Rights Reserved.

https://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands?showall=&start=1 19/19

Vous aimerez peut-être aussi