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 🙂
RECOMMENDED READ  writing and reading from AVR EEPROM in Block.

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

 

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

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

  2. 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?

  3. 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?

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

  5. 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
    
    
  6. 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…

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

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

  9. 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. Simcom only offers MQTT AT Commands in 3G modules or may be in LTE as well. For sim900 you need to implement it in your microcontroller or in EAT

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

      1. You would require to download the new firmware file using gsm module to its flash memory and then implement a bootloader like the arduino has to start the flashing process.

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

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

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

      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. I have no idea of supl server anf have not worked with them. If you need to get some data using TCP you can achieve that easily.

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

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

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

    1. No special library has been used. Simple Serial.read and print functions are used. Go through the code to understand it

  15. 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?

      1. As I explained in the email its easier to use the HTTP commands and use GET/POST requests done although you can create a get and post request by the method you used. See this post.

  16. 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?

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

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

    test is your database ?

    thx for all

          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…

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

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

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

      1. you can setup your sim900 as a server or as client, but in one configuration at a time.

        For incoming connections you must set it as server!

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

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

  24. 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. I am not sure what is the best way… what I do is :

      • check if connection is alive
      • close connection i not alive and reconnect
    2. 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
        
  25. 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
            
  26. 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. You need to understand how a client and server works together… The server needs to listen on a port for incoming data.

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