Posting to php server using SIM900 GPRS with AT commands

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I am using a SIMCOM SIM900 GSM/GPRS module in an embedded hardware application. Rather than sending device data to a server by SMS (what I've been doing so far) I want to switch and start using GPRS to post data to a server with a PHP script I've written.

The SIM900 literature (pdf) is abysmal. Section 13 gives an example sequence for connecting GPRS, which I've pieced together with a few other bits, but I can't get it working:

*COMMAND*           *RESPONSE*  *COMMENT*
ATD*99#             CONNECT     Establish connection
AT+CGATT?           +CGATT:1    Check connection
AT+CGDCONT=1,"IP"   OK          Set context
AT+HTTPINIT         OK          Enable HTTP mode
AT+HTTPPARA="URL","www.google.com"
                    OK          Set the address
AT+HTTPDATA="data"  OK          Send some data

I am getting the expected responses, but nothing happens after the last step.

profilepic.png
manpreet 2 years ago

After much googling and mashing together various answers, I got it working.

Here's the AT command sequence. You can test this from start to finish, you'll just need to confirm the APN of the carrier you're using.

// My comments are here
Command to send is here             Expected responses are here

// See if the SIM900 is ready
AT                                  OK

// SIM card inserted and unlocked?
AT+CPIN?                            +CPIN: READY
                                    OK

// Is the SIM card registered?
AT+CREG?                            +CREG: 0,1
                                    OK

// Is GPRS attached?
AT+CGATT?                           +CGATT: 1
                                    OK

// Check signal strength - should be 9 or higher
AT+CSQ                              +CSQ: 14,0
                                    OK

// Set connection type to GPRS
AT+SAPBR=3,1,"Contype","GPRS"       OK

// Set the APN - this will depend on your network/service provider
AT+SAPBR=3,1,"APN","wholesale"      OK

// Enable GPRS - this will take a moment or two
AT+SAPBR=1,1                        OK

// Check to see if connection is correct and get your IP address
// (I hid mine here, but you'll get a real IP back)
AT+SAPBR=2,1                        +SAPBR: 1,3,"0.0.0.0"
                                    OK

// Enable HTTP mode
AT+HTTPINIT                         OK

// Set HTTP profile identifier
AT+HTTPPARA="CID",1                 OK

// Put in the URL of the PHP webpage where you will post - 
// the URL below is a test server so you can use it in testing
AT+HTTPPARA="URL","http://posttestserver.com/post.php"
                                    OK

// Tell the SIM900 how much data you'll send (18 bytes here) 
// and how long to wait for a time-out (10,000 ms here)
AT+HTTPDATA=18,10000                DOWNLOAD

// Key in the data you want to send after you get the "DOWNLOAD" prompt.
vdc=12&adc=3&rel=8                  OK

// Post the data - wait a second for the response
AT+HTTPACTION=1                     OK
                                    +HTTPACTION:1,200,142

// Read the response - www.posttestserver.com will give you a 
// URL where you can confirm that it's working
AT+HTTPREAD                         +HTTPREAD:142

"Successfully dumped 0 post variables. View it at 
http://www.posttestserver.com/data/2016/04/28/14.19.041655610622
Post body was 18 chars long."
                                    OK

// Close the HTTP connection
AT+HTTPTERM                         OK

// Disconnect the GPRS
AT+SAPBR=0,1                        OK

Edit to add: Here are the sources I used to put all of this together, along with help from some folks I asked in my lab.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community