Thursday, March 20, 2014

TCP communication over GPRS modem


The following section will explain you the step wise procedure to treat SIM300/SIM900 GPRS modem as a TCP client and send the data to server.prerequisites: SIM300/SIM900 GPRS modem with simcard and TCP server with which you want to establish a connection.
Use the Following AT commands sequentially to get appropriate response.
(The correct response for the respective commands is shown by commented text).

1. AT

//OK

2. AT+CREG?

//+CREG: 0,1

//OK

Description: This command is used for simcard registration.

If you are unable to get proper response for it just check out the input supply voltage of modem or change the simcard and try again.

3. AT+CGATT?

//+CGATT: 1

//OK

Description: This command is used to get the GPRS status.

If you are getting the response as shown above then your GPRS is active

If you are getting +CGATT: 0 then GPRS is inactive.

4. AT+CSTT=”APN”,”username”,”password”

//OK

Description: This command is used to set APN.

APN is provided by simcard manufacturer which is available on internet.

e.g. AT+CGATT=”INTERNET”  (Internet is the APN for idea simcard)

5. AT+CIICR

//OK

Description: This command is used to bring up wireless connection with GPRS

6. AT+CIFSR

//IP (e.g. 153.45.78.2)

Description: This command is used to get local IP Address

7. AT+CIPSTART=”TCP”,”IP”,”PORT”

//OK

//CONNECT OK

Description: This command is used to establish TCP connection with the provided ip address and port.

e.g.  AT+CIPSTART=”TCP”,”192.168.1.35”,”2500”

After connection is establish you will get the above response and you are free to send the data to server.

you can use below commands to send the data to server:

AT+CIPSEND

// >

provide data here after ‘>’ response and press ctrl+z.

or you can use AT+CIPSEND=DataLength for known data length.

e.g AT+CIPSEND=4

ABCD/r/n (No need to provide ctrl+z in this case.)

Note: Use /r/n ( carriage return and new ling) casing after writing each command to the serial port in your code.

e.g AT/r/n.