I am trying to check the time from the GSM module to let my code run or do nothing.
If I send the command, AT+CCLK? to the SIM900. This is the response:
AT+CCLK?
+CCLK: "17/02/14,16:58:25-20"
OK
How do I parse the time information from the SIM900 and setup a loop for my code to run if it is past 6pm but before 6am?
My code currently:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7,8); //RX,TX
void setup() {
PowerOn(); //power on GSM Module
delay(10000); //delay 10 seconds
SIM900.begin(19200); //software serial for GSM Shield
delay(500);
}
void loop() {
// if time is past 6pm and before 6am send text message else do nothing
SendTextMessage();
}
///GetTime
void GetTime()
{
SIM900.print("AT+CCLK?");
}
///SendTextMessage
void SendTextMessage()
{
SIM900.print("AT+CMGF=1\r");//Because we want to send the SMS in text mode
delay(100);
SIM900.println("AT + CMGS = \"+12137777777\"");//send sms message, be careful need to add a country code before the cellphone number
delay(100);
SIM900.println("Motion Detected!");//the content of the message
delay(100);
SIM900.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
SIM900.println();
}
///PowerOn
void PowerOn()
{
///software equivalent of pressing the GSM shield "power" button
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}