4

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.

LShaver
  • 841
  • 1
  • 13
  • 28
  • Even if you answer your own question immediately, this sets a bad example for people to assume we are the free alternative to Freelancer.com. I am, unfortunately, going to agree with the going close vote, to protect future me from many more questions that genuinely intend to have us as Google-Code-Monkeys. I hope you can rewrite/regroup your question-answer pair to fit the rules of asking better. – Asmyldof May 05 '16 at 08:50
  • @Asmyldof, with AT commands on the SIM900 there is a very specific answer to this question. Should I edit the question to make it more clear that there really is a very limited set of possible solutions? – LShaver May 05 '16 at 16:39
  • The point of my comment, and joining the close, is that your question reads as here is my problem, fix it. Even if, to the select few that know the AT set, that is not the case. This then invites others who see it to ask similar questions about broader or more complex problems and the maintenance on that is hell on all who try here. We are just preventing the snow ball from rolling faster than we can chase it. If you can narrow down the actual question to fit more inside the rules for asking (specific problem with a description of what has been tried etc), it can be re-opened and/or protected. – Asmyldof May 05 '16 at 17:43
  • @Asmyldof that makes sense. I made some edits - how does it look now? – LShaver May 06 '16 at 01:28
  • Much better! Consider this your first re-open vote. – Asmyldof May 06 '16 at 09:15

2 Answers2

10

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.

LShaver
  • 841
  • 1
  • 13
  • 28
  • 1
    just run `AT+HTTPPARA="CONTENT","application/x-www-form-urlencoded" ` before `AT+HTTPDATA=137,20000` and its good to go – alex Jul 14 '17 at 04:34
0
AT

AT+CIPSHUT

AT+CGDCONT=1,"IP","www"

AT+CSTT="www","","" 

AT+CIICR

AT+CIFSR

AT+CIPSHUT

AT+CIPHEAD=1

AT+CIPSTART="tcp","52.66.122.8","8000" 

AT+CIPSEND

POST http://52.66.122.8 HTTP/1.1(ctrl+m)(ctrl+j)

Host: 52.66.122.8:8000(ctrl+m)(ctrl+j)

User-Agent:curl/7.47.0(ctrl+m)(ctrl+j)

Content-Length:11 (ctrl+m)(ctrl+j)

Content-Type:application/x-www-form-urlencoded(ctrl+m)(ctrl+j)(ctrl+j)

data=ramesh(ctrl+z)

You will get responce successfully here.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60