How can I read date and time data from RTC of sim900 module using arduino?

Guitargang picture Guitargang · Jun 4, 2015 · Viewed 11.3k times · Source
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"

SMSGSM sms;

boolean started=false;
int count = 0;


void setup()
{
 pinMode(5, INPUT);          // input pin for switch  
 Serial.begin(9600); 
 if (gsm.begin(2400))
 {
   Serial.println("\nstatus=READY");
   started=true;  
 }
 else Serial.println("\nstatus=IDLE");
 delay(1000);  
}


void loop()                                    
{
  if (digitalRead(5)==1) 
  {
    delay(500);
    if (digitalRead(5)==1)
    {
      count = count+1;
      /*if(started)
      {
        if (sms.SendSMS("+12345678", "ALARM"))
        Serial.println("\nSMS sent OK");
      }*/          
      Serial.println("Count = ");
      Serial.println(count); 
      readtime();
      Serial.println(content);
    }

  }
  else 
  {
    Serial.println("Normal");
  }
}

I use sim 900 with arduino to detect change of input pin 5 and then ALARM to user. I have a few question that need your help

  1. How can I know which pin that sim 900 use to communicated for sent sms? I use jumper at D2 and D3. Did it use these two pins? because in my program I use an .h include file which I didn't know detail inside it.
  2. How can I read date and time data from RTC in sim 900 module and store in a variable and use them for data logger later? I know that if I have already set date and time in RTC, it can be read by "AT+CCLK?" and it return date and time data. But how can I use this command in my program?

Answer

jabujavi picture jabujavi · Jun 5, 2015

I found this code and work for me. First you ask for time and then expect answers and parse it.

const char* const  SIM900::getTimeStamp(){
 Serial2.print("AT+CCLK?");      //SIM900 AT command to get time stamp
 Serial2.print(13,BYTE);
   delay(2000);
 if (Serial2.available()>0){
   int i = 0;
           while (Serial2.available()>0){
                 timeStamp[i]=(Serial2.read());
              i++;              
           }

       }
  int years = (((timeStamp[25])-48)*10)+((timeStamp[26])-48);
  int months = (((timeStamp[22])-48)*10)+((timeStamp[23])-48);
  int days  = (((timeStamp[19])-48)*10)+((timeStamp[20])-48);
  int hours = (((timeStamp[28])-48)*10)+((timeStamp[29])-48);
  int mins = (((timeStamp[31])-48)*10)+((timeStamp[32])-48);
  int secs = (((timeStamp[34])-48)*10)+((timeStamp[35])-48);
  //YOUR CODE HERE
}