Timestamp from GSM Network

Dear all,
do you know if is it possible to know the current time (hh/mm/ss) from the GSM network with the GSM Shield?

GSM network doesn't have such service. GPRS, which is Internet over GSM, may work, same way like your OS getting timing from NTP, only you need a data in your GSM plan.

Is there any service then on arduino GSM shield in order to retrieve the timestamp from NTP?

How to setup an UDP communication over a GPRS network?
I am still missing something...

dtluigi:
How to setup an UDP communication over a GPRS network?
I am still missing something...

Actual GSM library doesn't support UDP connections, but it is possible sending AT commands.
Read M10 manual for more information: http://arduino.cc/en/uploads/Main/Quectel_M10_AT_commands.pdf

Thank you for your reply, but I have now an issue when I have both the include:

#include <GSM.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

Do you know why?!?

dtluigi:
Thank you for your reply, but I have now an issue when I have both the include:

#include <GSM.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

Do you know why?!?

Don't use SoftwareSerial and GSM library in the same sketch. They have conflicts with interruptions.

Try googling GSM_Location_ATC_V10 which seems to be floating around the net. It gives

AT+QIFGCNT=0 //Choose the contect 0 to activate GPRS/CSD context for the TCP/IP service.
AT+QICSGP=1,"bluevia.movistar.es"
AT+QGSMLOC=2 //Get the time

That will give you the current date and time.

Try AT+QGSMLOC=1 and you will get the longitude and latitude as well :wink: There is a AT+QGSMLOC=8 that should get better precision, but it's not working for me...

It's better / easier to use a GPS module if you need accurate time

See: Direct AT Commands to shield (for getting time) - Arduino GSM Shield - Arduino Forum

Ok guys,
with gsmAccess(true) it is possible to send (and see on serial port) AT commands; following this step I have tried to send AT+CCLK? right now (2013-07-02 17:00:00) receiving as reply from the modem:
85 2>%13%%10%OK%13%%10%%13%%10%+CCLK: "08/01/01,01:39:15+00"%13%%10%%13%%10%OK%13%%10%

How can be possible that the timestamp that it gives to me is "08/01/01,01:39:15+00"?!?
What's wrong?

If the GSM TimeStamp is not affordable just like the previous one I reported here, I'll try to do a UDP connection with a NTP Server by GPRS.

dtluigi:
If the GSM TimeStamp is not affordable just like the previous one I reported here, I'll try to do a UDP connection with a NTP Server by GPRS.

Hey dtluigi, have you managed to do this yet? UDP is supported but I have no clue how to use it.

AT+CCLK is a method to write the actual date and time in the GSM Module, and using its internal RTC it's possible anytime retrieving the timestamp with the same command.
It can't be used to know the Timestamp without first have written in it (in a GSM module setup phase).
So the only method I think to use to know the actual Timestamp is a NTP or Daytime service over internet.

For what concern NTP I am still at the beginning of my first sketch (it needs an UDP communication with a NTP server)...if someone could help us, it would be appreciated! :wink:

dtluigi:
AT+CCLK is a method to write the actual date and time in the GSM Module, and using its internal RTC it's possible anytime retrieving the timestamp with the same command.
It can't be used to know the Timestamp without first have written in it (in a GSM module setup phase).

Ok, that explains alot. I'm having trouble with getting the anwsers from my AT commands. For some reason, even in debuggin mode, I don't get the responeses that others get, for example in: Direct AT Commands to shield (for getting time) - Arduino GSM Shield - Arduino Forum
Actually, the shield just returns nothing...

dtluigi:
So the only method I think to use to know the actual Timestamp is a NTP or Daytime service over internet.

For what concern NTP I am still at the beginning of my first sketch (it needs an UDP communication with a NTP server)...if someone could help us, it would be appreciated! :wink:

I'm currentely working on a project that needs to be finshed next week and I have a couple of other problems I need to overcome. I was thinking of doing something simply for the time being: letting a php script display te time on a server, important that into the arduino and using that as timestamp. I think that's the easiest and quiest solution. Not sure if it's the best ;).
I've been looking up about the NTP thing and the UDP connection and came across this page:
http://www.cooking-hacks.com/index.php/documentation/tutorials/arduino-3g-gprs-gsm-gps#step14
It's for a different gsm shield but the principle is the same I think. I guess all the elements are there to cover the UDP part, except I still have that problem with recieving the answer to my AT commands...

MathiasVDA:
Actually, the shield just returns nothing...

Dear MathiasVDA in order to see a reply from the GSM modem forget Software Serial! :wink:
First of all write: GSM gsmAccess(true);
Now you will be able to see all the AT Commands exchanged from the ATMega and GSM Module.
If you want to send your own AT Command please use this format: theGSM3ShieldV1ModemCore.println("AT+CCLK?");

MathiasVDA:
It's for a different gsm shield but the principle is the same I think. I guess all the elements are there to cover the UDP part, except I still have that problem with recieving the answer to my AT commands...

The concept is correct, only the AT Commands are different: the right ones to be used for the Quectel GSM module are in its reference manual: http://arduino.cc/en/uploads/Main/Quectel_M10_AT_commands.pdf

dtluigi:
Dear MathiasVDA in order to see a reply from the GSM modem forget Software Serial! :wink:
First of all write: GSM gsmAccess(true);
Now you will be able to see all the AT Commands exchanged from the ATMega and GSM Module.
If you want to send your own AT Command please use this format: theGSM3ShieldV1ModemCore.println("AT+CCLK?");

Unfortunately, I know all that and still have the problem:

#include <GSM.h>
GSM gsmAccess(true);

char answer[100];

void setup()
{
  Serial.begin(9600);
  
  boolean notConnected = true;
  
  Serial.println("Connecting to the GSM network");
  
  while(notConnected){
    if(gsmAccess.begin("xxxx") == GSM_READY)
      notConnected = false;
    else {
      Serial.println("Not connected, trying again");
      delay(1000);
    }
  }
  
  Serial.println("Connected. Sending AT Command.");
  theGSM3ShieldV1ModemCore.println("AT+CNUM?");
  theGSM3ShieldV1ModemCore.println("AT+GSN?");
  theGSM3ShieldV1ModemCore.println("AT+CCLK?"); 
}

void loop()
{

}

And this is what I get in return:

Connecting to the GSM network
AT%13%
0 9>AT%13%%13%%10%OK%13%%10%
AT+CPIN=xxxx%13%
9 44>AT+CPIN=xxxx%13%%13%%10%+CPIN: READY%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
44 75>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
75 120>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%%13%%10%Call Ready%13%%10%
AT+CGREG?%13%
120 23>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
23 54>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
54 85>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
85 116>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
AT+IFC=1,1%13%
116 5>AT+IFC=1,1%13%%13%%10%OK%13%%10%
AT+CMGF=1%13%
5 21>AT+CMGF=1%13%%13%%10%OK%13%%10%
AT+CLIP=1%13%
21 37>AT+CLIP=1%13%%13%%10%OK%13%%10%
ATE0%13%
37 48>ATE0%13%%13%%10%OK%13%%10%
AT+COLP=1%13%
48 54>%13%%10%OK%13%%10%
Connected. Sending AT Command.
AT+CNUM?%13%%10%AT+GSN?%13%%10%AT+CCLK?%13%%10%

dtluigi:
Dear all,
do you know if is it possible to know the current time (hh/mm/ss) from the GSM network with the GSM Shield?

I wrote something similar for the SIM900 using AT commands. Depending on your GPRS chip, your AT command may be differnt, but the network response should be the same.

//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 
 
#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(2, 3);
 
void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate   
}
 
void loop()
{
/* if (mySerial.available())     Serial.write(mySerial.read());
 if (Serial.available())       mySerial.write(Serial.read());  
*/
  String mystr="";
  int i = 0;
  mySerial.println("AT+CCLK?");
  delay (500);
  while (mySerial.available()>0) {
    mystr += char(mySerial.read());
  }
  Serial.println("My String |"+mystr+"|");
  String clockString = "";
  int x = mystr.indexOf(String('"'))+1;   // Find the first occurance of an open quotation.  This is where we begin to read from
  int y = mystr.lastIndexOf(String('"')); // Find the last occurance of an open quotation. This is where we end.
  Serial.println(mystr.substring(x,y));   // This is the time string yy/mm/dd,hh:mm:ss-tz (tz in qtrs)

  while (Serial.read()<1); // Sit and do nothing
  
}

another way:
when you call a special number in order to know the phone credit, lot of carrier send you a message(free) with money and the TIMESTAMP..you can parse it..obviously this method it's not perfect..you could have an error of 30-60 seconds

m_ri:
another way:
when you call a special number in order to know the phone credit, lot of carrier send you a message(free) with money and the TIMESTAMP..you can parse it..obviously this method it's not perfect..you could have an error of 30-60 seconds

The idea is good, but how can you know the GSM operator of the SIM that will be used by another person? :wink: