storing AT command response

Helloo everyone !
Im using a M10 GSM/GPRS Shield and I had to know how to get the time without using an external RTC, so i used AT command to get it, but the problem is that i have to use that incoming information, maybe store it into a variable !

so here is what Im using in the code :

void loop()
{
 
 Serial.println("Sending AT Commands.");
 
 send_command("AT+CCLK?",1000);
 
 while(true);
}
void send_command(String AT_COMMAND, int tDelay){
 Serial.print("COMMAND: "+AT_COMMAND);
 Serial.println(modemAccess.writeModemCommand(AT_COMMAND,tDelay));
 Serial.println("-----------------------------------------------");
}

and this is the response that Im getting over the serial monitor :
Connecting to the GSM network
Connected.
Sending AT Commands.
COMMAND: AT+CCLK?
+CCLK: "04/01/01,00:01:12+00"

OK


i want to store that : 04/01/01,00:01:12
:confused:
any kind of help is appreciated !! thank youuu

I ran into the same issue grabbing the IP from an ESP8266. This bit of code should help.

Serial.find("+CCLK: \"");
  Serial.readBytesUntil('\+"', MYData, 17);

MYData is the array to store it in so you will want that set as char MyData[18].

thank you very much !
but I don't know why i have an error msg when i add it to the code :confused: :

prog2time.ino: In function 'void loop()':
prog2time.ino:39:30: error: 'send_command' was not declared in this scope
Erreur lors de la compilation.

and when i delete the + here :

Serial.readBytesUntil('+"', MYData, 17);

then there is no error but no results :confused:
what am i doing wrong ? :confused:

My mistake, that should have read

Serial.find("+CCLK: \"");
  Serial.readBytesUntil('\+', MYData, 17);

Im not getting anything in return ...
a little more help please :confused: ?

a little more help please :confused: ?

We can assume that you implemented the suggested changes correctly, or we can assume that you butchered the code royally. Which do you think is more likely?

Well, Ummmmm, i guess it's more the second one because i didn't get the results that i want, here is the code :

void loop()
{
 
 Serial.println("Sending AT Commands.");
 
 send_command("AT+CCLK?",1000);
 Serial.find("+CCLK: \""));
  Serial.readBytesUntil('\+', MYData, 17);
}
void send_command(String AT_COMMAND, int tDelay){
 Serial.print("COMMAND: "+AT_COMMAND);
 Serial.println(modemAccess.writeModemCommand(AT_COMMAND,tDelay));
 Serial.println("-----------------------------------------------");
}

with char MYDate[18];
so
Im getting the same results as earlier :
Connecting to the GSM network
Connected.
Sending AT Commands.
COMMAND: AT+CCLK?
+CCLK: "04/01/01,00:01:12+00"

OK


Are you using Serial to talk to the phone? Or are you using it to talk to the PC? Both is wrong answer. So is yes.

Once you read data from the serial port, and store it in MYData, you are not printing what is in MYData, so of course the results are going to be exactly the same.

i added Serial.print(MYData) and i delete it because i wasn't getting anything

find() reads data from the stream until the target string of given length is found The function returns true if target string is found, false if timed out.

So, wouldn't it be nice to know if find() found +CCLK: "? Before you assume that the rest of the data will be present?

yeah it would be so nice :smiley: I agree !! but what if i still don't get anything new in return !
if you know how it should be done, can you pleaaaaaaaaaaaaaaaaase tell me, i need help because i still have a lot of things to do and not too much time ! i never used find() neither readbytesuntil and i didn't find how using it in arduino website reaally clear ! so please if you already know how, just tell me :confused:

so please if you already know how, just tell me

I'm supposed to know whether the reply contains the string you are trying to find? I don't think so.

You need to do something like:

if(Serial.find("+CCLK: \""))
{
   Serial.readBytesUntil('\+', MYData, 17);
}
else
   Serial.print(F("Did not find \"+CCLK: \" in the response stream"));

Now, are you using Serial to talk to the modem? Or, are you using Serial to talk to the PC? Both is the wrong answer. So is yes.

I tried this above code but i got output as did not find the response. How should i rectify it?