Go Down

Topic: Direct AT Commands to shield (for getting time) (Read 22808 times) previous topic - next topic

andreasulmer

Hi,

after some searching in the library I still do not get how to do it.

I would like to white AT+CCLK? and read the answer.

Thanks,
Andreas



BigByte

Hi,
you can try something like


SoftwareSerial _gprs;

...

_gprs.println("AT+CCLK?");
_gprs.flush();
      
            
   while(_gprs.available()!=0)
   {   
      delay(300);
      Serial.print(_gprs.read());         
   }



AndersHedberg

Thanks BigByte, I must test this as I also got lost in the C++ classes while trying to figure it out..

Question: How safe is this? Can several SoftSerial-ports exist at the same time? Will all see the same characters? or will only the last one do that? How do I close it? etc... is it using the CMUX protocol to have several different AT-command parsers in the modem? (is that even possible with this module) etc...

matessi

I have a similar issue: I am trying to send AT commands directly in my code to the GSM shield (in my case to retrieve the MSISDN/telephone number). The suggested code does not work as the SoftwareSerial.h library conflicts with the GSM.h library. If I have both libraries in my code here the error I get:

Quote

GSM/GSM3SoftSerial.cpp.o: In function `__vector_5':
/Applications/Arduino.app/Contents/Resources/Java/libraries/GSM/GSM3SoftSerial.cpp:525: multiple definition of `__vector_5'
SoftwareSerial/SoftwareSerial.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:319: first defined here
GSM/GSM3SoftSerial.cpp.o: In function `__vector_4':
/Applications/Arduino.app/Contents/Resources/Java/libraries/GSM/GSM3SoftSerial.cpp:518: multiple definition of `__vector_4'
SoftwareSerial/SoftwareSerial.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:312: first defined here
GSM/GSM3SoftSerial.cpp.o: In function `__vector_3':
/Applications/Arduino.app/Contents/Resources/Java/libraries/GSM/GSM3SoftSerial.cpp:511: multiple definition of `__vector_3'
SoftwareSerial/SoftwareSerial.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:305: first defined here


And the code is very simple:

Code: [Select]

#include <SoftwareSerial.h>
#include <GSM.h>

GSM gsmAccess(false);
SoftwareSerial _mySerial(2,3); // RX, TX on GSM shield


void setup()
{
  Serial.begin(9600);
  _mySerial.begin(9600);

 
  // connection state
  boolean notConnected = true;
 
  while(notConnected){
    if(gsmAccess.begin() == GSM_READY) //Note: I do not require PIN #
      notConnected = false;
    else {
      Serial.println("Not connected, trying again");
      delay(1000);
    }
  }
 
  Serial.println("Connected");
}

void loop()
{
  if (_mySerial.available())
    Serial.write(_mySerial.read());
  if (Serial.available())
    _mySerial.write(Serial.read());

}


Any help greatly appreciated. The basic question is: "How do you send AT commands directly to the GSM shield?"

davidgoth

Don't use GSM with SoftwareSerial in the same sketch, because this two libraries modify interrupt vector. You can use only SoftwareSerial for enter AT commands and connect to GPRS network manually.

fersuoch

Hi,


I  had the same issue too and I solved it in this way:


for sending an AT command, you can write

Code: [Select]



theGSM3ShieldV1ModemCore.println("AT+QTONEDET=1");




if  you want the answer, you can write

Code: [Select]



theGSM3ShieldV1ModemCore.println("AT+QTONEDET?");





if you want to print out the  AT commands from the modem you have to include the "true" parametre in the constructor in this way

Code: [Select]



GSM gsmAccess(true);



Please, excuse me,  I'm Italian and English it' s not my language

matessi

#6
May 18, 2013, 08:26 am Last Edit: May 18, 2013, 08:31 am by butyouyes Reason: 1
davidgoth, fersuoch,

thank you for the infos. In my case I need to parse the response as well, as I need to get the telephone number associated to the SIM (using AT+CNUM command, and the modem will return me my telephone number).

How safe do you think the following code is? I use synchronous mode: is there any risk that theBuffer() contains other responses other than the one associated to AT+CNUM? I don't think so in synchronous mode....

Also, do I need to flush() the buffer or clean something after this code?

After a few tests all seem to work ok...

Code: [Select]

 char myNumber[20];

 theGSM3ShieldV1ModemCore.println("AT+CNUM"); // AT Command to retrieve a MSISDN
   
 while(!theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CNUM: \"\",\"", "\"", myNumber, 20)){
 }
 
 Serial.print("My Telephone number: ");
 Serial.println(myNumber);



andreasulmer, if this works you can use something similar to retrieve the time, parsing the correct response.

just fyi the AT+CNUM response looks something like:
Quote

+CNUM: "","##########",129,7,4


Where ########## is the telephone number

AndersHedberg

butyouyes, could you post a bit more code? I can't get it to work. It just hangs on the while I assume.

AndersHedberg

Got it to work to read out the IMEI number.

Code: [Select]

// Initialize the GSM library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess(true); // True for debugging


call gsmAccess.begin() so the modem is started... and then this function works:

Code: [Select]

String imei;
void readIMEI(){
    GSM3ShieldV1DirectModemProvider modemAccess;
    modemAccess.begin();
    int tries = 10;
    while (imei.length() < 15 && tries>0) {
      imei = modemAccess.writeModemCommand("AT+GSN", 2000);
     
      Serial.print(F("IMEI: "));
      Serial.println(imei);
      tries--;
    }
    int i;
    String imei2="";
    for (i=0;i<imei.length();i++) {
      char a = imei[i];
      Serial.println(a);
      if (a >= '0' && a<='9') imei2 = imei2 + a; //Remove any characters except the numbers.
      Serial.println(imei2);
    }
    imei = imei2;
}

matessi

Sure. Here the full sketch (I added a timeout as well now):

Code: [Select]

/* This Sketch is to retrieve the MSISDN of the SIM using AT commands */

#include <GSM.h>

GSM gsmAccess(false);
char myNumber[20];
int timeout = 5000; // 5 seconds

void setup()
{
  Serial.begin(9600);
 
  boolean notConnected = true;
 
  Serial.println("Connecting to the GSM network");
 
  while(notConnected){
    if(gsmAccess.begin() == GSM_READY) // Note: I do not require PIN #
      notConnected = false;
    else {
      Serial.println("Not connected, trying again");
      delay(1000);
    }
  }
 
  Serial.println("Connected");
 
  theGSM3ShieldV1ModemCore.println("AT+CNUM"); // AT Command to retrieve a MSISDN
 
  int start = millis();
   
  while((millis() - start) < timeout && !theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CNUM: \"\",\"", "\"", myNumber, 20)){
  }
 
  Serial.print("My Telephone number: ");
  Serial.println(myNumber);
 
}

void loop()
{

}


AndersHedberg


Prezzat0r

#11
Jun 04, 2013, 06:06 pm Last Edit: Jun 04, 2013, 06:34 pm by Prezzat0r Reason: 1

Sure. Here the full sketch (I added a timeout as well now):

Code: [Select]

 
 theGSM3ShieldV1ModemCore.println("AT+CNUM"); // AT Command to retrieve a MSISDN
 
 int start = millis();
   
 while((millis() - start) < timeout && !theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CNUM: \"\",\"", "\"", myNumber, 20)){
 }
 
 Serial.print("My Telephone number: ");
 Serial.println(myNumber);




I've tried the same thing (with CCLK instead of CNUM), but it's working only when i use the constructor:

gsmAccess(true);

I've tried to execute your program as well, but i have the same problem. When the time runs out, it just says:
My Telephone number:

And nothing more.

What did I miss?
(I didn't make any syntax mistakes, it perfectly works if i type gsmAccess(true)).

Thank you for your time.

EDIT: your sketch isn't working with gsmAccess(true) either, while mine is working.

DonShea

I realize this has not been replied to in quite a while, but the topic is exactly what I needed.  I want to find out what time is it is at boot so I can initialize the Time class and have a pretty good real time clock.  I want an SMS message delivered at 3pm every day.

After looking at the GSM code and this thread, here is how I read the GSM network clock after booting the Arduino.

Code: [Select]

/* This Sketch will get the GSM Network time using AT commands
 *
 * the time is only set when the GSM card is initialized, so
 * the time seems to never get updated.  I'll work on that.
 *
 * time response format:
 * <cr><lf>+QLTS: "yy/MM/dd,hh:mm:sszzz,x"<cr><lf>
 * where:
 *  <cr> = binary decimal 13 (carrage return)
 *  <lf> = binary decimal 10 (line feed)
 *   yy  = year
 *   MM  = month (1=jan)
 *   dd  = day of month
 *   hh  = hour (24 hour)
 *   mm  = minute
 *   ss  = second
 *   zzz = +/- quarter hours to GMT
 *   x   = 1 is daylight savings, 0 is not
 *
 * example:
 * <cr><lf>+QLTS: "15/02/20,01:03:28-20,0"<cr><lf>
 *
 * Arduino 1.6.0 IDE
 * Arduino UNO R3
 * Arduino GSM Shield R3
 * Quectel M10ER01A06W32
 * T-Mobile Pay as you go SIM ($3/month on 2015)
 * Annapolis, MD, USA
 *
 */

#include <GSM.h>

#define MY_BUFFER_SIZE 30

GSM gsmAccess(false);  // pass in true to see debug information
int timeout = 5000; // 5 seconds

char myBuffer[MY_BUFFER_SIZE];
int start;
bool resp;

void setup()
{
  Serial.begin(9600);
   
  Serial.println("Connecting to the GSM network");
 
  boolean notConnected = true;
  while(notConnected) {
    if(gsmAccess.begin() == GSM_READY) // Note: I do not require PIN #
      notConnected = false;
    else {
      Serial.println("Not connected, trying again");
      delay(1000);
    }
  }
  Serial.println("Connected");
 
  Serial.println("sending AT+QLTS");
  theGSM3ShieldV1ModemCore.genericCommand_rqc("AT+QLTS");
  myBuffer[0] = 0;
  start = millis();
  while((millis() - start) < timeout) {
    theGSM3ShieldV1ModemCore.genericParse_rsp(resp, "QLTS", "OK");
    if(resp) {
      if(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+QLTS: \"", "\"", myBuffer, 100)) {
        break;
      }
    }
  }
  if(myBuffer[0]) {
    Serial.print("GSM clock = ");
    Serial.println(myBuffer);
  } else
    Serial.println("GSM clock = nothing");
}

void loop()
{
}


BhanuTejaJ


arkeenkanalan

hi, Good day, I hope you can help me about my concern. My GSM shield interconnected to Arduino is now working , it can send alert (SMS) to the mobile number I just put on program, now my concern is, how can I put more mobile numbers (Receivers) or send it to multiple numbers in the command?


is this one will work?:

Serial.print("1234567890", 0987654321, 11111222211);

thanks in advance :)

Go Up