15
\$\begingroup\$

I am using SIM800E. I want to know what AT command should be sent to the modem to get time? This modem has a RTC. But I need to set it automatically through cell tower. The tower can send the time to the modem when requested using an AT command. I have seen in many phones that the time is updated during hand-offs.

The manual does not have this information.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ According to that hardware design document you need to obtain the "SIM800E AT Command Manual" - a separate document. \$\endgroup\$ Commented Sep 12, 2013 at 7:24
  • \$\begingroup\$ Then in practice how simple non-Multimedia phones update location? \$\endgroup\$
    – gpuguy
    Commented Sep 12, 2013 at 8:27
  • 3
    \$\begingroup\$ NITZ is an optional part of the GSM standards, not supported by all carriers and may not be accurate to better than a few minutes. \$\endgroup\$ Commented Sep 12, 2013 at 8:43
  • 3
    \$\begingroup\$ I believe this is on topic because it concerns the use of an embedded GSM module for M2M communications. Why is this post off-topic, and the four posts following were allowed: example 1 2 3 4 \$\endgroup\$
    – tcrosley
    Commented Sep 12, 2013 at 20:23

10 Answers 10

9
\$\begingroup\$

I have used the following command:

AT+CCLK?

which returns the date and time, like:

+CCLK: "00/01/12,05:44:53+00" 

successfully in products using three different cell modules: Enfora, Telit, and Sierra. The fact that it uses a + character after the AT implies it is a common (as opposed to proprietary) command, and should be available on most if not all cell modules. (Proprietary commands use a vendor specific character after the AT, like AT$, AT%, AT! etc.)

As I mentioned in a comment, if you can't get the time using this command (for example, it returns all 0's), then another way is to connect to the network and get the time off of a server using an HTTP command.

For example, the following HTTP request:
HEAD /index.html HTTP/1.1\r\n
Host: www.somehost.com\r\n;
\r\n

where somehost is either your own server or Google.com etc. This also assumes index.html is the main page for the site (not the case for Google).

It will return a header like:

HTTP/1.x 200 OK  
Transfer-Encoding: (something)  
Date: Fri, 13 Nov 2013 04:36:25 GMT
(lots more stuff)

As far as I know, all severs are obligated to return GMT time in their headers.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Some stuff I read suggested the value returned by +CCLK may be from the on-board clock (RTC), not from the GSM network (tower). \$\endgroup\$ Commented Sep 13, 2013 at 21:04
  • 1
    \$\begingroup\$ I have read the command described that way also, however I have been using it in several different products using three different cell modules over the last five years or so, and it has worked just about everywhere in the US and also Europe and Asia. There has been a few carriers, for example one in Germany, where it didn't work (returned all 0's); I contacted them and were told they didn't support time updates over the network. So I wrote code to do an HTTP 1.1 request and grab the time off of a server. \$\endgroup\$
    – tcrosley
    Commented Sep 13, 2013 at 21:51
  • 1
    \$\begingroup\$ I think the HTTP request could be better written as HEAD / HTTP/1.0\r\nHost: example.com\r\n\r\n as I feel / is less prone to 404s and that HTTP 1.0 better represents our (device-wise) ignorance of HTTP. Besides, the semicolon looks like a typo. Other than that, the date is GMT/UTC by specification (see also). \$\endgroup\$
    – user72833
    Commented Aug 18, 2015 at 11:26
  • 1
    \$\begingroup\$ This answer is informing but deserves an update regarding the onboard RTC vs. network time problem. \$\endgroup\$
    – user72833
    Commented Aug 18, 2015 at 11:30
6
\$\begingroup\$

First of all, NITZ is poorly supported in many networks (can you say COST-CUTTING). I would not rely on it at all as 1 in 10 networks use it, especially in far flung places.

Secondly +CCLK command is for the internal RTC of the modem. Some modems have facilities to update this clock from the network. Relying on this is risky.

The above HTTP request is incomplete i.e. it doesn't work. I used to know how to do this so will revert back when it works.

The fact that it uses a + character after the AT implies it is a common (as opposed to proprietary) command, and should be available on most if not all cell modules. (Proprietary commands use a vendor specific character after the AT, like AT$, AT%, AT! etc.)

This is not entirely true. There are proprietary modem commands that follow the AT+ convention. For example AT+WOPEN is a proprietary Sierra command.

There are a certain set of commands that are the same regardless of modem. These are defined in the 3GPP documents. The proprietary commands are usually defined in the vendor's user manuals and clearly marked as being proprietary.

\$\endgroup\$
6
\$\begingroup\$

AT+CLTS=1 ( Get local time stamp ) AT&W ( Save configuration )

Turn off modem and turn on modem(reboot to get local time from network)

Next time when modem boots up you should be able to get local time by network and can be read by sending

AT+CCLK?

This worked for me i m using SIM800 GSM modem read AT command descriptions for more information

\$\endgroup\$
1
  • \$\begingroup\$ @s0nic2k answer confirmed, this would NOT work as you would expect. \$\endgroup\$
    – Ali80
    Commented Dec 9, 2019 at 12:39
3
\$\begingroup\$

PuTTY:

AT+COPS=2

OK

AT+CTZU=1

OK

AT+COPS=0

OK

+CTZU: "15/05/06,17:25:42",-12,0

Works perfectly, after that you have to parse the result and place in clk because this does not happen automatically. (at least in my Cinterion)

\$\endgroup\$
3
  • 6
    \$\begingroup\$ It would help if you could explain, in English, what this does and why it is a solution to the question. \$\endgroup\$
    – David
    Commented May 6, 2015 at 18:25
  • \$\begingroup\$ @David Stay tuned, we are working on a translation in the chat. \$\endgroup\$ Commented May 6, 2015 at 19:37
  • 2
    \$\begingroup\$ Variant for SIM800H that worked for me: use AT+CLTS=1 instead of AT+CTZU=1 (since CTZU isn't supported). Then you'll get an unsolicited message like *PSUTTZ: 2017,1,30,20,17,28,"-20",0 when you reregister \$\endgroup\$ Commented Jan 30, 2017 at 20:21
2
\$\begingroup\$

Use AT+CIPGSMLOC command. It works well in SIMCOM modules.

This command needs the GPRS service attached before you use it. So first attach the GPRS service using appropriate command sequence then use this command to get date and time from GSM network.

For attaching GPRS service:

CMD:AT+CGATT=1 CMD:AT+SAPBR=3,1,"Contype","GPRS" CMD:AT+SAPBR=3,1,"APN","" CMD:AT+SAPBR=3,1,"USER","" CMD:AT+SAPBR=3,1,"PWD","" CMD:AT+SAPBR=1,1 CMD:AT+SAPBR=2,1 /* to confirm that GPRS is attached. will show IP if attached */

Then use GSM Location command:

AT+CIPGSMLOC=1,1

This command needs considerable time (few seconds) to get the information from network so give the command execution function proper timeout.

This command also returns the BTS location which the module is connected to. So you can get a roughly accurate location of the GSM module as well.

Refer to this manual for more information: (works the same way for SIM800)

SIM900_GSM Location AT Command Manual_V1.00

Also note that the AT+CLBS command is not the same as this command. It may not work in some regions. (I haven't been able to use it!). But the AT+CIPGSMLOC always works.

\$\endgroup\$
3
  • \$\begingroup\$ I get +CIPGSMLOC: 302<\r><\n> in response \$\endgroup\$
    – Ali80
    Commented Dec 9, 2019 at 12:47
  • 1
    \$\begingroup\$ @Ali80 Recharge your simcard credit. This might happen if your simcard does have credit but haven't been charged for a long time. You can test with another simcard as well. \$\endgroup\$
    – MDR
    Commented Dec 11, 2019 at 4:45
  • \$\begingroup\$ yeah I can confirm this method works, my simcard had credit but had some data plan limited access. \$\endgroup\$
    – Ali80
    Commented Dec 11, 2019 at 6:33
1
\$\begingroup\$

NITZ as pointed out by RedGrittyBrick is the answer. However, this is a message that's sent by the network only, usually on joining the network. Some carriers send it, some don't. There's no standard way to request it.

\$\endgroup\$
1
\$\begingroup\$

Here is the AT command sequence to get the cellular network time.It worked in my UBLOX LEON G-200 GSM module.

GSM_Send_Modem_Command("AT+COPS=2\r\n");//de register
GSM_Send_Modem_Command("AT+CTZU=1\r\n");//automatic time zone update is enabled
GSM_Send_Modem_Command("AT+COPS=0\r\n");// register to network
GSM_Send_Modem_Command("AT+CCLK?\r\n");// gets the clock of the MT
\$\endgroup\$
1
\$\begingroup\$

first send this two command
AT+CLTS=1;&W

AT+CFUN=1,1 and than AT+CLTS? check whether you get this reply +clts: 1
and than send this command AT+CCLK?

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to EE.SE. Use two back-ticks (``) around code snippets in your posts or use the {} button on the editor toolbar for blocks of code as in the other answers. This will give a grey background and fixed width font making it easy to see where your code starts and ends. \$\endgroup\$
    – Transistor
    Commented Apr 26, 2019 at 8:50
0
\$\begingroup\$

I've successfully used NITZ during initialisation, and CCLK when I want to read the internal RTC. HOWEVER it can take a minute or two before the modem RTC is set from the network. It's worth maintaining a flag to indicate if the time is indeed valid.

\$\endgroup\$
0
\$\begingroup\$

I developed a firmware for a U-Blox LTE. There I used the AT+CCLK? to obtain the current local time from the modem.

It gives a time in following format. Not that it's a synchronized command.

+CCLK: "00/01/01,05:44:53+00" (might get unsynchronized time if the modem time is not sync with the system time)

So the following AT command was sent prior to the registration, to sync the time with the network

AT+CTZU=1\r\n

So my command sequence is:

AT+CTZU=1\r\n
AT+CREG=1\r\n (to subscribe for the network registration updates)
AT+CCLK?\r\n (The Time Zone information is provided after the network registration, if the network supports the time
zone information)

Additional logic to ensure that it has the correct time:

It checks the date against 70/01/01 or 00/01/01 (in our case, those are the times that we get if the modem has an invalid time). And if it's invalid it tries periodically every 1 minute till it gets a correct time. After few retries stops sending CCLK? and rely on other time sources.

Note: NITZ is supported in limited set of countries yet (https://en.wikipedia.org/wiki/NITZ)

So it's best to have a backup way of updating time if it's not supported in that country.

In my case we have GPS module so I obtain time updates through GNSS data.

Additionally, which is not relevant here, but thought useful for time synchronisation.

We run chrony deamon to update the system time (manual commands enabled). So both time updates are fetched and chrony decides the correct time and updates the system time.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.