How can I read date and time data from sim900 RTC module using arduino?
#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 am using sim 900 with arduino to detect input pin 5 change and then ALARM for user. I have several questions that need your help.
- How can I know which contact the sim 900 is using to send SMS? I am using a jumper on D2 and D3. Did they use these two contacts? because in my program I am using a .h include file which I didn’t know in detail inside it.
- How can I read date and time data from RTC in sim 900 module and store in variable and use it for datalogger later? I know if I have already set the date and time in the RTC can it be read "AT + CCLK"? and it returns date and time data. But how can I use this command in my program?
+3
source to share
1 answer
I found this code and it worked for me. You ask for time first, then wait for responses 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
}
+1
source to share