How get Date/time from sim900 via sms

hello to all. i have a problem i dont know how can i store the date and time from sim900 in a string and sendit to my phone i have do some object this is my code

/*Note:This code is used for Arduino 1.0 or later*/
#include <SoftwareSerial.h>
#include <string.h> 
SoftwareSerial Sim900Serial(2, 3);
byte buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array
#define phonenumber "+30xxxxxxxxxx"  //Change to your phonenumber, the phonenumber should be the same as the format received by the SMS, may include your country code.
int led = 5;
char stat;
void setup()
{
  digitalWrite(7, HIGH);
  delay(1000);
  digitalWrite(7, LOW);
  delay(2200);
  Sim900Serial.begin(19200);               // the SIM900 baud rate   
  Serial.begin(19200);             // the Serial port of Arduino baud rate.
  delay(500);
  Sim900_Inti();
  pinMode(led, OUTPUT); 
}

void loop()
{
  if (Sim900Serial.available())              // if date is comming from softwareserial port(data is comming from gprs shield)
  {
    while(Sim900Serial.available())          // reading data into char array 
    {
      buffer[count++]=Sim900Serial.read();     // writing data into array
      if(count == 64)break;
    }
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    Cmd_Read_Act();                        //Read the 'COMMAND' sent to SIM900 through SMS
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero


  }
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    Sim900Serial.write(Serial.read());       // write it to the GPRS shield
}
void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<count;i++)
  { 
    buffer[i]=NULL;
  }                  // clear all index of array with command NULL
}
void Sim900_Inti(void)
{
  Sim900Serial.println("AT+CMGF=1");
  delay(500);
  Sim900Serial.println("AT+CNMI=2,2,0,0,0");
  delay(500);
}
void Cmd_Read_Act(void)          //This function read the SMS sent to SIM900 shield, then act based on the command.
{  
  char buffer2[64];
  char comparetext[25];    //take out the first part of the SMS which include the phoneunmber
  for (int i=0; i<count;i++)
  { 
    buffer2[i]=char(buffer[i]);
  }  
  memcpy(comparetext,buffer2,25); //take out the first part of the SMS which include the phoneunmber
  if (strstr(comparetext,phonenumber))
  {      
    if (strstr(buffer2,"ON"))            //If there are word 'ON' in the SMS, turn on GPIO 1 of SIM900
    {
      // Sim900Serial.println("AT+SGPIO=0,1,1,1");// set GPIO 1 PIN to 1
      digitalWrite(led, HIGH);
      SendTextMessageON();
      delsms();
    }
    if (strstr(buffer2,"OFF"))        //If there are word 'OFF' in the SMS, turn off GPIO 1 of SIM900
    {
      digitalWrite(led, LOW);
      SendTextMessageOFF();
      delsms();
      // Sim900Serial.println("AT+SGPIO=0,1,1,0");// set GPIO 1 PIN to 0
    }
    if (strstr(buffer2,"STATUS"))        //If there are word 'OFF' in the SMS, turn off GPIO 1 of SIM900
    {

      statusread(); 
    }  
  } 
}

void SendTextMessageON()
{
  Sim900Serial.println("AT+CMGF=1\r");    //Sending the SMS in text mode
  delay(500);
  Sim900Serial.println("AT + CMGS = \"+xxxxxxxxxx\"");//The target phone number
  delay(500);
  Sim900Serial.println("LED 5 IS ON");//the content of the message
  delay(500);
  Sim900Serial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(500);
  Sim900Serial.println();
}

void SendTextMessageOFF()
{
  Sim900Serial.println("AT+CMGF=1\r");    //Sending the SMS in text mode
  delay(500);
  Sim900Serial.println("AT + CMGS = \"+xxxxxxxxxx\"");//The target phone number
  delay(500);
  Sim900Serial.println("LED 5 IS OFF");//the content of the message
  delay(500);
  Sim900Serial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(500);
  Sim900Serial.println();
}

void statusread()
{ 
  Sim900Serial.println("AT+CCLK?");    //read the time
  delay(500);
}

void delsms()
{
  Sim900Serial.println("AT+CMGDA =\"DEL ALL\"");
  delay(500);
  //Sim900Serial.println("AT+CMGD=1,4");
  //delay(500);
}

how can i store the recive value of AT+CCLK? in a string to send it in sms?
any help or idea thanks to all :slight_smile:

anyone please guys how can read the serial reply from sim900 and store it to a variable or string ?

?

 void SendTextMessage()
{    mySerial.println( "AT+CCLK?" );
 mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
 delay(100);
 mySerial.println("AT + CMGS = \"+86138xxxxx615\"");//send sms message, be careful need to add a country code before the cellphone number
 delay(100);
 mySerial.println("the time is");//the content of the message
 delay(100);
     mySerial.write(mySerial.read() );
 mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
}

Can't your phone tell you when a text arrived?

if i will do this the arduino send me the firs character of AT+CCLK? that meas send me back the time is A

i want to store the reply from sim 900 in the string for example "14/06/13 19:50:12" in sms back to me ..
sorry for my english do you unterstand what i mean ?

i write this but i have a problem the string is the command not the reply from the AT+CCLK? for example "14/06/13 19:50:12"

String time()
{
  String content = "";
  char character;
  Sim900Serial.println("AT+CCLK?");    //read the time
  delay(500);
  while(Sim900Serial.available()) {
    character = Sim900Serial.read();
    content.concat(character);
  }

  if (content != "") {
    return (content);
  }
}

Yes I understand what you mean. I was just guessing as I have not got my SIM900 running yet because of the power supply.

What I am sure about is that examples using the clock are virtually impossible to find - but I guess you are already aware of that - and I can only assume it is because nobody uses it. There is a hint of this in that the manufacturers never bother about supplying a battery with the shield, which suggest they aren't serious about the clock.

You might try dannable, who might have progressed a bit further by now

http://forum.arduino.cc/index.php?topic=246168.msg1760741#msg1760741

This is shaping up to be a whole new realm for me - all about manipulation of string data.

Did you ever get this working?

How i can enable or disable received sms date and time.