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