Troubles getting time on MKR GSM 1400

Hi everyone,

I'm using the library : #include <MKRGSM.h>
I have a problem when I try to get the time with the command:

MODEM.send("AT+CCLK?");
if (MODEM. waitForResponse(100, &response) != 1) 
{
  Serial. println("Issue while acquiring AT+CCLK?, reset after wacthdog's timer");
  while(1) {}
}
Serial.println(response);

Answer--> +CCLK: "04/01/01,00:00:38+04" which corresponds to the factory-programmed value. Instead of this, I should have something like +CCLK: "22/12/28,16:11:38+04" corresponding to the actual date.

Any ideas ?

Do you have a valid SIM and network connection? I think the time comes from syncing with cell towers

Hi JML,
Yes I have a valid SIM and network connection, I was able to send a receive SMS.
Here is an example of my code :

#include <MKRGSM.h>

GSM gsmAccess;

void setup() {
  Serial.begin(9600);
  
  bool connected = false;
  while (!connected) {
    if (gsmAccess.begin("") == GSM_READY) {
      connected = true;
    } else {
      Serial.println("Not connected, we retry");
      delay(1000);
    }
  }

  String response;
  MODEM.send("AT+CCLK?");
  if (MODEM.waitForResponse(100, &response) != 1) {
    Serial.println("Issue while acquiring answer");
  }
  Serial.println(response);
}

void loop() {
  delay(100);
}

Returning : +CCLK: "04/01/01,00:28:27+04"

Have you tried AT+UTIME?

Indeed the answer could be there.
When I send AT+UTIME? it returns +UTIME: 0,0,0
So I tried to send AT+UTIME=2,3 but no answer

Do I writing AT+UTIME=2,3 badly?

May be

Have you tried to read what .getTime(); sees ?

Actually they send the same thing

Serial.println(gsmAccess.getTime()); --> 1072920213 corresponding to 01/01/2004 02:23:33

And when I power off the module and restart it, I have the factory time : 1072915255 --> 01/01/2004 01:00:55

Yes indeed, I checked too the librairy

May be it depends on provider supporting the GSM time signal?

I did some other tests. Finally I manage to recover the date, then I lose it again. I feel like it's network dependent, even though my arduino hasn't moved. It's a shame, but this thing does not suit me, I will have to go on an external RTC module I think, unless someone has an explanation?

If you can make an NTP request then you could get the time from the internet without adding an RTC

I'm not used to these technologies but I tried this code to send NTP request:
docs-content/mkr-gsm-library-examples.md at main · arduino/docs-content · GitHub

I adapted it for my time zone and it works well, thank you!

Do you know what the data consumption is for sending a request? I only have 50MB of data per month. I think updating the time once every hour is enough? Or even a day would be ok.

NTP is a UDP-based protocol and NTP packets are relatively small, and without any optional extensions the incoming and outgoing packets are usually 76 bytes in length.

The NTP time stamp is in the first 48 bytes of the message so you might even be able to ignore everything else.

You could possibly fetch time once a day and use a time library. If the clock on your MKR GSM 1400 is ok, you should not diverge too much from the real time

may be explore GitHub - PaulStoffregen/Time: Time library for Arduino

Thats also my experience, you can't rely on this. NTP (as suggested by J-M-L Jackson) or a regular http get request on a custom made website with the desired time format?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.