6 Replies Latest reply on Jan 30, 2017 12:20 PM by Intel Corporation

    How to connect Intel Galileo to internet using GPRS module?

    malvika_bhardwaj

      Hello folks,

      I am using these commands to connect my intel galileo to 3G internet using gprs module  of LINL SPRITE ATwin. I  able to run the commands till  cgdcont,

      I am using the following commands to connect to the internet.

       

      #include <String.h>

      char data[256];

      void setup()

      {

      Serial1.begin(115200);

      Serial.begin(9600); // the GPRS baud rate

      delay(1000);

      }

      void loop()

      {

      if (Serial.available())

      switch(Serial.read())

      {

      case 't':

      SendTextMessage();

      break;

       

       

      case 'd':

      DialVoiceCall();

      break;

       

       

      case 'g':

      activateGPRS();

      break;

      }

      if (Serial1.available())

      Serial.write(Serial1.read());

      }

       

       

      void SendTextMessage()

      {

      Serial1.print("AT+CMGF=1\r"); //Because we want to send the SMS in

      delay(1000);

      Serial1.println("AT+CMGS=\"+919148434113\"");

      delay(1000);

      Serial1.write("Hello from Galileo?");

      delay(1000);

      Serial1.println((char)26); //the ASCII code of the ctrl+z is 26 (0x1A)

      delay(1000);

      Serial1.println();

      }

       

      void DialVoiceCall()

      {

      Serial1.println("ATD +919148434113;");//dial the number

      delay(100);

      Serial1.println();

      }

      void ShowSerialData()

      {

      while(Serial1.available()!=0)

      Serial.write(Serial1.read());

      }

       

       

      void activateGPRS()

      {

      Serial1.println("AT+CPIN?"); // Is SIM ready to use?

      delay(1000);

      ShowSerialData();

      Serial1.println("AT+CGREG?"); // Is device registered?

      delay(1000);

      ShowSerialData();

      Serial1.println("AT+COPS?"); // Does SIM info match network?

      delay(1000);

      ShowSerialData();

      Serial.println("Check signal quality");

      Serial1.println("AT+CSQ"); // Check signal quality

      delay(1000);

      ShowSerialData();

      Serial1.println("AT+cgatt=1"); // GPRS attach// define a PDP context with IP connection, ID is 1

      Serial1.println("AT+CGDCONT=1,\"IP\",\"internet\"");

      delay(1000);

      ShowSerialData();

       

      //list PDP contexts that are defined

      Serial1.println("at+cgdcont?");

      delay(3000);

      ShowSerialData();

       

      // setup the session using the appropriate PDP context

      Serial1.println("AT+CGACT=1,1");

      delay(1000);

      ShowSerialData();

      Serial.println("session is setup delay 5 seconds");

      delay(5000);

       

      Serial1.println("AT+CGQMIN=?");

      delay(1000);

      ShowSerialData();

       

       

      Serial1.println("AT+CGQREQ=?");

      delay(1000);

      ShowSerialData();

       

       

      Serial1.println("AT+CGACT");

      delay(1000);

      ShowSerialData();

      }

       

       

      I am also attaching the response of all the commands which I had got, I am getting OK response till the command cgdcont, after that ERROR is there.

       

        • 1. Re: How to connect Intel Galileo to internet using GPRS module?
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi Malvika_bhardwaj,

          I would love to help you with this.

          I think you should take a look to the Shield Testing Report for Intel® Galileo Board, Intel® Galileo Gen 2 Board, and Intel® Edison Board, I'm not sure if your module is the 23 of the list but you can check it.

          You can also use the sketch that is in there as reference for your code.

          I hope you find this information helpful.

          Regards,
          -Leonardo

          • 2. Re: How to connect Intel Galileo to internet using GPRS module?
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hi Malvika_bhardwaj,

            Do you have any updates about this? Was the information helpful?

            Have a nice day!

            Regards,
            -Leonardo

            • 3. Re: How to connect Intel Galileo to internet using GPRS module?
              malvika_bhardwaj

              Hello Sir,

              With the help of these AT commands, I am able to activate my GPRS module. I want to send data through GPRS to THINKSPEAK server, what are the commands which will be used?

              I am also attaching the code and the response of the link which you had send me earlier.

               

              #include <String.h>

              char data[256];

              void setup()

              {

              Serial1.begin(11500);

              Serial.begin(9600); // the GPRS baud rate

              delay(1000);

              }

               

               

              void loop()

              {

              if (Serial.available())

              switch(Serial.read())

              {

              case 't':

              SendTextMessage();

              break;

              case 'g':

              GPRS();

              break;

              }

              if (Serial1.available())

              Serial.write(Serial1.read());

              }

               

               

              void SendTextMessage()

              {

              Serial1.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode

              delay(1000);

              Serial1.println("AT+CMGS=\"+919148434113\"");

              delay(1000);

              Serial1.println("Hello from Galileo?");

              delay(1000);

              Serial1.println((char)26); //the ASCII code of the ctrl+z is 26 (0x1A)

              delay(1000);

                Serial1.println();

              }

               

               

              void ShowSerialData()

              {

              while(Serial1.available()!=0)

              Serial.write(Serial1.read());

              }

               

               

              void GPRS()

              {

              Serial1.println("AT+CPIN?"); // Is SIM ready to use?

              delay(1000);

              ShowSerialData();

              Serial1.println("AT+CGREG?"); // Is device registered?

              delay(1000);

              ShowSerialData();

              Serial1.println("AT+COPS?"); // Does SIM info match network?

              delay(1000);

              ShowSerialData();

               

               

              Serial.println("Check signal quality");

              Serial1.println("AT+CSQ"); // Check signal quality

              delay(1000);

              ShowSerialData();

              Serial1.println("AT+cgatt=1"); // GPRS attach

              delay(1000);

              ShowSerialData();

               

               

              // define a PDP context with IP connection, ID is 1

              Serial1.println("AT+CGDCONT=1,\"IP\",\"internet\"");

              delay(1000);

              ShowSerialData();

              // list PDP contexts that are defined

              Serial1.println("at+cgdcont?");

              delay(3000);

              ShowSerialData();

               

               

              // setup the session using the appropriate PDP context

              Serial1.println("AT+CGACT=1,1");

              delay(1000);

              ShowSerialData();

              Serial.println("session is setup delay 5 seconds");

              delay(5000);

               

               

              // deactivate the PDP context

              Serial1.println("AT+CGACT=0,1");

              delay(1000);

              ShowSerialData();

              // detach from GPRS newtork

              Serial1.println("AT+CGATT=0");

              delay(1000);

              ShowSerialData();

              }

               

               

              Response of the above code is....

               

              AT+CPIN?

               

               

              +CPIN: READY

               

               

              OK

               

               

              AT+CGREG?

               

               

              +CGREG: 0,1

               

               

              OK

              AT+COPS?

               

               

              +COPS: 0,0,"Spice Telecom"

               

               

              OK

               

               

              Check signal quality

              AT+CSQ

               

               

              +CSQ: 25,99

               

               

              OK

              AT+cgatt=1

               

               

              OK

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

               

               

              OK

              at+cgdcont?

               

               

              +CGDCONT: 1,"IP","internet","",0,0

               

               

              OK

              AT+CGACT=1,1

               

               

              OK

              session is setup delay 5 seconds

              AT+CGACT=0,1

               

               

              OK

              AT+CGATT=0

               

               

              OK

              • 4. Re: How to connect Intel Galileo to internet using GPRS module?
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi Malvika_bhardwaj,

                Thanks for letting us know, about how to send data to ThingSpeak server, I'm not familiarized with that cloud, and I didn't find any helpful information, so I think you should contact https://thingspeak.com/ for a better support.

                Have a nice day.

                Regards,
                -Leonardo

                • 5. Re: How to connect Intel Galileo to internet using GPRS module?
                  malvika_bhardwaj

                  Hello Sir,

                   

                  I have run a code to access data through GPRS, but I am unable to get the response of command "AT+CREG".

                  Kindly help me out.

                   

                   

                  int8_t answer;

                  int onModulePin=2;

                  char aux_str[100];

                  char pin[]="1234";

                  char apn[]="Internet";

                  char user_name[]=" ";

                  char password[]=" ";

                  char IP_address[]="*******";

                  char port[]="8080";

                  char ip_data[40]="Test string from GPRS shield\r\n";

                  void setup(){

                     pinMode(onModulePin, OUTPUT);

                      Serial.begin(115200);   

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

                      void power_on();

                       delay(3000);

                       //sets the PIN code

                      snprintf(aux_str, sizeof(aux_str), "AT+CPIN=%s", pin);

                      sendATcommand(aux_str, "OK", 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(sendATcommand("AT+CIPSTATUS", "INITIAL", 500)  == 0 );

                          delay(5000);

                         snprintf(aux_str, sizeof(aux_str), "AT+CSTT=\"%s\",\"%s\",\"%s\"", apn, user_name, password);

                          // Sets the APN, user name and password

                          if (sendATcommand2(aux_str, "OK",  "ERROR", 30000) == 1)

                          {           

                              // Waits for status IP START

                              while(sendATcommand("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(sendATcommand("AT+CIPSTATUS", "GPRSACT", 500)  == 0 );

                                  delay(5000);

                                 // Gets Local IP Address

                                  if (sendATcommand2("AT+CIFSR", ".", "ERROR", 10000) == 1)

                                  {

                                      // Waits for status IP STATUS

                                      while(sendATcommand("AT+CIPSTATUS", "IP STATUS", 500)  == 0 );

                                      delay(5000);               

                                    Serial.println("Opening TCP");

                                    snprintf(aux_str, sizeof(aux_str), "AT+CIPSTART=\"TCP\",\"%s\",\"%s\"", IP_address, port);

                                   // Opens a TCP socket

                                      if (sendATcommand2(aux_str, "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 opening 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 = sendATcommand("AT", "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 = sendATcommand("AT", "OK", 2000);   

                          }}}

                   

                  int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout)

                  {

                      uint8_t x=0,  answer=0;

                      char response[100];

                      unsigned long previous;

                      memset(response, '\0', 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(Serial.available() != 0)

                          {   

                              // if there are data in the UART input buffer, reads it and checks for the asnwer

                              response[x] = Serial.read();

                              //Serial.print(response[x]);

                              x++;

                              // check if the desired answer  is in the response of the module

                              if (strstr(response, expected_answer) != NULL)   

                              {

                                  answer = 1;

                              }

                          }

                      }

                      // Waits for the asnwer with time out

                      while((answer == 0) && ((millis() - previous) < timeout));   

                        return answer;

                  }

                   

                  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, '\0', 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;

                  }

                     

                  Response of above code is.........

                   

                   

                   

                  Starting...

                  AT+CPIN=1234

                  Connecting to the network...

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  AT+CREG?

                  • 6. Re: How to connect Intel Galileo to internet using GPRS module?
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hi Malvika_bhardwaj,

                    Unfortunately we don't have this shield with us to do some test and help you, but I think that you can contact the author of the library to help you in a better way, or contact LinkSprite.

                    I found this wiki that can be helpful for you: http://linksprite.com/wiki/index.php5?title=ATWIN_Quad-band_GPRS/GSM_Shield_for_Arduino

                    Have a nice day.

                    Regards,
                    -Leonardo