How to set the time of gsm a7670c by ntp server

THIS IS MY CODE BUT NOT WORKING

#include <HardwareSerial.h>
#if defined(CONFIG_IDF_TARGET_ESP32) 
    #define mySerial Serial2
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
    #define mySerial Serial1
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
   #define mySerial Serial2
#endif

String msg="";
void setup() 
{
  Serial.begin(115200);
  delay(500);
  pinMode(19,OUTPUT);
  #if defined(CONFIG_IDF_TARGET_ESP32) 
    mySerial.begin(115200);
 #elif defined(CONFIG_IDF_TARGET_ESP32S2)
    mySerial.begin(115200);
 #elif defined(CONFIG_IDF_TARGET_ESP32S3)
   mySerial.begin(115200, SERIAL_8N1, 18, 17);
 #endif
  delay(500);
  mySerial.println("AT+CCLK?");
  delay(100);
  update_serial();
mySerial.println("AT+CNTP=\"193.204.114.232\",20");delay(500);
  delay(100);
  update_serial();
mySerial.println("AT+CCLK?");
  delay(100);
  update_serial();

}
void loop() 
{     
  if (Serial.available()){
    char d = Serial.read();
    
    mySerial.write(d);
  }
 update_serial();

}

void update_serial()
{
    if (mySerial.available()) {
       msg = mySerial.readStringUntil('\n');
      Serial.println(msg);
    }
}

I AM FOLLWING THIS PDF OF AT COMMANDS
SIM7500_SIM7600_Series_AT_Command_Manual_V2.00.pdf (2.7 MB)

You may find it easier to use the +CCLK command to retrieve the local time from the cell network. That’s NTP derived anyway, so there you go

how to retrieve the local time from the cell network by +CCLK can you explain by some of line of code

Try reading ng the modem reference…
MANUAL PDF

More info

AT+CCLK=“08/11/28,12:30:33+32”
OK
AT+CCLK?
+CCLK: “08/11/28,12:30:35+32”
I saw these lines in manual but I don't want to set the time manually.

mySerial.println("AT+CCLK=\"24/04/02,16:14:00+20\"\r");delay(500);
  delay(100);

You request the time, then receive the response.
That’s it.
You need to separate (parse) the date and time elements out as you need it,
The next time you request the CCLK, it will have an updated time.

You NEVER have to set the time, it’s derived from the cell.

I want to say that once I set the the time after this I get the time by AT+CCLK? command
but what about the situation when GSM don't have power

If the modem is turned off, it’s unlikely to work.

is there other method ?

than what ?
if you want to use the modem - either to get the time from the cell, or an NTP server, it has to be turned on.

You could run a ‘time’ instance locally, and update it when the modem is connected, but the local tine will drift in the period between sync events.

no my question is that ones i set the time of modem … if I turn off the modem and then turn on it ….can I get the correct time without setting it again

Hello,

AT+CCLK read the "RTC" of your simcom module. If not set, you get the firmware time from bootup.
You need tell the simcom module, to fetch the gsm celltower time. This service is not enabled in some countrys and the clock is not always to be trusted. Its a matter of money.. You can ask the simcom module to fetch gsm celltower time with AT+QNITZ. You can also set the timezone with AT+CTZU. The gsm celltower broadcast (if any) within tens of minuttes. So, my opinion, useless function. I use simcom modules with GPS feature and parse the date and time. So, I get GPS time. After 13-14 minuttes, I get UTC time, with leap second compensation. You can use this time to set the Simcom "RTC" or a external RTC, like DS3231 and f.ex set the clock every 24 hours. You can also poll a NTP server over the internet. But then you need a very good code to verify the time and date, as the network may be down, busy or yield false data, that damage your program for execution.

how?
can you explain or give me AT command

first of all i dont have this command AT+QNITZ
secondaly i tried AT+CTZU is give me wrong time zone

If you have simcom module with gps function, power on the gps module: AT+CGPSPWR=1. Then, you can ask for a simcom made, sumarization string, of relevant data: AT+CGPSINF. You can also ask the simcom module for one nmea readout, our continous nmea readouts.

One benefit of using the cell time over GPS/NTP, is the time is automatically localised with DST applied when necessary.

first of all I don't have this command AT+QNITZ
secondly I tried AT+CTZU is give me wrong time zone

what about this?

My Solution to this Problem
Instead of using NTP, you can get the time directly from the network using the following AT commands:

Enable Automatic Time Update:

plaintext

AT+CTZU=1

This command enables the module to automatically update its internal clock from the network time.

Check the Current Time:

AT+CCLK?

Formate for this is +CCLK: "yy/MM/dd,hh:mm:ss±zz"

The time zone offset (±zz) is given in quarters of an hour (1/4 hour). For example, I live in Germany, so I get this response:

+CCLK: "24/08/29,01:14:17+08"

Here, +08 means the time zone is UTC+2 hours because 8 quarters of an hour equals 2 hours (8/4 = 2).

If you still get the wrong time zone. I have no idea don't ask me lol
Btw, what the hell is this thread? Only semi-useful replies to your problem. If Tordens had taken 5 seconds to Google, he would have realized that the A7670 does not have a GPS function

Your "solution" do not work, as the GSM towers general do not provide correct time. Google "nits problem" and voila, seems like your "solution" dont work and probably a better idea is to feth gps time and get a module that realy can do it without hassle.

Try to Send these AT commands in the following order after powering on the modem:

  1. AT&F – Reset parameters .
  2. AT+CTZU=1 – Enable automatic timezone update from the network.
  3. AT+CNTP="time.google.com",22 – Set your preferred NTP server.
  4. AT+CNTP – Sync the time.
  5. Wait 2–5 seconds (to allow sync to complete).
  6. AT+CCLK? – Retrieve the updated time.