I write the Serial.print("AT+CCLK"); in "void loop2" but I don´t get the hour. With Serial.print("AT+CMGS=""); I send the sms to a phone number whit out problem but with AT+CCLK I can´t get what I want...
This is the code (you help me with it in another topic):
#include <Keypad.h>
//VARIABLES ENVIO DATOS
int led = 13;
int onModulePin = 2; // Definimos el Pin 2 para activar o desactivar el modulo 3G (sin pulsar el botón)
int timesToSend = 1; // Numero de sms a enviar
int count = 0;
char phone_number[]="*********"; // ********* numero que recibirá el sms
//VARIABLES TECLADO
const byte ROWS = 4; //4 filas
const byte COLS = 3; //3 columnas
char keys[ROWS][COLS] = {
{
'1','2','3' }
,
{
'4','5','6' }
,
{
'7','8','9' }
,
{
'*','0','#' }
};
byte rowPins[ROWS] = {
7, 6, 5, 4}; // reserva de memoria en bytes, conectar a los pines de filas del teclado
byte colPins[COLS] = {
10, 9, 8}; // reserva de memoria en bytes, conectar a los pines de columnas del teclado
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char serialnumber[10]="6103722";
char usuario1[]="111#";
char usuario2[]="222#";
char usuario3[]="333#";
char usuario4[]="444#";
char usuario5[]="555#";
char attempt[]="0000"; // usado para comparar
int z=0;
int sal1 = 11; // salida led verde pin 11
int sal2 = 12; // salida led rojo pin 12
char attempt2[5]="0000";
//PROGRAMA
void setup()
{
pinMode(sal1, OUTPUT);
pinMode(sal2, OUTPUT);
Serial.begin(115200); //Configura la velocidad del puerto serie
keypad.setHoldTime(150); // Tiempo de pulsado de boton. Default is 1000mS
keypad.setDebounceTime(30); // Tiempo de rebote de bootn. Default is 50mS
Serial.println(" Introduzca PIN: ");
}
void leds()
{
if (sal1 == LOW)
sal2 = HIGH;
else
{
sal2 = LOW;
}
}
void checkPIN()
{
Serial.print("attempt: [");
Serial.print(attempt);
Serial.print("]");
int correct = 0;
if(strcmp(attempt, usuario1) == 0)
correct = 1;
else if(strcmp(attempt, usuario2) == 0)
correct = 2;
else if(strcmp(attempt, usuario3) == 0)
correct = 3;
else if(strcmp(attempt, usuario4) == 0)
correct = 4;
else if(strcmp(attempt, usuario5) == 0)
correct = 5;
if ( correct=!0)
{
Serial.println("PIN OK");
digitalWrite(11, HIGH); // activa un contacto
for (int zz=0; zz<=4; zz++) // borrar el último código introducido
{
attempt[zz]=0;
}
switchModule();
setup2();
loop2();
}
else
{
Serial.println("PIN erroneo");
digitalWrite(12, HIGH); // activa un contacto
delay(1000);
digitalWrite(12, LOW);
for (int zz=0; zz<=4; zz++) // borrar el último código introducido
{
attempt[zz]=0;
}
setup();
}
}
void readKeypad()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
switch(key)
{
case '*':
z=0;
digitalWrite(12, LOW);
digitalWrite(11, LOW);
setup();
break;
case '#':
delay(50);
Serial.println(" ");
checkPIN();
break;
default:
attempt[z]=key;
z++;
attempt[z] = '\0'; // Add this to keep attempt NULL terminated (after making attempt larger)
}
Serial.print("*");
leds();
}
}
void loop()
{
readKeypad();
}
void switchModule(){
digitalWrite(onModulePin,HIGH); //Para activar el módulo 3G, debemos enviarle un pulso de 2sg por el pin número 2 (lo mismo para apagar)
Serial.println("Activando modulo 3G...");
delay(2000);
digitalWrite(onModulePin,LOW);
Serial.println("Modulo 3G activado...");
}
void setup2(){
Serial.begin(115200); //Configuramos puerto UART
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
for (int i=0;i< 5;i++){
delay(5000);
}
Serial.println("AT+CMGF=1"); //Seleccionamos el formato del sms (0=PDU 1=texto)
delay(100);
}
void loop2(){
while (count < timesToSend){
delay(1500);
Serial.print("AT+CMGS=\""); // send the SMS number
Serial.print(phone_number);
Serial.println("\"");
delay(1500);
Serial.print("Numero de serie: ");
Serial.println (serialnumber);
delay(1500);
Serial.print("Usuario: ");
Serial.println (attempt);
delay(500);
Serial.write(0x1A); //sends ++
Serial.write(0x0D);
Serial.write(0x0A);
delay(5000);
count++;
}
}
Thanks