I am writing an SIM900A + arduino(Arduino UNO with Atmega 328P) code to just send the current time stamp every 20 minutes.
The code keeps crashing in the SendMessage()
function as the setup prints keep coming again and again. Please let me know what I am doing wrong. Thanks in advance
#include <SoftwareSerial.h>
#include <LowPower.h>
SoftwareSerial mySerial(9, 10);
char msg;
char call;
int ctr;
#define TIME_STR_LEN 100 // the actual number of characters for date and time
char timeStamp[TIME_STR_LEN]; // holds the time string
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
Serial.println("GSM SIM900A BEGIN");
mySerial.println( "AT+CLTS=1");
delay(1000);
ctr = 0;
delay(10000);
}
void loop()
{
if(mySerial.available()>0)
{
while (mySerial.available()>0)
{
mySerial.read();
}
}
if (ctr%1 == 0)
{
delay(1000);
SendMessage();
delay(100);
ctr = 0;
Serial.println("just sent a message");
}
delay(60000);
ctr++;
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
}
void SendMessage()
{
mySerial.println( "AT+CCLK?" );
delay(2000);
int i = 0;
if (mySerial.available()>0)
{
while (mySerial.available()>0 && i < TIME_STR_LEN)
{
timeStamp[i]=(mySerial.read());
i++;
}
}
delay(2000);
mySerial.println("AT+CMGF=1");
delay(1000);
mySerial.println("AT+CMGS=\"xxxxxxxxxx\"\r");
delay(1000);
mySerial.println("Motor is ON ");
delay(100);
mySerial.println(timeStamp);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}