15

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.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
gpuguy
  • 1,618
  • 8
  • 31
  • 54
  • 1
    According to that hardware design document you need to obtain the "SIM800E AT Command Manual" - a separate document. – RedGrittyBrick Sep 12 '13 at 07:24
  • Then in practice how simple non-Multimedia phones update location? – gpuguy Sep 12 '13 at 08:27
  • 3
    [NITZ](http://en.wikipedia.org/wiki/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. – RedGrittyBrick Sep 12 '13 at 08:43
  • 3
    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](http://electronics.stackexchange.com/questions/79174/gsm-gprs-at-command-hitting-a-link) [2](http://electronics.stackexchange.com/questions/26238/why-do-people-use-at-commands-in-serial-communication) [3](http://electronics.stackexchange.com/questions/33421/how-to-call-at-command-on-xbee-from-arduino) [4](http://electronics.stackexchange.com/questions/74587/xbee-doesnt-respond-to-command-sequence) – tcrosley Sep 12 '13 at 20:23

10 Answers10

9

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.

tcrosley
  • 47,708
  • 5
  • 97
  • 161
  • 1
    Some [stuff](http://note19.com/2009/06/30/how-to-setup-network-time-on-telit-module/) I [read](http://en.wikipedia.org/wiki/Motorola_phone_AT_commands) suggested the value returned by +CCLK may be from the on-board clock (RTC), not from the GSM network (tower). – RedGrittyBrick Sep 13 '13 at 21:04
  • 1
    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. – tcrosley Sep 13 '13 at 21:51
  • 1
    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](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18) ([see also](http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1)). –  Aug 18 '15 at 11:26
  • 1
    This answer is informing but deserves an update regarding the onboard RTC vs. network time problem. –  Aug 18 '15 at 11:30
6

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

Sumit Dubey
  • 61
  • 1
  • 2
6

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.

s0nic2k
  • 71
  • 2
3

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)

gre_gor
  • 107
  • 6
died74
  • 31
  • 1
  • 6
    It would help if you could explain, in English, what this does and why it is a solution to the question. – David May 06 '15 at 18:25
  • @David Stay tuned, we are working on a translation in the chat. – Nick Alexeev May 06 '15 at 19:37
  • 2
    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 – Matt Thomas Jan 30 '17 at 20:21
2

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.

MDR
  • 21
  • 2
  • I get `+CIPGSMLOC: 302<\r><\n>` in response – Ali80 Dec 09 '19 at 12:47
  • 1
    @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. – MDR Dec 11 '19 at 04:45
  • yeah I can confirm this method works, my simcard had credit but had some data plan limited access. – Ali80 Dec 11 '19 at 06:33
1

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
Myanju
  • 213
  • 1
  • 3
  • 9
1

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?

  • 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. – Transistor Apr 26 '19 at 08:50
1

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.

pjc50
  • 46,540
  • 4
  • 64
  • 126
0

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.

M C
  • 1
0

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.

SajithP
  • 101
  • 2