11
\$\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\$
  • 1
    \$\begingroup\$ According to that hardware design document you need to obtain the "SIM800E AT Command Manual" - a separate document. \$\endgroup\$ – RedGrittyBrick Sep 12 '13 at 7:24
  • \$\begingroup\$ Then in practice how simple non-Multimedia phones update location? \$\endgroup\$ – gpuguy Sep 12 '13 at 8:27
  • 2
    \$\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\$ – RedGrittyBrick Sep 12 '13 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 Sep 12 '13 at 20:23
6
\$\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\$
  • 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\$ – RedGrittyBrick Sep 13 '13 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 Sep 13 '13 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\$ – Tibo Aug 18 '15 at 11:26
  • 1
    \$\begingroup\$ This answer is informing but deserves an update regarding the onboard RTC vs. network time problem. \$\endgroup\$ – Tibo Aug 18 '15 at 11:30
5
\$\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\$
4
\$\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\$
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\$
  • 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 May 6 '15 at 18:25
  • \$\begingroup\$ @David Stay tuned, we are working on a translation in the chat. \$\endgroup\$ – Nick Alexeev May 6 '15 at 19:37
  • 1
    \$\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\$ – Matt Thomas Jan 30 '17 at 20:21
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\$
  • \$\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 Apr 26 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, privacy policy and cookie policy

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