este programa recibe ordenes codificadas en mensajes de texto y envia mensajes cuando pulsan un boton use Alarma1 y Alarma2 de prueba...regresa por pulsador Alarma1. captura el numero de telefono de quien manda la orden

Dependencies:   DebouncedIn mbed

Fork of CLASEDELGSM by Gustavo Ramirez

Este programa se probo y valido verificando que no se bloquea salvo se quede sin credito la SIMCARD se puede adaptar a cualquier aplicación de telemetría GSM o GPRS, ya que las funciones de librería lo permiten. Se adapta fácil a un rastreador satelital o monitoreo de variables si se usan los programas PDU1 y PDU2 para pasar entre octetos y septetos y viceversa.

baje el programa de abajo para determinar cadenas completas PDU en modo Hex y determine sus propias claves use el menú mandos del teléfono/enviar mensajes. Este programa monitorea completamente la actividad del modem facilitandonos la apropiación de la dinámica de codificación de mensajes PDU

/media/uploads/tony63/movilon.rar

/media/uploads/tony63/movilon1.png

puede bajar también TERMITE

http://www.compuphase.com/software_termite.htm

ejecutarlo con privilegios de administrador

baje este documento donde explico bastante como se codifica en PDU y multiples ejemplos y experimentos con el modem GSM/GPRS

/media/uploads/tony63/practicassms.rar

Committer:
tony63
Date:
Sun May 08 08:56:40 2016 +0000
Revision:
3:0b889f7a8eba
Parent:
2:0377af333c98
Child:
4:dbb0384120e0
Sistema de alarma contra robo que envia mensaje SMS a tel?fono celular y acepta ordenes de accionamiento decodificando los mensajes. Usa modo PDU que es mas complejo que el modo texto. En esta ocasi?n se usaron cadenas de mensajes en octetos fijas.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 3:0b889f7a8eba 1 /*************************Alarma Contra Robo*********************************************************
tony63 3:0b889f7a8eba 2 Como modem usa un celular SIEMENS a56i
tony63 3:0b889f7a8eba 3 Envia el mensaje intruso y otras cosas (mire el codigo de abajo)
tony63 3:0b889f7a8eba 4 Como modem GSM usa un celular SIEMENS A56i
tony63 3:0b889f7a8eba 5 El conector se distingue asi:
tony63 3:0b889f7a8eba 6 Cable verde es RX conectelo a PTE0 cable blanco es TX conectelo a PTE1
tony63 3:0b889f7a8eba 7 La alarma se dispara segun la señal digital de entrada de un sensor PIR que se le filtra el ruido por medio de
tony63 3:0b889f7a8eba 8 una validacion por retardo
tony63 3:0b889f7a8eba 9 La alarma puede hacer accionamientos como:
tony63 3:0b889f7a8eba 10 Accionamiento Permanente de una sirena
tony63 3:0b889f7a8eba 11 Accionaminto temporizado de una sirena
tony63 3:0b889f7a8eba 12 Accionamiento de un Mensaje de voz reperido y temporizado con un modulo de voz parallax
tony63 3:0b889f7a8eba 13 puede marcar un telefono fijo y uno de celular e inyectar audio, como voz robotizada a la linea de audio
tony63 3:0b889f7a8eba 14 usando un modulo GSM/GPRS SIM900 para arduino con entradas y salidas de audio
tony63 3:0b889f7a8eba 15 puede leer coordenadas de gps y enviarlas con el link de googlemaps.
tony63 0:edc50cf04b46 16 // OJO CON ESTO
tony63 0:edc50cf04b46 17 // conector del siemens cable verde es RX conectelo a PTE0 cable blanco es TX conectelo a PTE1
tony63 3:0b889f7a8eba 18
tony63 3:0b889f7a8eba 19 ESTA ALARMA SE PUEDE PROBAR DE LA SIGUIENTE FORMA
tony63 3:0b889f7a8eba 20 LOS TELEFONOS ESTAN PREGRAVADOS O CON UN CAMBIO SIMPLE EN EL PROGRAMA EL SISTEMA PUEDE CONTESTAR
tony63 3:0b889f7a8eba 21 CON EL TELEFONO QUE LO LLAMO
tony63 3:0b889f7a8eba 22 EN EL CASO DE RASTREADORES
tony63 3:0b889f7a8eba 23 HAY UN SUICHE QUE SE LLAMA PIR UBICADO EN PTA13..SI SE PULSA POR UN INSTANTE DE TIEMPO
tony63 3:0b889f7a8eba 24 EL LED VERDE DESTELLA INDICANDO QUE SE ENVIO EL MENSAJE AL NUMERO CODIFICADO EN LA CADENA SEGUN LAS TRAMAS PDU
tony63 3:0b889f7a8eba 25 ENVIA EL MENSAJE "HAY INTRUSOS EN LA FINCA...."
tony63 3:0b889f7a8eba 26
tony63 3:0b889f7a8eba 27 EN EL CASO DE ENVIAR ORDENES SE DISEÑARON DOS
tony63 3:0b889f7a8eba 28 SI SE ENVIA UN MENSAJE CON Alarma1 prende el led azul 5 segundos y retorna a verde
tony63 3:0b889f7a8eba 29 SI se envia el mensaje con Alarma2 prende el led rojo 5 segundos y retorna a verde
tony63 3:0b889f7a8eba 30 si el telefono falla da indicacion con rojo
tony63 3:0b889f7a8eba 31 el sistema reintenta de forma infinita la configuracion hasta que lo logra
tony63 3:0b889f7a8eba 32 *****se verifico que no se de bloqueo y asi resulto bajo intensas pruebas********
tony63 3:0b889f7a8eba 33 este sistema detecta el mensaje, el tamaño del mensaje y el numero telefonico de quien llama pero etos parametros no se estan usando
tony63 3:0b889f7a8eba 34 se podrian usar en programas mas complejos como rastreadores satelitales o sistemas de monitoreo de variablees fisicas
tony63 3:0b889f7a8eba 35 que se consultan por medio de ordenes previas segun algun Mensaje corto.
tony63 3:0b889f7a8eba 36
tony63 3:0b889f7a8eba 37 */
tony63 0:edc50cf04b46 38 #include "mbed.h"
tony63 0:edc50cf04b46 39 #include "DebouncedIn.h"
tony63 0:edc50cf04b46 40 #include "stdio.h"
tony63 0:edc50cf04b46 41 #include "string.h"
tony63 0:edc50cf04b46 42 Timer t;
tony63 0:edc50cf04b46 43 DigitalOut LedVerde(LED2);
tony63 0:edc50cf04b46 44 DigitalOut LedRojo(LED1);
tony63 0:edc50cf04b46 45 DigitalOut LedAzul(LED3);
tony63 3:0b889f7a8eba 46 DebouncedIn PIR(PTA13); //señal que inicia el envio del mensaje
tony63 0:edc50cf04b46 47 DebouncedIn button1(PTC12); //señal que inicia el envio del mensaje
tony63 0:edc50cf04b46 48 Serial GSM(PTE0,PTE1); //Configura puerto UART de la FRDMKL25Z
tony63 0:edc50cf04b46 49 Serial pc(USBTX,USBRX);//Configura puerto USB a la consola serial del PC conectado.
tony63 0:edc50cf04b46 50 void Rx_interrupt();
tony63 0:edc50cf04b46 51 int position=0;
tony63 2:0377af333c98 52 int intentos=0;
tony63 0:edc50cf04b46 53 int lenpack=6;
tony63 2:0377af333c98 54 int ret=1;
tony63 0:edc50cf04b46 55 int longi=0;
tony63 1:6b506dde0a6e 56 char tel[11];
tony63 0:edc50cf04b46 57 char DE[50];
tony63 1:6b506dde0a6e 58 char buffer[100];
tony63 2:0377af333c98 59 char buffermsg[100];
tony63 2:0377af333c98 60 char buffer1[100];
tony63 1:6b506dde0a6e 61 char datos[100];
tony63 2:0377af333c98 62 char NUMBER[13];
tony63 2:0377af333c98 63 char resp[6];
tony63 2:0377af333c98 64 char CMT[]="+CMTI";
tony63 2:0377af333c98 65 char tam[2];
tony63 0:edc50cf04b46 66 int index;
tony63 0:edc50cf04b46 67 int count;
tony63 0:edc50cf04b46 68 int i = 0;
tony63 1:6b506dde0a6e 69 int j = 0;
tony63 0:edc50cf04b46 70 int c=0;
tony63 0:edc50cf04b46 71 unsigned char CtrlZ = 0x1A; // comodin de emision controlZ
tony63 0:edc50cf04b46 72 bool Flag = false; // bandera
tony63 0:edc50cf04b46 73 char r[]=""; //Cadena de recepcion de la trama PDU si se usa!!
tony63 0:edc50cf04b46 74 char msg[256];
tony63 0:edc50cf04b46 75 char char1;
tony63 0:edc50cf04b46 76 //Flush serial para el buffer
tony63 0:edc50cf04b46 77 void FlushGSM(void) {
tony63 0:edc50cf04b46 78 char1 = 0;
tony63 0:edc50cf04b46 79 while (GSM.readable()){
tony63 0:edc50cf04b46 80 char1 = GSM.getc();}
tony63 0:edc50cf04b46 81 return;}
tony63 0:edc50cf04b46 82
tony63 0:edc50cf04b46 83 void callback() {
tony63 0:edc50cf04b46 84 // Note: you need to actually read from the serial to clear the RX interrupt
tony63 0:edc50cf04b46 85 pc.printf("%c\n", GSM.getc());
tony63 0:edc50cf04b46 86
tony63 0:edc50cf04b46 87 }
tony63 2:0377af333c98 88 //****************************************************************************************************************
tony63 2:0377af333c98 89 //esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de
tony63 2:0377af333c98 90 //$, count es lo que va a leer.Lo leido lo mete en buffer que es una cadena previamente definida
tony63 2:0377af333c98 91 //incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1
tony63 2:0377af333c98 92 //****************************************************************************************************************
tony63 0:edc50cf04b46 93 int readBuffer(char *buffer,int count)
tony63 0:edc50cf04b46 94 {
tony63 0:edc50cf04b46 95 int i=0;
tony63 0:edc50cf04b46 96 t.start(); // start timer
tony63 0:edc50cf04b46 97 while(1) {
tony63 0:edc50cf04b46 98 while (GSM.readable()) {
tony63 0:edc50cf04b46 99 char c = GSM.getc();
tony63 0:edc50cf04b46 100 if (c == '\r' || c == '\n') c = '$';
tony63 0:edc50cf04b46 101 buffer[i++] = c;
tony63 0:edc50cf04b46 102 if(i > count)break;
tony63 0:edc50cf04b46 103 }
tony63 0:edc50cf04b46 104 if(i > count)break;
tony63 0:edc50cf04b46 105 if(t.read() > 3) {
tony63 0:edc50cf04b46 106 t.stop();
tony63 0:edc50cf04b46 107 t.reset();
tony63 0:edc50cf04b46 108 break;
tony63 0:edc50cf04b46 109 }
tony63 0:edc50cf04b46 110 }
tony63 0:edc50cf04b46 111 wait(0.5);
tony63 0:edc50cf04b46 112 while(GSM.readable()) { // display the other thing..
tony63 0:edc50cf04b46 113 char c = GSM.getc();
tony63 0:edc50cf04b46 114 }
tony63 0:edc50cf04b46 115 return 0;
tony63 0:edc50cf04b46 116 }
tony63 2:0377af333c98 117 //********************************************************************************
tony63 0:edc50cf04b46 118 /* esta funcion de abajo limpia o borra todo un "buffer" de tamaño "count"
tony63 2:0377af333c98 119 lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena
tony63 0:edc50cf04b46 120 no retorna nada
tony63 0:edc50cf04b46 121 */
tony63 0:edc50cf04b46 122 //***************************************************************************************
tony63 0:edc50cf04b46 123 void cleanBuffer(char *buffer, int count)
tony63 0:edc50cf04b46 124 {
tony63 0:edc50cf04b46 125 for(int i=0; i < count; i++) {
tony63 0:edc50cf04b46 126 buffer[i] = '\0';
tony63 0:edc50cf04b46 127 }
tony63 0:edc50cf04b46 128 }
tony63 0:edc50cf04b46 129 /* esta funcion de abajo envia un comando parametrizado como cadena
tony63 2:0377af333c98 130 puede ser un comando tipo AT
tony63 0:edc50cf04b46 131 */
tony63 0:edc50cf04b46 132 //***************************************************************************************
tony63 0:edc50cf04b46 133 void sendCmd(char *cmd)
tony63 0:edc50cf04b46 134 {
tony63 0:edc50cf04b46 135 GSM.puts(cmd);
tony63 0:edc50cf04b46 136 }
tony63 2:0377af333c98 137 //****************************************************************************************
tony63 0:edc50cf04b46 138 /* esta funcion de abajo espera la respuesta de un comando que debe ser identica a la cadena "resp" y un tiempo timeout"
tony63 0:edc50cf04b46 139 si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 140 si algo sale mal ( no se parece o se demora mucho )retorna -1 que debera validarse con alguna expresion logica
tony63 0:edc50cf04b46 141 */
tony63 0:edc50cf04b46 142 //***************************************************************************************
tony63 0:edc50cf04b46 143 int waitForResp(char *resp, int timeout)
tony63 0:edc50cf04b46 144 {
tony63 0:edc50cf04b46 145 int len = strlen(resp);
tony63 0:edc50cf04b46 146 int sum=0;
tony63 0:edc50cf04b46 147 t.start();
tony63 0:edc50cf04b46 148
tony63 0:edc50cf04b46 149 while(1) {
tony63 0:edc50cf04b46 150 if(GSM.readable()) {
tony63 0:edc50cf04b46 151 char c = GSM.getc();
tony63 0:edc50cf04b46 152 sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c
tony63 0:edc50cf04b46 153 if(sum == len)break; //ya acabo se sale
tony63 0:edc50cf04b46 154 }
tony63 0:edc50cf04b46 155 if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo
tony63 0:edc50cf04b46 156 t.stop();
tony63 0:edc50cf04b46 157 t.reset();
tony63 0:edc50cf04b46 158 return -1;
tony63 0:edc50cf04b46 159 }
tony63 0:edc50cf04b46 160 }
tony63 0:edc50cf04b46 161 t.stop(); // stop timer antes de retornar
tony63 0:edc50cf04b46 162 t.reset(); // clear timer
tony63 0:edc50cf04b46 163 while(GSM.readable()) { // display the other thing..
tony63 0:edc50cf04b46 164 char c = GSM.getc();
tony63 0:edc50cf04b46 165 }
tony63 0:edc50cf04b46 166
tony63 0:edc50cf04b46 167 return 0;
tony63 0:edc50cf04b46 168 }
tony63 0:edc50cf04b46 169 /* esta funcion de abajo es muy completa e util se encarga de enviar el comando y esperar la respuesta
tony63 0:edc50cf04b46 170 si todo sale bien retorna un cero(herencia de las funciones contenedoras) que en la programacion hay que validar
tony63 0:edc50cf04b46 171 con alguna expresion logica
tony63 0:edc50cf04b46 172 */
tony63 0:edc50cf04b46 173 //***************************************************************************************
tony63 0:edc50cf04b46 174 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout)
tony63 0:edc50cf04b46 175 {
tony63 0:edc50cf04b46 176 sendCmd(cmd);
tony63 0:edc50cf04b46 177 return waitForResp(resp,timeout);
tony63 0:edc50cf04b46 178 }
tony63 0:edc50cf04b46 179 /* esta funcion de abajo chequea que el modem este vivo envia AT y le contesta con OK y espera 2 segundos
tony63 0:edc50cf04b46 180 */
tony63 0:edc50cf04b46 181 //***************************************************************************************
tony63 0:edc50cf04b46 182 int powerCheck(void)// este comando se manda para verificar si el modem esta vivo o conectado
tony63 0:edc50cf04b46 183 {
tony63 0:edc50cf04b46 184 return sendCmdAndWaitForResp("AT\r\n", "OK", 2);
tony63 0:edc50cf04b46 185 }
tony63 0:edc50cf04b46 186 /* esta funcion de abajo chequea el estado de la sim card
tony63 0:edc50cf04b46 187 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 188 con alguna expresion logica
tony63 0:edc50cf04b46 189 */
tony63 0:edc50cf04b46 190 //***************************************************************************************
tony63 0:edc50cf04b46 191 int checkSIMStatus(void)
tony63 0:edc50cf04b46 192 {
tony63 0:edc50cf04b46 193 char gprsBuffer[30];
tony63 0:edc50cf04b46 194 int count = 0;
tony63 0:edc50cf04b46 195 cleanBuffer(gprsBuffer,30);
tony63 0:edc50cf04b46 196 while(count < 3) {
tony63 0:edc50cf04b46 197 sendCmd("AT+CPIN?\r\n");
tony63 0:edc50cf04b46 198 readBuffer(gprsBuffer,30);
tony63 0:edc50cf04b46 199 if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
tony63 0:edc50cf04b46 200 break;
tony63 0:edc50cf04b46 201 }
tony63 0:edc50cf04b46 202 count++;
tony63 0:edc50cf04b46 203 wait(1);
tony63 0:edc50cf04b46 204 }
tony63 0:edc50cf04b46 205
tony63 0:edc50cf04b46 206 if(count == 3) {
tony63 0:edc50cf04b46 207 return -1;
tony63 0:edc50cf04b46 208 }
tony63 0:edc50cf04b46 209 return 0;
tony63 0:edc50cf04b46 210 }
tony63 0:edc50cf04b46 211 /* esta funcion de abajo chequea la calidad de la señal
tony63 2:0377af333c98 212 y si todo sale bien retorna con el valor de señal util o un -1 si no es aceptable, en la programacion hay que validar
tony63 0:edc50cf04b46 213 con alguna expresion logica
tony63 0:edc50cf04b46 214 */
tony63 0:edc50cf04b46 215 //***************************************************************************************
tony63 0:edc50cf04b46 216 int checkSignalStrength(void)
tony63 0:edc50cf04b46 217 {
tony63 0:edc50cf04b46 218 char gprsBuffer[100];
tony63 0:edc50cf04b46 219 int index,count = 0;
tony63 0:edc50cf04b46 220 cleanBuffer(gprsBuffer,100);
tony63 0:edc50cf04b46 221 while(count < 3) {
tony63 0:edc50cf04b46 222 sendCmd("AT+CSQ\r\n");
tony63 0:edc50cf04b46 223 readBuffer(gprsBuffer,25);
tony63 0:edc50cf04b46 224 if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
tony63 0:edc50cf04b46 225 break;
tony63 0:edc50cf04b46 226 }
tony63 0:edc50cf04b46 227 count++;
tony63 0:edc50cf04b46 228 wait(1);
tony63 0:edc50cf04b46 229 }
tony63 0:edc50cf04b46 230 if(count == 3) {
tony63 0:edc50cf04b46 231 return -1;
tony63 0:edc50cf04b46 232 }
tony63 0:edc50cf04b46 233 return index;
tony63 0:edc50cf04b46 234 }
tony63 0:edc50cf04b46 235
tony63 0:edc50cf04b46 236 /* esta funcion de abajo inicaliza el modem se compone de un grupo de subfunciones ya definidas previamente
tony63 0:edc50cf04b46 237 primero chequea que este vivo
tony63 0:edc50cf04b46 238 segundo chequea el estado de la simcard
tony63 0:edc50cf04b46 239 tercero chequea la intencidad de señal celular
tony63 0:edc50cf04b46 240 cuarto aplica la configuracion
tony63 0:edc50cf04b46 241 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 242 con alguna expresion logica
tony63 0:edc50cf04b46 243 */
tony63 0:edc50cf04b46 244 //***************************************************************************************
tony63 0:edc50cf04b46 245 int init()
tony63 0:edc50cf04b46 246 {
tony63 2:0377af333c98 247 if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){
tony63 2:0377af333c98 248 return -1;
tony63 2:0377af333c98 249 }
tony63 2:0377af333c98 250 if (0 != sendCmdAndWaitForResp("AT+CNMI=1,1\r\n", "OK", 3)){
tony63 2:0377af333c98 251 return -1;
tony63 2:0377af333c98 252 }
tony63 2:0377af333c98 253 if (0 != sendCmdAndWaitForResp("AT+CMGF=0\r\n", "OK", 3)){
tony63 0:edc50cf04b46 254 return -1;
tony63 2:0377af333c98 255 }
tony63 2:0377af333c98 256 if (0 != sendCmdAndWaitForResp("AT+CBST=0,0,1\r\n", "OK", 3)){
tony63 0:edc50cf04b46 257 return -1;
tony63 2:0377af333c98 258 }
tony63 2:0377af333c98 259 LedVerde=0;
tony63 2:0377af333c98 260 return 0;
tony63 2:0377af333c98 261 }
tony63 2:0377af333c98 262
tony63 0:edc50cf04b46 263 /* esta funcion de abajo intenta leer un mensaje de texto en formato PDU o HEX
tony63 0:edc50cf04b46 264 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 265 con alguna expresion logica
tony63 0:edc50cf04b46 266 */
tony63 0:edc50cf04b46 267 //***************************************************************************************
tony63 0:edc50cf04b46 268 int readSMSpdu(char *message, int index)
tony63 0:edc50cf04b46 269 {
tony63 0:edc50cf04b46 270 int i = 0;
tony63 0:edc50cf04b46 271 char gprsBuffer[100];
tony63 0:edc50cf04b46 272 char *p,*s;
tony63 0:edc50cf04b46 273 GSM.printf("AT+CMGR=%d\r\n",index);
tony63 0:edc50cf04b46 274 cleanBuffer(gprsBuffer,100);
tony63 0:edc50cf04b46 275 readBuffer(gprsBuffer,100);
tony63 0:edc50cf04b46 276 if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) {
tony63 0:edc50cf04b46 277 return -1;
tony63 0:edc50cf04b46 278 }
tony63 0:edc50cf04b46 279 if(NULL != ( s = strstr(gprsBuffer,"+32"))) {
tony63 0:edc50cf04b46 280 p = s + 6;
tony63 0:edc50cf04b46 281 while((*p != '$')&&(i < 5)) {
tony63 0:edc50cf04b46 282 message[i++] = *(p++);
tony63 0:edc50cf04b46 283 }
tony63 0:edc50cf04b46 284 message[i] = '\0';
tony63 0:edc50cf04b46 285 }
tony63 0:edc50cf04b46 286 return 0;
tony63 0:edc50cf04b46 287 }
tony63 0:edc50cf04b46 288 /* esta funcion de abajo borra mensajes SMS del modem
tony63 0:edc50cf04b46 289 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 290 con alguna expresion logica
tony63 0:edc50cf04b46 291 */
tony63 0:edc50cf04b46 292 //***************************************************************************************
tony63 0:edc50cf04b46 293 int deleteSMS(int index)
tony63 0:edc50cf04b46 294 {
tony63 0:edc50cf04b46 295 char cmd[32];
tony63 0:edc50cf04b46 296 snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
tony63 0:edc50cf04b46 297 sendCmd(cmd);
tony63 0:edc50cf04b46 298 return 0;
tony63 0:edc50cf04b46 299 }
tony63 2:0377af333c98 300 //************************************************************************************
tony63 3:0b889f7a8eba 301 //*****************SE INICIA EL PROGRAMA PRINCIPAL*******************************************************
tony63 3:0b889f7a8eba 302 int main() {
tony63 3:0b889f7a8eba 303 //configuramos los puertos seriales
tony63 3:0b889f7a8eba 304 GSM.baud(9600);//configura los baudios de la FRDMKL25Z en 9600
tony63 3:0b889f7a8eba 305 GSM.format(8,Serial::None,1); //configura el formato de los datos de la UART
tony63 3:0b889f7a8eba 306 LedVerde=1; //APAGO LOS LEDS
tony63 3:0b889f7a8eba 307 LedRojo=1;
tony63 3:0b889f7a8eba 308 LedAzul=1;
tony63 3:0b889f7a8eba 309 LedRojo=0; // PRENDO EL LED ROJO
tony63 3:0b889f7a8eba 310 //quito el eco del modem
tony63 3:0b889f7a8eba 311
tony63 3:0b889f7a8eba 312 //****************CONFIGURAMOS EL MODEM GSM (TELEFONO CELULAR SIEMENS A56i)
tony63 3:0b889f7a8eba 313 inicio1:
tony63 3:0b889f7a8eba 314 ret = init();
tony63 3:0b889f7a8eba 315 if(ret==0){
tony63 3:0b889f7a8eba 316 LedRojo=1;
tony63 3:0b889f7a8eba 317 LedVerde=0;
tony63 3:0b889f7a8eba 318 }
tony63 3:0b889f7a8eba 319 else{
tony63 3:0b889f7a8eba 320 wait(5);
tony63 3:0b889f7a8eba 321 goto inicio1;
tony63 3:0b889f7a8eba 322 }
tony63 0:edc50cf04b46 323
tony63 2:0377af333c98 324 //RUTINA PRINCIPAL*******************************************************************************************
tony63 3:0b889f7a8eba 325
tony63 2:0377af333c98 326 //*********************************************************************************************************************
tony63 2:0377af333c98 327 while(1){
tony63 3:0b889f7a8eba 328 //***************ALARMA POR ACTIVACION PIR***************************************************
tony63 3:0b889f7a8eba 329 if (PIR.falling())
tony63 2:0377af333c98 330 {
tony63 3:0b889f7a8eba 331 wait(1);
tony63 3:0b889f7a8eba 332 if (!PIR)
tony63 2:0377af333c98 333 {
tony63 3:0b889f7a8eba 334
tony63 3:0b889f7a8eba 335 //**********se envia la palabra "Hay Intrusos En La Finca de Rionegro"
tony63 3:0b889f7a8eba 336 //******Gustavo
tony63 3:0b889f7a8eba 337 GSM.printf("AT+CMGS=50\n\r");
tony63 3:0b889f7a8eba 338 wait_ms(200);
tony63 3:0b889f7a8eba 339 GSM.printf("0011000A9113223717370000AA2A21970B19CE83926EBABC3E7FCF41453788190699D3EE7118442E83A4E9B7BB7C96BF5DAE10");
tony63 3:0b889f7a8eba 340 wait_ms(200);
tony63 3:0b889f7a8eba 341 GSM.putc((char)0x1A);
tony63 3:0b889f7a8eba 342 for(i=0;i<6;i++){
tony63 2:0377af333c98 343 LedVerde=1;
tony63 3:0b889f7a8eba 344 wait(0.2);
tony63 2:0377af333c98 345 LedVerde=0;
tony63 3:0b889f7a8eba 346 wait(0.2);
tony63 3:0b889f7a8eba 347 }
tony63 3:0b889f7a8eba 348 }
tony63 3:0b889f7a8eba 349 }
tony63 3:0b889f7a8eba 350 // **************apartir de aca se pueden escribir mas alarmas o mensajes de salida activar leds salidas o generar respuestas
tony63 3:0b889f7a8eba 351
tony63 3:0b889f7a8eba 352
tony63 2:0377af333c98 353
tony63 2:0377af333c98 354
tony63 3:0b889f7a8eba 355 //***************inicia la recepcion de un mensaje de texto**********************************
tony63 3:0b889f7a8eba 356 //la comparacion de estos mensajes constituye generar accionamiento abrir o cerrar circuitos o contestar mensajes
tony63 3:0b889f7a8eba 357
tony63 2:0377af333c98 358 if (GSM.readable()) {
tony63 2:0377af333c98 359 readBuffer(buffer,100);
tony63 2:0377af333c98 360 pc.printf("%s\r\n",buffer);
tony63 2:0377af333c98 361 for(i=0;i<5;i++)
tony63 2:0377af333c98 362 {
tony63 2:0377af333c98 363 resp[i]=buffer[i];
tony63 2:0377af333c98 364 }
tony63 2:0377af333c98 365
tony63 2:0377af333c98 366 pc.printf("%s\r\n",resp);
tony63 2:0377af333c98 367 if(strcmp("$$+CM",resp) == 0){ //COMPARA resp con "+CMTI"
tony63 2:0377af333c98 368 pc.printf("llego MSG\r\n");
tony63 2:0377af333c98 369 cleanBuffer(buffer,10);
tony63 2:0377af333c98 370 wait(0.5);
tony63 2:0377af333c98 371 GSM.printf("AT+CMGL=0\r\n");//envio comando para leer mensaje
tony63 2:0377af333c98 372 pc.printf("AT+CMGL=0\r\n");
tony63 2:0377af333c98 373 //if (GSM.readable()) {
tony63 2:0377af333c98 374 GSM.printf("AT+CMGD=0\r\n");
tony63 2:0377af333c98 375 readBuffer(buffer,100);
tony63 2:0377af333c98 376 pc.printf("%s\r\n",buffer);
tony63 2:0377af333c98 377 wait(5);
tony63 2:0377af333c98 378 //leer telefono
tony63 2:0377af333c98 379 for(i=0;i<10;i++){
tony63 2:0377af333c98 380 tel[i]=buffer[i+40];
tony63 2:0377af333c98 381 }
tony63 2:0377af333c98 382 pc.printf("%s-\r\n",tel);
tony63 2:0377af333c98 383 //leer tamaño
tony63 2:0377af333c98 384 for(i=0;i<2;i++){
tony63 2:0377af333c98 385 tam[i]=buffer[i+68];
tony63 2:0377af333c98 386 }
tony63 2:0377af333c98 387 pc.printf("%s-\r\n",tam);
tony63 2:0377af333c98 388 //leer mensaje
tony63 2:0377af333c98 389 for(i=0;i<14;i++){
tony63 3:0b889f7a8eba 390 msg[i]=buffer[i+70]; //OJO SE LEE EL MENSAJE APARTIR DE LA POSICION 70
tony63 2:0377af333c98 391 }
tony63 2:0377af333c98 392 pc.printf("%s-\r\n",msg);
tony63 2:0377af333c98 393 //decodificar mensaje
tony63 2:0377af333c98 394 //comparar mensaje
tony63 3:0b889f7a8eba 395 deleteSMS(1);//se borra el bufer por medio de una funcion
tony63 2:0377af333c98 396 if(strcmp("417658DE0EC700",msg) == 0){ //COMPARA resp con "417658DE0EC700" que es Alarma1
tony63 2:0377af333c98 397 LedVerde=1;
tony63 2:0377af333c98 398 LedAzul=0;
tony63 2:0377af333c98 399 wait(15);
tony63 2:0377af333c98 400 LedAzul=1;
tony63 2:0377af333c98 401 LedVerde=0;
tony63 2:0377af333c98 402 }
tony63 2:0377af333c98 403 if(strcmp("417658DE0ECB00",msg) == 0){ //COMPARA resp con "417658DE0ECB00" que es Alarma2
tony63 2:0377af333c98 404 LedVerde=1;
tony63 2:0377af333c98 405 LedRojo=0;
tony63 2:0377af333c98 406 wait(15);
tony63 2:0377af333c98 407 LedRojo=1;
tony63 2:0377af333c98 408 LedVerde=0;
tony63 2:0377af333c98 409 }
tony63 2:0377af333c98 410
tony63 2:0377af333c98 411
tony63 3:0b889f7a8eba 412 //ejecurar orden si esta es mas que prender leds
tony63 2:0377af333c98 413 cleanBuffer(buffer,100);
tony63 2:0377af333c98 414
tony63 2:0377af333c98 415 }
tony63 1:6b506dde0a6e 416 }
tony63 2:0377af333c98 417
tony63 2:0377af333c98 418
tony63 2:0377af333c98 419 }
tony63 2:0377af333c98 420
tony63 1:6b506dde0a6e 421
tony63 2:0377af333c98 422 //**********************************************************************************************************************
tony63 2:0377af333c98 423 loop1: LedRojo=0;
tony63 2:0377af333c98 424 wait(0.3);
tony63 2:0377af333c98 425 LedRojo=1;
tony63 2:0377af333c98 426 wait(0.3);
tony63 2:0377af333c98 427 goto loop1;
tony63 2:0377af333c98 428
tony63 3:0b889f7a8eba 429 }
tony63 3:0b889f7a8eba 430
tony63 3:0b889f7a8eba 431 /*
tony63 3:0b889f7a8eba 432 si se manda para enviar mensaje
tony63 3:0b889f7a8eba 433 AT+CMGS=20
tony63 3:0b889f7a8eba 434 //un salto de linea y el simbolo mayor
tony63 3:0b889f7a8eba 435 >
tony63 3:0b889f7a8eba 436
tony63 3:0b889f7a8eba 437
tony63 3:0b889f7a8eba 438
tony63 3:0b889f7a8eba 439
tony63 3:0b889f7a8eba 440 */