How to get live GPS Sim800 Module RTC time on Arduino

Hello I wanted the live GPS Sim800 Module RTC time on Arduino without the use of library, I am able to achieve it using library but without library the correct data comes in only 1 minute and other comes the garbage.

Please tell me the code that can help me achieve it

look how they did it in the library that works, you have source code access...

J-M-L:
look how they did it in the library that works, you have source code access...

I have the library code in cpp and header file

This is the code for getting time

void Sim800L::RTCtime(int *day,int *month, int *year,int *hour,int *minute, int *second)
{
this->SoftwareSerial::print(F("at+cclk?\r\n"));
// if respond with ERROR try one more time.
_buffer=_readSerial();
if ((_buffer.indexOf("ERR"))!=-1)
{
delay(50);
this->SoftwareSerial::print(F("at+cclk?\r\n"));
}
if ((_buffer.indexOf("ERR"))==-1)
{
_buffer=_buffer.substring(_buffer.indexOf(""")+1,_buffer.lastIndexOf(""")-1);
*year=_buffer.substring(0,2).toInt();
*month= _buffer.substring(3,5).toInt();
*day=_buffer.substring(6,8).toInt();
*hour=_buffer.substring(9,11).toInt();
*minute=_buffer.substring(12,14).toInt();
*second=_buffer.substring(15,17).toInt();
}
}

here you go, congrats, you now know which AT command to send to get the clock information.

if you don't use a library, I would suggest to study Serial Input Basics to handle the serial communication.


Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here

You have a choice..

The cellular time with AT+CCLK as above, which is convenient because it is automagically matched to the local TZ...
or, the UTC time from GPS, which you then need to offset to the local TZ, as well as DST offset when appropriate.

J-M-L:
here you go, congrats, you now know which AT command to send to get the clock information.

if you don't use a library, I would suggest to study Serial Input Basics to handle the serial communication.


Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here

I did the same thing with the code but what i got was garbage text instead of the time please check my stack overflow post to see the full code:-

please check my stack overflow post to see the full code

try a bit harder (and your link is not even clickable)... tens of thousands of forum members do it without any issue.. if you make it harder for people to help you, you won't get help... (read forum's rules)

I don't think it's a good use of my time either if you have posted in multiple places. I find that very disrespectful and thus will leave it to stack overflow's members to handle.

lastchancename:
You have a choice..

The cellular time with AT+CCLK as above, which is convenient because it is automagically matched to the local TZ...
or, the UTC time from GPS, which you then need to offset to the local TZ, as well as DST offset when appropriate.

But I am getting only garbage text instead of time sir. Please see I have done this only in my code

Check here please

Sorry, Very few of us will go off site to look at your code.
Garbage text either means a serial configuration problem, or you’re not capturing all the text (lost chars, handshaking etc)

I’m on a mobile here, so online code is by far the easiest, or if I’m on the desktop, attached files.

If you want help with your problem, then post the information the forum needs to help you here, not on some other forum ..........

Sorry Everyone for the inconvenience

#include <SoftwareSerial.h>
SoftwareSerial gsm(10, 11);
String Buffer;
String inData;

int i;
int *year, *month, *day, *hour, *minute, *second;

void setup() {
Serial.begin(9600);
gsm.begin(9600);
delay(5000);
}

void loop() {
Ansh:
delay(500);
gsm.println(“AT+CCLK?\r\n”);
while (gsm.available()) {
char recieved = gsm.read();
inData += recieved;
delay(100);

// Process message when new line character is recieved
if (recieved == ‘\n’)
{
Serial.print("Arduino Received: ");
Serial.println(inData);

if (inData.substring(1, 5) == “+CCLK”) {
Serial.println(“Hello”);
}

// You can put some if and else here to process the message juste like that:

if (inData == “+++\n”) { // DON’T forget to add “\n” at the end of the string.
Serial.println(“OK. Press h for help.”);
}

inData = “”; // Clear recieved buffer
goto Ansh;
}

/* Buffer = Buffer.substring(Buffer.indexOf(""") + 1, Buffer.lastIndexOf(""") - 1);
year = Buffer.substring(0, 2).toInt();
month = Buffer.substring(3, 5).toInt();
day = Buffer.substring(6, 8).toInt();
hour = Buffer.substring(9, 11).toInt();
minute = Buffer.substring(15, 17).toInt();
second = Buffer.substring(18, 20).toInt();
/
}/

Serial.println(*hour);
delay(100);
Serial.println(*minute);
delay(100);
Serial.println(*second);
delay(100);
*/
}
But I don’t get live output but after 1 correct output it returns garbage as follows

12:22:38.960 → Arduino Received: +CCLK: “20/10/04,12:22:31+22” 12:22:38.960 → 12:22:39.672 → Arduino Received: 12:22:39.672 → 12:22:40.596 → Arduino Received: OK 12:22:40.596 → 12:22:42.339 → Arduino Received: AT+CCLK?

12:22:42.339 → 12:22:44.362 → Arduino Received: +CCAT+CCLK?

12:22:44.362 → 12:22:46.067 → Arduino Received: AT+CCLK?

12:22:46.067 → 12:22:50.344 → Arduino Received: +CCLK: "20/10/04,12ATAT+CAT+CCLK?

12:22:50.344 → 12:22:52.043 → Arduino Received: AT+CCLK?

12:22:52.043 → 12:22:54.082 → Arduino Received: +CCAT+CCLK?

12:22:54.082 → 12:22:55.822 → Arduino Received: AT+CCLK?

12:22:55.822 → 12:23:00.064 → Arduino Received: +CCLK: "20/10/04,12:22:49AT+CCLK?

12:23:00.098 → 12:23:01.791 → Arduino Received: AT+CCLK?

12:23:01.791 → 12:23:03.810 → Arduino Received: +CCAT+CCLK?

12:23:03.845 → 12:23:05.552 → Arduino Received: AT+CCLK?

12:23:05.552 → 12:23:09.803 → Arduino Received: +CCLK: "20/10/04,12:22:58AT+CCLK?

12:23:09.838 → 12:23:11.544 → Arduino Received: AT+CCLK?

12:23:11.544 → 12:23:13.563 → Arduino Received: +CCAT+CCLK?

12:23:13.563 → 12:23:15.290 → Arduino Received: AT+CCLK?

12:23:15.290 → 12:23:19.557 → Arduino Received: +CCLK: "20/10/04,12:23:08AT+CCLK?

12:23:19.557 → 12:23:21.278 → Arduino Received: AT+CCLK?

if I remove the delays from the code then I receive the following output

12:34:56.406 → Arduino Received: (⸮⸮SCC⸮⸮CL?⸮

1-⸮

AT+CCLK?

AT+CCL~Q⸮ -j 12:34:56.473 → 12:34:56.541 → Arduino Received: ⸮5⸮⸮AT+CCLK?

⸮⸮⸮~⸮⸮ 1⸮j⸮b-⸮

AT+CCLK?

AT+C⸮~⸮⸮ 1-j⸮5⸮⸮(⸮i 1-⸮

AV⸮1-j 12:34:56.607 → 12:34:56.913 → Arduino Received: ⸮5⸮⸮J⸮jj⸮j AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CK5Q⸮ 1⸮j⸮5⸮⸮AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK⸮Q⸮ Zj⸮5⸮⸮(⸮⸮1-⸮

1⸮j⸮5j⸮ը(⸮CCP⸮i 1-⸮5Q⸮⸮j⸮jj⸮ը(j⸮jQb⸮⸮E⸮jj⸮(⸮⸮1-⸮5Q⸮ Zj⸮5⸮⸮(⸮⸮(j⸮jQ⸮Zj⸮5j⸮ը(⸮j⸮⸮ 1⸮j⸮⸮5j⸮(⸮⸮(⸮j⸮V 1-j 12:34:57.184 → 12:34:57.252 → Arduino Received: ⸮5⸮⸮D⸮j1-⸮

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

A 1-⸮

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCL~Q⸮ -j 12:34:57.354 → 12:34:57.561 → Arduino Received: ⸮5⸮⸮AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK? j AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+C⸮⸮5Q⸮⸮⸮Ԋi⸮j⸮(Q⸮⸮j⸮jj⸮ը(⸮CCP⸮i⸮j⸮ը(⸮CC⸮⸮⸮K? ⸮+CCLK?

AT+C⸮Q⸮Zj⸮5⸮⸮(Q⸮ -j 12:34:57.763 → 12:34:57.763 → Arduino Received: ⸮5⸮⸮E⸮jj⸮j AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT+CCLK?

AT⸮⸮z⸮⸮z⸮⸮b⸮⸮Қ⸮Ҫ⸮Z⸮⸮j 12:34:57.866 → 12:34:57.866 → Arduino Received: 12:34:57.905 → 12:34:57.905 → Arduino Received: OK 12:34:57.968 → 12:34:57.968 → Arduino Received: AT+CCLK?

12:34:57.968 → 12:34:57.968 → Arduino Received: +CCLK: “20/10/04,12:34:54+22” 12:34:58.037 → 12:34:58.037 → Arduino Received: 12:34:58.070 → 12:34:58.070 → Arduino Received: OK 12:34:58.070 → 12:34:58.070 → Arduino Received: AT+CCK ⸮⸮'I⸮)j⸮H(⸮5⸮ꨨH⸮)⸮Қ⸮Ҫ⸮Z⸮⸮j 12:34:58.138 → 12:34:58.138 → Arduino Received: 12:34:58.172 → 12:34:58.172 → Arduino Received: OK A+⸮1-⸮jRb҂⸮jjZ⸮⸮Ҫ⸮Z⸮⸮j 12:34:58.207 → 12:34:58.207 → Arduino Received:

That delay(100) could easily allow the incoming stream to overrun the buffer at 9600.
No delay necessary.

You can also use to present your code properly.

Where you are seeing “ CCLK: "20/10/04,12:23:08AT+CCLK?”
I suspect either the overflow noted, or you’re not clearing or parsing properly.
Check the response terminator… I suspect you’ll find it has a mix of CR & LF separating the lines.

The STRING type is not a good idea in AVR / small memory processors- that’s a whole ‘ other topic… search ARDUINO STRING PROBLEMS

goto Ansh :o :o :o ...

this is not the proper way to listen to the answer

 gsm.println("AT+CCLK?\r\n");
 while (gsm.available()) {
   char recieved = gsm.read();
   inData += recieved;
   delay(100);

you are at risk of loosing input or not reading enough of the answer

don't try to second guess the timing of an asynchronous protocol. I would suggest to study Serial Input Basics to handle this


Please read the forum rules once for all and correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)