TCP connection over GPRS using SIM900 and similar modems using AT commands

GSM/GPRS modems are getting very common these days, as prices are getting cheaper and cheaper. Apart from providing SMS and call functions to my projects I also wanted to communicate via TCP.

Although there are many documents and blog posts to help but I have always found that they either are answers to specific problem faced by someone or not providing complete details.  In this post I would first explain the AT commands used in brief. You may connect your SIM900 to your computer via a serial/usb and test these commands. In the later part of this post I would include arduino example code.

AT commands for TCP/UDP Connection with example response and a brief description are given in the table below. Refer to the AT commands manual of your modem for details

AT command Response Description
AT  OK test command. reply is OK
AT+CGATT?  +CGATT:n checks if GPRS is attached? n=1 if attached
AT+CIPMUX=n  OK use n as 0 for single connection
or use 1 for multiple connections
AT+CSTT=”apn”,”username”,”pass” OK Sets APN, user name and password
AT+CIICR  OK Brings up wireless connection
AT+CIFSR  ip address Get local IP address if connected
AT+CIPSTART=“TYPE” , “domain”, “port”  Connected Establishes a connection with a server. Type can be UDP or TCP
AT+CIPSEND  > Sends data when the a connection is established.
AT+CIPCLOSE  OK Closes the connection
AT+CIPSHUT  SHUT OK resets IP session if any

how to make a connection:

  1. Send ATr and wait for a response from the modem. You should recieve OK
    if everything is set.
  2. Make sure that the Modem has registered to network and that PIN code is disabled on the SIM. Send AT+CGATT?r to check if GPRS is attached or not.  +CGATT: 1 indicates that GPRS is attached.
  3. Send AT+CIPSHUTr . Although its optional this will be helpful as it resets IP session if any. you will get a response SHUT OK .
  4. Send AT+CIPMUX=0 to set a single connection mode, response would be OK
  5. Now set APN settings by AT+CSTT= “apn ”, “username”, “password”r . replace apn, username and password to match APN (Access Point Name) ,username and password for your service provider.
  6. Now send AT+CIICRr , this will bring up the wireless connection. OK is received on successful connection
  7. Send AT+CIFSRr , this will reply with the IP address the modem has been assigned.
  8. Send AT+CIPSTART=”TCP”,”server domain name or ip”,”port”r, replace the domain name/ip and port with appropriate values, on connection modem will reply with CONNECT OK
  9. Now you can send your data using AT+CIPSENDr  AT command. modem will respond with > indicating it is ready to receive data to be sent. Type in your data.
  10. Now the modem is waiting for the ASCII 26  that is control+z on keyboard. Depending on the terminal software used you can either press control and Z together on keyboard or send hex value 0x1A. The modem will then send the response from server.
  11. Now send AT+CIPSHUT to shut down the connection. Modem will reply with SHUT OK 
  12. cheers 🙂

ARDUINO CODE :

Below is example code for single and multiple connection using arduino and sim900

int8_t answer;
int onModulePin= 2;
char aux_str[50];
char ip_data[40]="Test string from GPRS shieldrn";
void setup(){
    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);
    Serial.println("Starting...");
    power_on();
    delay(3000);
    // sets the PIN code
    sendATcommand2("AT+CPIN=****", "OK", "ERROR", 2000);
    delay(3000);
    Serial.println("Connecting to the network...");
    while( sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000)== 0 );
}
void loop(){
    // Selects Single-connection mode
    if (sendATcommand2("AT+CIPMUX=0", "OK", "ERROR", 1000) == 1)
    {
        // Waits for status IP INITIAL
        while(sendATcommand2("AT+CIPSTATUS", "INITIAL", "", 500)  == 0 );
        delay(5000);

        // Sets the APN, user name and password
        if (sendATcommand2("AT+CSTT="APN","user_name","password"", "OK",  "ERROR", 30000) == 1)
        {
            // Waits for status IP START
            while(sendATcommand2("AT+CIPSTATUS", "START", "", 500)  == 0 );
            delay(5000);

            // Brings Up Wireless Connection
            if (sendATcommand2("AT+CIICR", "OK", "ERROR", 30000) == 1)
            {
                // Waits for status IP GPRSACT
                while(sendATcommand2("AT+CIPSTATUS", "GPRSACT", "", 500)  == 0 );
                delay(5000);

                // Gets Local IP Address
                if (sendATcommand2("AT+CIFSR", ".", "ERROR", 10000) == 1)
                {
                    // Waits for status IP STATUS
                    while(sendATcommand2("AT+CIPSTATUS", "IP STATUS", "", 500)  == 0 );
                    delay(5000);
                    Serial.println("Openning TCP");

                    // Opens a TCP socket
                    if (sendATcommand2("AT+CIPSTART="TCP","IP_address","port"",
                            "CONNECT OK", "CONNECT FAIL", 30000) == 1)
                    {
                        Serial.println("Connected");

                        // Sends some data to the TCP socket
                        sprintf(aux_str,"AT+CIPSEND=%d", strlen(ip_data));
                        if (sendATcommand2(aux_str, ">", "ERROR", 10000) == 1)
                        {
                            sendATcommand2(ip_data, "SEND OK", "ERROR", 10000);
                        }

                        // Closes the socket
                        sendATcommand2("AT+CIPCLOSE", "CLOSE OK", "ERROR", 10000);
                    }
                    else
                    {
                        Serial.println("Error openning the connection");
                    }
                }
                else
                {
                    Serial.println("Error getting the IP address");
                }
            }
            else
            {
                Serial.println("Error bring up wireless connection");
            }
        }
        else
        {
            Serial.println("Error setting the APN");
        }
    }
    else
    {
        Serial.println("Error setting the single connection");
    }

    sendATcommand2("AT+CIPSHUT", "OK", "ERROR", 10000);
    delay(10000);
}

void power_on(){

    uint8_t answer=0;

    // checks if the module is started
    answer = sendATcommand2("AT", "OK", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);

        // waits for an answer from the module
        while(answer == 0){     // Send AT every two seconds and wait for the answer
            answer = sendATcommand2("AT", "OK", "OK", 2000);
        }
    }

}

int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
        char* expected_answer2, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '', 100);    // Initialize the string

    delay(100);

    while( Serial.available() > 0) Serial.read();    // Clean the input buffer

    Serial.println(ATcommand);    // Send the AT command

    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial.available() != 0){
            response[x] = Serial.read();
            x++;
            // check if the desired answer 1  is in the response of the module
            if (strstr(response, expected_answer1) != NULL)
            {
                answer = 1;
            }
            // check if the desired answer 2 is in the response of the module
            else if (strstr(response, expected_answer2) != NULL)
            {
                answer = 2;
            }
        }
    }
    // Waits for the asnwer with time out
    while((answer == 0) && ((millis() - previous) < timeout));

    return answer;
}
int8_t answer;
int onModulePin= 2;
char aux_str[50];

char ip_data[40]="Test string from GPRS shieldrn";

void setup(){

    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);

    Serial.println("Starting...");
    power_on();

    delay(3000);

    // sets the PIN code
    sendATcommand2("AT+CPIN=****", "OK", "ERROR", 2000);

    delay(3000);

    Serial.println("Connecting to the network...");

    while( sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000) == 0 );

}


void loop(){


    // Selects Multi-connection mode
    if (sendATcommand2("AT+CIPMUX=1", "OK", "ERROR", 1000) == 1)
    {
        // Waits for status IP INITIAL
        while(sendATcommand2("AT+CIPSTATUS", "INITIAL", "", 500)  == 0 );
        delay(5000);

        // Sets the APN, user name and password
        if (sendATcommand2("AT+CSTT="APN","user_name","password"", "OK",  "ERROR", 30000) == 1)
        {
            // Waits for status IP START
            while(sendATcommand2("AT+CIPSTATUS", "START", "", 500)  == 0 );
            delay(5000);

            // Brings Up Wireless Connection
            if (sendATcommand2("AT+CIICR", "OK", "ERROR", 30000) == 1)
            {
                // Waits for status IP GPRSACT
                while(sendATcommand2("AT+CIPSTATUS", "GPRSACT", "", 500)  == 0 );
                delay(5000);

                // Gets Local IP Address
                if (sendATcommand2("AT+CIFSR", ".", "ERROR", 10000) == 1)
                {
                    // Waits for status IP STATUS
                    while(sendATcommand2("AT+CIPSTATUS", "IP STATUS", "", 500)  == 0 );
                    delay(5000);
                    Serial.println("Openning TCP");

                    // Opens a TCP socket with connection 1
                    if (sendATcommand2("AT+CIPSTART=1,"TCP","IP_address","port"",
                                    "CONNECT OK", "CONNECT FAIL", 30000) == 1)
                    {
                        Serial.println("Connected");

                        // Sends some data to the TCP socket
                        sprintf(aux_str,"AT+CIPSEND=1,%d", strlen(ip_data));
                        if (sendATcommand2(aux_str, ">", "ERROR", 10000) == 1)
                        {
                            delay(500);
                            sendATcommand2(ip_data, "SEND OK", "ERROR", 10000);
                        }

                        // Closes the socket
                        sendATcommand2("AT+CIPCLOSE=1", "CLOSE OK", "ERROR", 10000);
                    }
                    else
                    {
                        Serial.println("Error openning the connection 1");
                    }

                }
                else
                {
                    Serial.println("Error getting the IP address");
                }
            }
            else
            {
                Serial.println("Error bring up wireless connection");
            }
        }
        else
        {
            Serial.println("Error setting the APN");
        }
    }
    else
    {
        Serial.println("Error setting the multi-connection");
    }

    sendATcommand2("AT+CIPSHUT", "OK", "ERROR", 10000);
    delay(10000);
}

void power_on(){

    uint8_t answer=0;

    // checks if the module is started
    answer = sendATcommand2("AT", "OK", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);

        // waits for an answer from the module
        while(answer == 0){     // Send AT every two seconds and wait for the answer
            answer = sendATcommand2("AT", "OK", "OK", 2000);
        }
    }

}

int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
        char* expected_answer2, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '', 100);    // Initialize the string

    delay(100);

    while( Serial.available() > 0) Serial.read();    // Clean the input buffer

    Serial.println(ATcommand);    // Send the AT command

    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial.available() != 0){
            response[x] = Serial.read();
            x++;
            // check if the desired answer 1  is in the response of the module
            if (strstr(response, expected_answer1) != NULL)
            {
                answer = 1;
            }
            // check if the desired answer 2 is in the response of the module
            else if (strstr(response, expected_answer2) != NULL)
            {
                answer = 2;
            }
        }
    }
    // Waits for the asnwer with time out
    while((answer == 0) && ((millis() - previous) < timeout));

    return answer;
}

 
Dost Muhammad Shah

Dost Muhammad Shah

Dost Muhammad specializing in Embedded Design, Firmware development, PCB designing , testing and prototyping. He enjoys sharing his experience with others .Get in touch with Dost on Twitter or via Contact form

 

144 thoughts on “TCP connection over GPRS using SIM900 and similar modems using AT commands

  1. is there any way to maintain continuous reception of msgs from server by making sim 800c as client. in my case, module is hanging after 5 msgs received from server

  2. Hello
    the code posted in this topic doesn’t have the declaration of the sim gsm module, so when i upload it i just keep getting “AT” in the serial monitor.
    i’ve added:
    #include
    SoftwareSerial gprs(10,11);//TX,RX

    and in the setup:
    gprs.begin(9600);

    and in the loop:

    if(gprs.available()){
    Serial.write(gprs.read());
    }
    if(Serial.available()){
    gprs.write(Serial.read());
    }

    but i still can’t get any answers, i just get “AT”
    i hope that you post the entire code, or help making it.

  3. Hi using sim800c need to send 4000 bytes through tcp ip to server but limit exceed 1460 showing server same wismo modem work on them but now outdated how can i go up to 4000 bytes

  4. I am using sim800c and when I am trying to connect to internet using command AT+CGATT? it shows 0. what might be the problem? And once its done will I be able to use this existing GPRS connection for different tasks? or do we need to do the entire setup again?

  5. i made all steps of sending gprs packet to anther gprs modem very well. and when reaching to command of start connection at+cipstart , the command will be connect fail after 75 seconds.
    and if i make a ping from my pc to this ip , cipstart will be responded by connect ok.
    and then if i shutdown and reconnect again , all thing will be ok
    so what is the reason of it ? Is it form the network?
    why did it work when pinging the ip only for the first time ?

      1. 02/01/2018 10:36:07 [RX] – AT
        AT
        
        OK
        AT+CGMR
        AT+CGMR
        
        Revision:1137B10SIM900M64_ST
        
        OK
        
        *PSNWID: “602”,”01″, “Orange EG”, 0, “Orange EG”, 0
        
        *PSUTTZ: 2018, 1, 2, 8, 36, 7, “+8”, 0
        
        DST: 0
        
        02/01/2018 10:36:19 [RX] – AT+CREG?
        AT+CREG?
        
        +CREG: 0,1
        
        OK
        AT+CSQ
        AT+CSQ
        
        +CSQ: 21,0
        
        OK
        AT+SGPIO=0,1,1,0
        AT+SGPIO=0,1,1,0
        
        OK
        AT+SGPIO=0,2,1,0
        AT+SGPIO=0,2,1,0
        
        OK
        
        02/01/2018 10:36:23 [RX] – AT
        AT
        
        OK
        ATE0
        ATE0
        
        OK
        AT+IPR=9600
        
        OK
        AT+CGMR
        
        Revision:1137B10SIM900M64_ST
        
        OK
        AT+CPIN?
        
        +CPIN: READY
        
        OK
        AT+CCLK?
        
        02/01/2018 10:36:24 [RX] –
        +CCLK: “18/01/02,10:36:23+08″
        
        02/01/2018 10:36:35 [RX] –
        OK
        AT+CREG=0
        
        OK
        AT+CGATT=1
        
        OK
        AT+CSNS=4
        
        OK
        AT+CIPMUX=1
        
        OK
        AT+CSTT=”cws0066″,””,””
        
        OK
        AT+CIICR
        
        02/01/2018 10:36:37 [RX] –
        OK
        AT+CIFSR
        
        10.127.53.86
        AT+CIPSERVER=1,3000
        
        OK
        
        SERVER OK
        AT+SGPIO=0,1,1,1
        
        OK
        
        02/01/2018 10:37:05 [RX] – AT+SGPIO=0,2,1,1
        
        OK
        AT+CIPSTART=5,”TCP”,”10.127.53.19″,2000
        
        OK
        
        02/01/2018 10:38:20 [RX] –
        5, CONNECT FAIL
        AT+CIPSHUT
        
        02/01/2018 10:38:22 [RX] –
        SHUT OK
        AT+SGPIO=0,1,1,0
        
        OK
        AT+SGPIO=0,2,1,0
        
        OK
        
        02/01/2018 10:38:27 [RX] – AT
        
        OK
        ATE0
        
        OK
        AT+IPR=9600
        
        OK
        AT+CGMR
        
        Revision:1137B10SIM900M64_ST
        
        OK
        AT+CPIN?
        
        +CPIN: READY
        
        OK
        AT+CCLK?
        
        +C
        02/01/2018 10:38:28 [RX] – CLK: “18/01/02,10:38:27+08″
        
        OK
        AT+CREG=0
        
        OK
        AT+CGATT=1
        
        OK
        AT+CSNS=4
        
        OK
        AT+CIPMUX=1
        
        OK
        AT+CSTT=”cws0066″,””,””
        
        02/01/2018 10:38:29 [RX] –
        OK
        AT+CIICR
        
        OK
        AT+CIFSR
        
        02/01/2018 10:38:30 [RX] – 10.127.53.86
        AT+CIPSERVER=1,3000
        
        OK
        
        SERVER OK
        AT+SGPIO=0,1,1,1
        
        OK	
  6. Hello sir,

    Is it possible to send binary data over tcp/ip using gsm/gprs AT commands?
    If yes what command needs to be used?

    Thankyou.

  7. dear Dost Muhammad Shah,
    i am using gsm\gprs A7 with arduino.
    now I manage to send out string form data packet (etc:”Hello server!”) to the server,
    but I still failed to send out raw data packet (non-string data).
    is there any restriction to the type of data that can be sent using tcp over gsm/gprs?
    Thank you.

    1. hai sir,iam working on gsm sim900 and i want to set time delay for every 15minutes to check the hardware connection is alive or not.for every 15 minutes it should check the connection can you please help me out

  8. i get error when i send AT+CGATT=1 for TCP connection over GPRS using SIM900A
    ps: GSM WORK FINE FOR ME

          1. i tested with 3 different sim card ,and give the same result , and i flashed with another firmware(sim900) and nothing

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

  9. Dear,
    You have to add a sequence in order to send the data
    using AT+CIPSEND command after entering it,wait for
    > and send GET /XXXXXXXX after this,
    send

     Tx_char(13);
    	Tx_char(10);
    	Tx_char(13);
    	Tx_char(10);
    and finally send
    	Tx_char(26);

    this makes the data to be sent to website successfully
    by prompting the response with the number of times
    the data being sent to that website

  10. Hi Sir,
    I was sending message using GSM module, it was working fine,
    after connecting to the internet and sending some data to internet (this also worked fine )
    the same message command which I was using earlier is not working. the message is getting send to the SIM as sim message with no content.

    the function I am using to send a message is
    it was working very well before connecting to the internet

    gsm.println("AT+CMGF=1");
      delay(100);
      gsm.println("AT+CMGS=\"+91"+num+"\"\r");
      delay(100);
      gsm.println(msg+temp+","+hum+",21z");//msgstring4+temp+msgstring5+hum+msgstring6);// The SMS text you want to send
      delay(100);
      gsm.println((char)26);// ASCII code of CTRL+Z
      delay(100);*/
    
    1. i have done that earlier and i have even waited for “>” and then sent the message.

  11. Thanks for replying… AT+CIPSEND it’s giving > symbol after that I m passing my values and I typed ctr+z it’s giving Okay… So my doubt is (my values where it’s going) I know

  12. I am working with sim808 and arduino . I am sending AT commands to sim808 for getting gnss data then parsing it using arduino and again sending longitude and latitude to websocket server how should I do that?

      1. I am not able to connect websocket server the entire thing works fine with socket test application

  13. Hi! This is a brilliant blog and comments make it even better. I am using SIM808 for a vehicle tracking system. I am faced by 2 constraints.

    First, I cannot upload a packet of more than 255 bytes.

    Second, the port is automatically Closed after a successful CIPSEND. So I have to do CIPSTART every cycle.

    These 2 constraints induce a very tough situation in which I can only send small packets to server, that also not continuously but a gap of 30-40 seconds! What could be the possible solutions?

  14. Hello
    I saw the Mqtt code in RMAP -> Arduino. It is working when I connect module to Serail1. But it does not work when I connect it to Software Serial or the normal Serial.
    Can you tell me the changes

  15. How to implement these commmans in ardunio??help me

    
    AT+CREG?
    
    
    
    +CREG: 0,1
    
    
    
    OK
    
    The device is registered in home network.
    
    Checking if device is already connected...
    
    AT+CGACT?
    
    
    
    +CGACT: 3,0
    
    
    
    OK
    
    AT+CMEE=1
    
    
    
    OK
    
    Attaching to network...
    AT+CGATT=1
    
    
    
    OK
    
    
    Setting up APN for TCP connection...
    
    AT+CSTT="www"
    
    
    
    OK
    
    APN setup for TCP connection successful..
    
    Bring up GPRS Connection...
    
    AT+CIICR
    
    
    
    OK
    
    GPRS Connection bring up sucessful..
    
    AT+CIFSR
    
    
    
    10.97.249.175
    
    AT+CIPSTART="TCP","93.188.160.166","80"
    
    
    
    OK
    
    
    
    CONNECT OK
    
    TCP connection success
    
    
  16. hy, is there a way to send a zero length packet? this would be useful to check the connection health, i dont like to send “keep alive” messages…

  17. Hi, i am traying to implement a tcp connection. I need to keep open the connection all the time, and some time my SIM800L give me a CLOSED message. The TCP connection have a timeout by default? how i can keep open 1 tcp connection, without lost this connection? Thanks a lot.

    1. Servers and Clients implement a keep alive mechanism for this by deciding upon a keep alive interval. The server will usually waits 1.5 times the keep alive interval and if it didn’t receive any thing from the client, disconnects. The client will send a one byte message (Ping message) within that keep alive interval.

  18. Hi, I need to ask this. Have you ever used that module as a tcp server? I’m trying to do that but I got a problem, when a client disconnects from the module, It can’t reconnects again for like a half hour, even tho the module says it’s disconnected from the client and his ip state is “server listening”. I have browsed thru the documentación but I haven’t found the answer. I will apreciate if you can point me in any direction

      1. Thanks for your answer.

        I should had specified that I’m doing my tests using a TCP “raw” connexion between the gsm module and a “TCP/IP Client Server terminal” named “HERCULES”.

        I believed that the connexion-desconnexion messages and ack between client and server was solved by the module and the “teminal software” on their aplication layer.

        I had used “hercules” before for testing TCP sockets aplications in linux and never had a problem like this.

        Now, do you know how can i figure out the NAT protocol if there’s any implemented by this module in order to make my terminal compatible with it?

        Many thanks in advance

  19. Dost Muhammad Shah

    Hi Friend!

    Im was doing some similar like you program, i want to send some information to server TCP/IP (SOCKET)
    i ready can send my information. but i want to turn on some led to know if my shield (arduino uno) get the conection with the server. ¿How to read the word “CONECT OK” before the command AT [[AT+CIPSTART]] and turn on the led with this confirmation?? … thanks for you help .

    1. Assalamualaikum,
      It is great that you release good informative videos which help many over the internet.
      Actually I would like to know how I can implement FOTA (Firmware update over the Air) for Pic micro controller with GSM kit.
      please advise.

  20. Hi….Actually I am working on arduino based project.
    And I want to send the temperature sensor data at web server from gsm module900A interfaced with arduino uno. I didn’t find any helpful code on internet, all I found was using gsm shield which I don’t want to use. Can you please help me in this as I also want to keep sensor data updated on server.

    1. GSM shield is an easy way to connect sim900/sim900A or any other gsm module with an arduino. You just need to wire rx/tx and few more wires to arduino and you are done as most of your work is with AT commands.

  21. Hi Shah, about data connection status, I think SIM900 has a firmware bug. Several times a TCP connection stops passing data without notice, both on server side and client side. The SIM900 in client mode reports (CIPSTATUS) CONNECTED but doesn’t receive any data sent by the server. The server also reports connected. SIM900 can stay in this state for hours. If I tell SIM900 to close the TCP connection and connect again, it resumes receiving data for some time. It seems there is an inactivity timeout somewhere that breaks the link but doesn’t disconnect the TCP link when there is no data flowing for some time. Have you seen this behavior? Thanks.

    1. Servers and clients implement a keep alive mechanism where the connection is closed if there is no activity for 1.5 times the amount of keep alive interval. The client needs to send a ping or small packet within this time.

  22. Thanks for this detailed doc. But incase if we need to receive data using TCP/IP, then is there any command for that? suppose i need to receive a data over TCP/IP and depending on that i need to send response back. How do i do that? please help. Thanks in advance

        1. Hi, I checked and its a whole new headache to change my device to server mode. ie my device has to switch between server and client mode after every 10 sec. So is there a way to receive data from remote server while my SIm900 is in client mode itself? Please help

  23. hey i have sim808 and i need to connect it with google SUPL server.What else do i hve to apart from what’s given above ?

      1. I need A-Gps for assistantace of ephemeris data which can be fed to already present gps reciever .So require a periodic retrieval of ephimeris data.Supl client has to be ensembled with sim 808 module .Hey i m a beginner with this so apologies if i m wrong smwhere.

          1. How are you configuring server client(user agent) on an ardunio which sends and retrieve data frm any server over Tcp connection?

  24. Can we perform two way communication using sim900. That is will it possible to send data to a server via TCP using sim900 and to receive data from the server ung TCP via sim900…

    1. Hey, I too am working where requirement is to receiving data from Server using TCP via Sim900. Is it possible? If so then please help me doing that. Thanks

  25. Hey man,

    I need your help to solve the problem of receiving nothing. Could you please check my code if there are something wrong?

    #include 
    #include 
    #include 
    #include 
    
    const int pin_tx = 7;
    const int pin_rx = 8;
    
    SoftwareSerial gprs(pin_tx,pin_rx);//TX,RX
    
    void setup(){
      Serial.begin(9600);
      sim900_init(&gprs, -1, 9600);
      delay(1000);
      if(0 != sim900_check_with_cmd("AT\r\n","OK\r\n",CMD)){
          Serial.println("AT is error\r\n");
    
      }else{
        Serial.println("AT is OK\r\n");
        if(0 != sim900_check_with_cmd("AT+CGATT=1\r\n","OK\r\n",CMD)){
            Serial.println("AT+CGATT=1 is error\r\n");
      
        }else{
          Serial.println("AT+CGATT=1 is OK\r\n");
          delay(1000);
          if(0 != sim900_check_with_cmd("AT+CIPSHUT\r\n","OK\r\n",CMD)){
            Serial.println("AT+CIPSHUT is error\r\n");
        
          }else{
              Serial.println("AT+CIPSHUT is OK\r\n");
              delay(1000);
              if(0 != sim900_check_with_cmd("AT+CIPMUX=0\r\n","OK\r\n",CMD)){
                Serial.println("AT+CIPMUX is error\r\n");
            
              }else{
                Serial.println("AT+CIPMUX is OK\r\n");
                delay(1000);
                sim900_send_cmd("AT+CSTT=");
                sim900_send_cmd("\"wap.cingular\"");
                sim900_send_cmd(",");
                sim900_send_cmd("\"wap@cingulargprs.com\"");
                sim900_send_cmd(",");
                sim900_send_cmd("\"cingular1\"");
                
          
                 if(0 != sim900_check_with_cmd("\r\n", "OK\r\n", CMD)){
                    Serial.println("AT+CSTT is error\r\n");
                }else{
                    delay(2000);
                    Serial.println("AT+CSTT is OK\r\n");
                    if(0 != sim900_check_with_cmd("AT+CIICR\r\n","OK\r\n", CMD)){
                      Serial.println("AT+CIICR is error\r\n");
                    }else{
                        Serial.println("AT+CIICR is OK\r\n");
                        delay(3000);
                        sim900_send_cmd("AT+CIFSR\r\n");
                        char cmd[32];
                        memset(cmd, '\0', 32);
                        sim900_read_buffer(cmd, 32, 3);
                        Serial.println(cmd);
                        delay(1000);
                        sim900_send_cmd("AT+CIPSTART=\"TCP\",");
                        sim900_send_cmd("\"147.97.50.204\",");
                        sim900_send_cmd("\"80\"");
                        sim900_send_cmd("\r\n");
                        
                        memset(cmd, '\0', 32);
                        sim900_read_buffer(cmd, 32, 3);
                        Serial.println(cmd);
                        delay(1000);
                        char test[] = "GET /robots.txt HTTP/1.1\r\nHost: www.astate.edu\r\n\r\n";
                        
                        memset(cmd, '\0', 32);
                        sprintf(cmd, "AT+CIPSEND=%d\r\n", strlen(test));
                        Serial.println(cmd);
                        if(0 != sim900_check_with_cmd(cmd,">",CMD)){
                          Serial.println("AT+CIPSEND is error\r\n");
                        }else{
                            
                            //suli_delay_ms(500);
                            sim900_send_cmd(test);
                            //suli_delay_ms(500);
                            sim900_send_End_Mark();
                            Serial.println("AT+CIPSEND is OK\r\n");
                            delay(2000);
                             while (true) {
                                memset(cmd, '\0', 32);
                                sim900_clean_buffer(cmd,32);
                                sim900_read_buffer(cmd,32);
                                
                                //Serial.print("Recv: ");
                                Serial.println(cmd);
                            }
                        }
                    }
                }
              }
          }
        }
      }
      
    }
    
    void loop(){
      if(gprs.available()){
        Serial.write(gprs.read());
      }
      if(Serial.available()){     
        gprs.write(Serial.read()); 
      }
    }
    
    

    There are two possible results:

    1.
    AT+CIPSEND is error

    2.
    AT+CIPSEND is OK
    but receive nothing.

  26. Which library are you using to enable the communication between arduino and sim900 shield?

  27. Hello sir,
    I am working on Sim900 for last 3 months. Can you please tell me the error handling cases in AT Command Sequence for initializing SM900 as a TCP Client Module.

    1. I am trying to send a message to my domain name on port 8080 using AT+CIPSTART=“TYPE” , “domain”, “port”. I don’t know how can I retrieve this message/ see this message on my website. Could you please help me in this?

  28. Hello, I want to inquire that if i dont send the command “AT+CIPSHUT” and continue trnsmitting data to the same server with just writing “AT+CIPSEND” ,once after the TCP connection is established. Is it possible?

  29. dear mr.shah we are having a problem connecting the arduino to thingspeak which is iot website .
    our problem is writing the code but we have no experience in arduino programming ,we already have the code for the sensors (gas sensors) but we need to combine it with the thingspeak code that only supports wifi and ethernet …..any suggestions please …much respect

  30. hi, I need to know that code should be written in gettempdata.php plz

    test is your database ?

    thx for all

      1. i need file: gettempdata.php sorry for my english I need to send two variables with sim900 to MySQL

          1. Yes, I need to send two variables by AT commands from the SIM900 to wampserver (mysql) and does not work,
            I have to add is the gettemdata.php file in the C:wamp/www, I need the code gettempdata.php

          2. You have to do it yourself or ask someone to do it for you… Wamp server will only be accessable if you do port forwarding from your router and have a fix ip or a ddns setup…

  31. Hi
    Is it possible, sending real time data over tcp connection using AT+CIPSEND? for example sending voice data after sampling!

  32. Hi, i am failing with CIPSTART command.i actually tried my server and client codes directly in multiple systems and there is no issue with server/client code.
    below is the command i am giving after getting IP address.
    at+cipstart=”tcp”,”server ip”,”port”

    the above command giving me result as TCP closed.

  33. Hai i need a small help from you.I need to control the device from web server how to read the data from web server using by using SIM900 AT commands. Please get me back.

      1. Hai DMS

        thanks for your reply.I already created a web page.Now my doubt is what are the AT commands we have to read the data from server to SIM900 modem to control the device.

        EX: I need to turn ON and OFF the LED from the Web server.I connected this LED to the micro controller and i interfaced GPRS modem to my micro controller.

  34. Hi,
    I am able to send the UDP packet to the server but I am not receiving the UDP packets for the Server.
    I am using SIM 900 module with FreeeScale Controller ?

    Does ISP blocks the incoming UDP connections and I need the hole punching server to establish 2 way communication over UDP ?

    How do I establish 2 Way communication over UDP ?

    Thanks and Regards
    Sachin

  35. Hi Mr Shah,

    should there be a library for these codes? they don’t compile for me. using arduino ide 1.55 and I get an errors from mismatching brackets ) before APN to unknow source headers. Does anyone have these codes working? Thanks.

        1. Hello again,

          I’d like to use your routines to send a text file, or the contents of a text file, to a server.

          Will this be possible using your two routines – this one and the next?

          And, will it be possible to send the entire file as one action or will I need to read the file a character at a time and send each character to the remote server?

          I’ve been pulling my hair out trying to solve this problem and being a relatively new starter to Arduino am finding it difficult to understand all the possibilities. Your routines seem to fit the bill.

          Regards.

  36. mr dost shah i have one problem in apn for simcom 900.i am in saudi arabia using stc sim card this modem i am using in vending machine from russia i tried stc apn but its not connect the admin in russia.can u help me how to connect

  37. Hi, I finally got the POST method working using the TCP connection, my question is you do you keep the connection alive, I need to send data(make post) at 30s interval. but the connection closes inbetween, what is the best way to reconnect it.
    thanks!

    1. Hi, I tried to POST for many days unsuccesfully, only GET work. Can you help me with a bit of working code to use POST?

      Many thanks

      1. Hi, try this example code

        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
        
  38. When I send data to my server I get SEND OK then it closes the socket with and data is never recived by the server. Any help would be great.

      1. When I send data to my server I get SEND OK then it closes. The server is not receiving the data and I have tried sending data to the same server from pc with same request and it works. I am sending the data to the thingspeak website using the GET method like

        GET /update?api_key=VXVCDQ3MST4FZEN3&field2=30.9254&field3=80.6746&headers=false

          1. AT
            
            OK
            AT+CGATT=1
            
            OK
            AT+CIPMUX=0
            
            OK
            AT+CSTT="www","",""
            
            OK
            AT+CIICR
            
            OK
            AT+CIFSR
            
            100.120.179.19
            AT+CIPSTART="TCP","184.106.153.149","80"
            
            OK
            
            CONNECT OK
            AT+CIPSEND
            
            > GET /update?api_key=VXVCDQ3MST4FZEN3&field2=30.9254&field3=80.6746
            
            
            0x1A
            
            CLOSED
            
            ERROR
            AT+CIPSHUT
            
            SHUT OK
          2. As you can see the send ok command is displayed after i sent the data, but the data does not appear on the destination ip address.

            AT+CIPSTART="TCP","184.106.153.149","80"
            
            OK
            
            CONNECT OK
            
            AT+CIPSEND=80
            
            > GET /update?api_key=VXVCDQ3MST4FZEN3&field2=30.9254&field3=80.6746&headers=false
            
            SEND OK
            
            CLOSED
            
    1. dear Dost Muhammad Shah,
      iam using gsm\gprs sim900 module with raspberrypi2
      i was successfully establish tcp connection socket was running successfully client connect but iam unable to post the data by using AT+CIPSEND i got ‘>’ in sim900 pdf type some thing ctrl+Z after some time nothing will be posted can u tell me how we have to send the data using that AT command and step by step

      1. Dear Dost Muhammad Shah,

        import serial
        #import RPi,GPIO as GPIO
        import os,time
        #GPIO.setmode(GPIO.BOARD)
        global ime
        global port
        global flag
        flag=0
        a="0010010010110010111101011000001011111111000100010001001000010111001000110101011000101001xxx00x01xxx00001xxxxxxxxxxxxxxxxxx000001xxxxxx1xxxxxxxxxxxxxxxxx0000000011100110000000000000000000000001000100110000000100010110000101000001001001111000100101100101101001010101010000010010100001000010010000010100000001001011010000010101100000110010001011010001101000000001000000010000000100111100110010000100000101000010010101000011000100110011001101110011100100111000001101100111100001111010011100100011010100110011001100010011010000111000001110010011100100110010010110101010011110111101110000100000001010001110011100110011000100100011"
        port = serial.Serial(
                      
                       port='/dev/ttyUSB0',
                       baudrate = 9600,
                       parity=serial.PARITY_NONE,
                       stopbits=serial.STOPBITS_ONE,
                       bytesize=serial.EIGHTBITS,
                       timeout=1
                   )
        
        
        	
        port.write('AT'+'\r\n')
        rcv=port.read(10)
        print rcv
        time.sleep(2)
        
        port.write("AT+CPIN?\r")
        msg=port.read(128)
        print msg
        time.sleep(2)
        
        port.write('AT+CGSN\r')
        rcv=port.read(10)
        print rcv
        time.sleep(2)
        
        
        
        port.write("AT+CIPSHUT\r")
        rcv=port.read(128)
        print rcv
        time.sleep(2)
        
        port.write('AT+CIPMUX=0\r')
        rcv=port.read(10)
        print rcv
        time.sleep(2)
        
        port.write('AT+CGATT?\r')
        rcv=port.read(10)
        print rcv
        time.sleep(2)
        
        
        port.write('AT+CSTT="airtelgprs.com","",""\r')
        rcv=port.read(128)
        print rcv
        time.sleep(2)
        
        
        
        port.write('AT+CIICR\r')
        rcv=port.read(10)
        print rcv
        time.sleep(2)
        
        
        port.write('AT+CIFSR\r')
        rcv=port.read(120)
        print rcv
        time.sleep(2)
        
        
        
        
        port.write('AT+CIPSTART="TCP","137.69.271.80","8999"\r')
        rcv=port.read(120)
        print rcv
        time.sleep(2)
        
        port.write("AT+CIPSEND\r")
        rcv=port.read(120)
        print rcv
        time.sleep(2)
        
        port.write("%d" %a)
        rcv=port.read(10)
        print rcv
        time.sleep(2)
        
        
        
        port.write('\x1A')
        rcv=port.read(10)
        print rcv
        time.sleep(10)
        

        1.What happens when we give the time(time.sleep(0.5)) delay in one AT-command to another AT-Command
        2.Is that really required from each other can you explain clearly
        3.I was tested without time delay(time.sleep) to start to end but unable communicate errors will accured
        4.Can u send GET method AT-commands for Ardunio are raspberrypi

        1. 1 & 2 –> please note that you have to send a command and wait for the response and then act accordingly, In your code what you are doing is essentially just sending command after command with a small delay and not considering what was the reply. Although this might work but its not guaranteed to work.

          3 –> every command might take some time to process which you are not considering and sending the next command.

          4 –> I suggest to use a library for sim800/900 for arduino and raspberry pi , these days well developed libraries are available for both the platforms and are very reliable. As far as the AT-commands for GET method please refer to the content of this post!

  39. If I want to send a text message to another GSM/GPRS module via GPRS, then if I replace “Ip_address” with the IP address of the receiving module, will it be receive there? or do I have do something other?

    1. ya definitely it will receive . but this will happen only at that instance only.
      because the IP address you get for the GPRS/gsm module everytime you restart the device is different. it is dynamic . so you better find a better solution . or else make a broker between both , so that you can get the updated IP address every time you need.

      I hope this will solve you issue.

      Mahender verma
      mahender@uniolabs.com
      #uniolabs

Leave a Reply to AkshayCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.