RASTREADOR SATELITAÑ GSM

Dependencies:   mbed GPS_G

RASTREADOR SATELITAL USANDO MODULO BLUEPILL CHINO STM32F103 Y CELULAR SIEMENS A56I COMO MODEM GSM. SE PUEDE EMULAR GPS CON UN GPS VIRTUAL DE PROTEUS.

/media/uploads/tony63/img7.jpg

Committer:
tony63
Date:
Fri Apr 12 05:51:33 2019 +0000
Revision:
0:f7598e776b3c
RSTREADOR SATELITAL USANDO MUDULO BLUEPILL STM32F103 Y CELULAR SIEMENS A56I ENVIA COORDENADAS EN UNA TRAMA DE GOOGLE MAPS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 0:f7598e776b3c 1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 2 // Programa para establecer la comunicación con un módem Siemens A56 y un modulo STM32F103 BLUEPILL CHINO.
tony63 0:f7598e776b3c 3 // opera como rastreador satelital para Geolocalizacion.
tony63 0:f7598e776b3c 4 // Por la UART (1) se conecta el MODEM y por la uart (2) el GPS (se lee en modo NEMEA)
tony63 0:f7598e776b3c 5 // Este sistema genera una cadena de geolocalizacion para GoogleMaps con las coordenadas locales
tony63 0:f7598e776b3c 6 // Si previamente se envia el mensaje (Coordenadas o coordenadas)
tony63 0:f7598e776b3c 7 // El sistema ademas recibe ordenes de tipo mensaje GSM PDU para accionar cargas
tony63 0:f7598e776b3c 8 // 1----Una supuesta valvula de combustible (On y Off.....on y off......)
tony63 0:f7598e776b3c 9 // 2----Una cantonera para cerradura electrica (Pulso o pulso) (pulso de 7 segundos)
tony63 0:f7598e776b3c 10 // Este sistema responde con un mensaje si el mensaje fue recibido (Mensaje Recibido)
tony63 0:f7598e776b3c 11 //
tony63 0:f7598e776b3c 12 // Adicionalmente este sistema mide un valor analogico en respuesta al mensaje..(Voltaje o voltaje)
tony63 0:f7598e776b3c 13 // El sistema dispone de un jumper que permite operar el sistema con o sin GPS (jumper a tierra)
tony63 0:f7598e776b3c 14 // El sistema detecta si el modem GSM esta bien conectado configurado y respondiendo correctamente
tony63 0:f7598e776b3c 15 // El sistema detecta si el GPS emite cadenas NEMEA y señaliza con un led si es exitosa la conexion
tony63 0:f7598e776b3c 16 // Presenta borrado automatico de SMS entrantes para evitar perdida de sincronismo en la deteccion
tony63 0:f7598e776b3c 17 // de cadenas y prefijos.
tony63 0:f7598e776b3c 18 // Este codigo compila sin problemas para un modulo chino bluepill STM32F103
tony63 0:f7598e776b3c 19 // con las modificaciones adecuadas de puertos y leds
tony63 0:f7598e776b3c 20
tony63 0:f7598e776b3c 21 //+++++++++++++++++++++++++++++++ARCHIVOS INCLUIDOS*************************************************************************
tony63 0:f7598e776b3c 22 #include "mbed.h"
tony63 0:f7598e776b3c 23 #include "DebouncedIn.h"
tony63 0:f7598e776b3c 24 #include "stdio.h"
tony63 0:f7598e776b3c 25 #include "string.h"
tony63 0:f7598e776b3c 26 #include "GPS.h"
tony63 0:f7598e776b3c 27
tony63 0:f7598e776b3c 28 Timer t;
tony63 0:f7598e776b3c 29 //++++++++++++++++++++++++++++++++++++salidas y entradas digitales+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 30 DigitalOut LedVerde(PA_8);
tony63 0:f7598e776b3c 31 DigitalOut LedRojo(PB_15);
tony63 0:f7598e776b3c 32 DigitalOut LedAzul(PB_14);
tony63 0:f7598e776b3c 33 DigitalOut valvula(PB_13);//salida de la valvula
tony63 0:f7598e776b3c 34 DigitalOut puerta(PB_12);//salida de cerradura magnetica (en caso de usarlo en casa o desbloquear puertas de carro)
tony63 0:f7598e776b3c 35 DigitalIn sin_gps(PA_11);
tony63 0:f7598e776b3c 36
tony63 0:f7598e776b3c 37 // Entrada análoga
tony63 0:f7598e776b3c 38 AnalogIn v(PA_0);
tony63 0:f7598e776b3c 39 float medi;
tony63 0:f7598e776b3c 40
tony63 0:f7598e776b3c 41 // Declaración de los puertos de la FRDM, Módem GSM y GPS.
tony63 0:f7598e776b3c 42 Serial GSM(PB_6,PB_7); // Puertos del FRDM para el Módem.
tony63 0:f7598e776b3c 43 Serial pc(PB_10,PB_11);
tony63 0:f7598e776b3c 44 GPS gps(PA_9,PA_10); // Puerto del FDRM para el GPS.
tony63 0:f7598e776b3c 45
tony63 0:f7598e776b3c 46 // Declaración de variables
tony63 0:f7598e776b3c 47 // Cadenas de caracteres con las que se va a trabajar.
tony63 0:f7598e776b3c 48 char DE1[255];
tony63 0:f7598e776b3c 49 char DS1[255];
tony63 0:f7598e776b3c 50 char DE2[255];
tony63 0:f7598e776b3c 51 char DS2[255];
tony63 0:f7598e776b3c 52 char buffer[512];
tony63 0:f7598e776b3c 53 char resp[6];
tony63 0:f7598e776b3c 54 char tam[2];
tony63 0:f7598e776b3c 55 char mensaje[100];
tony63 0:f7598e776b3c 56
tony63 0:f7598e776b3c 57 //Variables enteras y caracteres
tony63 0:f7598e776b3c 58 int g=0;
tony63 0:f7598e776b3c 59 int count;
tony63 0:f7598e776b3c 60 int i, K, LENOUT1, LENIN1, LENOUT2, LENIN2, C;
tony63 0:f7598e776b3c 61 int c=0;
tony63 0:f7598e776b3c 62 char r[]="";
tony63 0:f7598e776b3c 63 char msg[256];
tony63 0:f7598e776b3c 64 char char1;
tony63 0:f7598e776b3c 65 int ind;
tony63 0:f7598e776b3c 66 float med;
tony63 0:f7598e776b3c 67 char outmed[16], outmedn[16];
tony63 0:f7598e776b3c 68 int ret = 1;
tony63 0:f7598e776b3c 69
tony63 0:f7598e776b3c 70 // Adquisición de números de teléfono, emisor - receptor
tony63 0:f7598e776b3c 71 char tel[15];
tony63 0:f7598e776b3c 72
tony63 0:f7598e776b3c 73 // El GPS entregará al celular coordenadas expresadas en latitud y longitud
tony63 0:f7598e776b3c 74 // según la ubicación que encuentre, por lo tanto se declaran estas variables.
tony63 0:f7598e776b3c 75 float lo,la;
tony63 0:f7598e776b3c 76 char clo[255], cla[255]; // Cadenas a capturar para latitud y longitud.
tony63 0:f7598e776b3c 77 char la_lo[255], volt[255];
tony63 0:f7598e776b3c 78
tony63 0:f7598e776b3c 79 // Cadena de google maps
tony63 0:f7598e776b3c 80 char http2[255];
tony63 0:f7598e776b3c 81 char http[] = "http://maps.google.com/maps?q=";
tony63 0:f7598e776b3c 82 char buf[100];
tony63 0:f7598e776b3c 83
tony63 0:f7598e776b3c 84 // Relleno de datos propio del protocolo de SMS.
tony63 0:f7598e776b3c 85 char relle1[] = "0011000A91";
tony63 0:f7598e776b3c 86 char relle2[] = "0000AA";
tony63 0:f7598e776b3c 87
tony63 0:f7598e776b3c 88 // Reverses a string 'str' of length 'len'
tony63 0:f7598e776b3c 89 // driver program to test above funtion.
tony63 0:f7598e776b3c 90 void reverse(char *str, int len)
tony63 0:f7598e776b3c 91 {
tony63 0:f7598e776b3c 92 int i=0, j=len-1, temp;
tony63 0:f7598e776b3c 93 while (i<j)
tony63 0:f7598e776b3c 94 {
tony63 0:f7598e776b3c 95 temp = str[i];
tony63 0:f7598e776b3c 96 str[i] = str[j];
tony63 0:f7598e776b3c 97 str[j] = temp;
tony63 0:f7598e776b3c 98 i++; j--;
tony63 0:f7598e776b3c 99 }
tony63 0:f7598e776b3c 100 }
tony63 0:f7598e776b3c 101
tony63 0:f7598e776b3c 102 // Converts a given integer x to string str[]. d is the number
tony63 0:f7598e776b3c 103 // of digits required in output. If d is more than the number
tony63 0:f7598e776b3c 104 // of digits in x, then 0s are added at the beginning.
tony63 0:f7598e776b3c 105 int intToStr(int x, char str[], int d)
tony63 0:f7598e776b3c 106 {
tony63 0:f7598e776b3c 107 int i = 0;
tony63 0:f7598e776b3c 108 while (x)
tony63 0:f7598e776b3c 109 {
tony63 0:f7598e776b3c 110 str[i++] = (x%10) + '0';
tony63 0:f7598e776b3c 111 x = x/10;
tony63 0:f7598e776b3c 112 }
tony63 0:f7598e776b3c 113
tony63 0:f7598e776b3c 114 // If number of digits required is more, then
tony63 0:f7598e776b3c 115 // add 0s at the beginning
tony63 0:f7598e776b3c 116 while (i < d)
tony63 0:f7598e776b3c 117 str[i++] = '0';
tony63 0:f7598e776b3c 118
tony63 0:f7598e776b3c 119 reverse(str, i);
tony63 0:f7598e776b3c 120 str[i] = '\0';
tony63 0:f7598e776b3c 121 return i;
tony63 0:f7598e776b3c 122 }
tony63 0:f7598e776b3c 123
tony63 0:f7598e776b3c 124 // Converts a floating point number to string.
tony63 0:f7598e776b3c 125 void ftoa(float n, char *res, int afterpoint)
tony63 0:f7598e776b3c 126 {
tony63 0:f7598e776b3c 127 // Extract integer part
tony63 0:f7598e776b3c 128 int ipart = (int)n;
tony63 0:f7598e776b3c 129
tony63 0:f7598e776b3c 130 // Extract floating part
tony63 0:f7598e776b3c 131 float fpart = n - (float)ipart;
tony63 0:f7598e776b3c 132
tony63 0:f7598e776b3c 133 // convert integer part to string
tony63 0:f7598e776b3c 134 int i = intToStr(ipart, res, 0);
tony63 0:f7598e776b3c 135
tony63 0:f7598e776b3c 136 // check for display option after point
tony63 0:f7598e776b3c 137 if (afterpoint != 0)
tony63 0:f7598e776b3c 138 {
tony63 0:f7598e776b3c 139 res[i] = '.'; // add dot
tony63 0:f7598e776b3c 140
tony63 0:f7598e776b3c 141 // Get the value of fraction part upto given no.
tony63 0:f7598e776b3c 142 // of points after dot. The third parameter is needed
tony63 0:f7598e776b3c 143 // to handle cases like 233.007
tony63 0:f7598e776b3c 144 float fp=10;
tony63 0:f7598e776b3c 145 fpart =fpart * pow(fp,afterpoint);
tony63 0:f7598e776b3c 146
tony63 0:f7598e776b3c 147 intToStr((int)fpart, res + i + 1, afterpoint);
tony63 0:f7598e776b3c 148 }
tony63 0:f7598e776b3c 149 }
tony63 0:f7598e776b3c 150 //++++++++++++++++++++++++++++++++++++libreria para vaciar el modem+++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 151 void FlushGSM(void) {
tony63 0:f7598e776b3c 152 char1 = 0;
tony63 0:f7598e776b3c 153 while (GSM.readable()){
tony63 0:f7598e776b3c 154 char1 = GSM.getc();
tony63 0:f7598e776b3c 155 }
tony63 0:f7598e776b3c 156 return;
tony63 0:f7598e776b3c 157 }
tony63 0:f7598e776b3c 158 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 159 void callback(){
tony63 0:f7598e776b3c 160 // Note: you need to actually read from the serial to clear the RX interrupt
tony63 0:f7598e776b3c 161 pc.printf("%c\n", GSM.getc());
tony63 0:f7598e776b3c 162 }
tony63 0:f7598e776b3c 163 //-----------------------------------------------------------------------------------------------------------------------------
tony63 0:f7598e776b3c 164 // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de
tony63 0:f7598e776b3c 165 // $, count es lo que va a leer. Lo leido lo mete en buffer que es una cadena previamente definida
tony63 0:f7598e776b3c 166 // incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1
tony63 0:f7598e776b3c 167 int readBuffer(char *buffer,int count){
tony63 0:f7598e776b3c 168 int i=0;
tony63 0:f7598e776b3c 169 t.start(); // start timer
tony63 0:f7598e776b3c 170 while(1) {
tony63 0:f7598e776b3c 171 while (GSM.readable()) {
tony63 0:f7598e776b3c 172 char c = GSM.getc();
tony63 0:f7598e776b3c 173 if (c == '\r' || c == '\n') c = '$';
tony63 0:f7598e776b3c 174 buffer[i++] = c;
tony63 0:f7598e776b3c 175 if(i > count)break;
tony63 0:f7598e776b3c 176 }
tony63 0:f7598e776b3c 177 if(i > count)break;
tony63 0:f7598e776b3c 178 if(t.read() > 3) {
tony63 0:f7598e776b3c 179 t.stop();
tony63 0:f7598e776b3c 180 t.reset();
tony63 0:f7598e776b3c 181 break;
tony63 0:f7598e776b3c 182 }
tony63 0:f7598e776b3c 183 }
tony63 0:f7598e776b3c 184 wait(0.5);
tony63 0:f7598e776b3c 185 while(GSM.readable()){ // display the other thing..
tony63 0:f7598e776b3c 186 char c = GSM.getc();
tony63 0:f7598e776b3c 187 }
tony63 0:f7598e776b3c 188 return 0;
tony63 0:f7598e776b3c 189 }
tony63 0:f7598e776b3c 190 //--------------------------------------------------------------------------------------------------------------
tony63 0:f7598e776b3c 191 // Esta función de abajo limpia o borra todo un "buffer" de tamaño "count",
tony63 0:f7598e776b3c 192 // lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena.
tony63 0:f7598e776b3c 193 // No retorna nada.
tony63 0:f7598e776b3c 194 void cleanBuffer(char *buffer, int count){
tony63 0:f7598e776b3c 195 for(int i=0; i < count; i++) {
tony63 0:f7598e776b3c 196 buffer[i] = '\0';
tony63 0:f7598e776b3c 197 }
tony63 0:f7598e776b3c 198 }
tony63 0:f7598e776b3c 199 //--------------------------------------------------------------------------------------------------------------
tony63 0:f7598e776b3c 200 // Esta función de abajo envia un comando parametrizado como cadena
tony63 0:f7598e776b3c 201 // puede ser un comando tipo AT.
tony63 0:f7598e776b3c 202 void sendCmd(char *cmd){
tony63 0:f7598e776b3c 203 GSM.puts(cmd);
tony63 0:f7598e776b3c 204 }
tony63 0:f7598e776b3c 205 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 206 // Esta función de abajo espera la respuesta de un comando que debe ser idéntica a la cadena "resp" y un tiempo "timeout",
tony63 0:f7598e776b3c 207 // si todo sale bien retorna un cero que en la programacion hay que validar,
tony63 0:f7598e776b3c 208 // si algo sale mal (no se parece o se demora mucho) retorna -1 que debera validarse con alguna expresion logica.
tony63 0:f7598e776b3c 209 int waitForResp(char *resp, int timeout){
tony63 0:f7598e776b3c 210 int len = strlen(resp);
tony63 0:f7598e776b3c 211 int sum=0;
tony63 0:f7598e776b3c 212 t.start();
tony63 0:f7598e776b3c 213
tony63 0:f7598e776b3c 214 while(1) {
tony63 0:f7598e776b3c 215 if(GSM.readable()) {
tony63 0:f7598e776b3c 216 char c = GSM.getc();
tony63 0:f7598e776b3c 217 sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c
tony63 0:f7598e776b3c 218 if(sum == len)break; //ya acabo se sale
tony63 0:f7598e776b3c 219 }
tony63 0:f7598e776b3c 220 if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo
tony63 0:f7598e776b3c 221 t.stop();
tony63 0:f7598e776b3c 222 t.reset();
tony63 0:f7598e776b3c 223 return -1;
tony63 0:f7598e776b3c 224 }
tony63 0:f7598e776b3c 225 }
tony63 0:f7598e776b3c 226 t.stop(); // stop timer antes de retornar
tony63 0:f7598e776b3c 227 t.reset(); // clear timer
tony63 0:f7598e776b3c 228 while(GSM.readable()) { // display the other thing..
tony63 0:f7598e776b3c 229 char c = GSM.getc();
tony63 0:f7598e776b3c 230 }
tony63 0:f7598e776b3c 231 return 0;
tony63 0:f7598e776b3c 232 }
tony63 0:f7598e776b3c 233 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 234 // Esta función de abajo es muy completa y útil, se encarga de enviar el comando y esperar la respuesta.
tony63 0:f7598e776b3c 235 // Si todo sale bien retorna un cero (herencia de las funciones contenedoras) que en la programacion hay que validar
tony63 0:f7598e776b3c 236 // con alguna expresion lógica.
tony63 0:f7598e776b3c 237 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout){
tony63 0:f7598e776b3c 238 sendCmd(cmd);
tony63 0:f7598e776b3c 239 return waitForResp(resp,timeout);
tony63 0:f7598e776b3c 240 }
tony63 0:f7598e776b3c 241 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 242 // Esta función de abajo chequea que el módem este vivo, envia AT, le contesta con OK y espera 2 segundos.
tony63 0:f7598e776b3c 243 int powerCheck(void){ // Este comando se manda para verificar si el módem esta vivo o conectado.
tony63 0:f7598e776b3c 244 return sendCmdAndWaitForResp("AT\r\n", "OK", 2);
tony63 0:f7598e776b3c 245 }
tony63 0:f7598e776b3c 246 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 247 // Esta función de abajo chequea el estado de la sim card
tony63 0:f7598e776b3c 248 // y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:f7598e776b3c 249 // con alguna expresión lógica.
tony63 0:f7598e776b3c 250 int checkSIMStatus(void){
tony63 0:f7598e776b3c 251 char gprsBuffer[30];
tony63 0:f7598e776b3c 252 int count = 0;
tony63 0:f7598e776b3c 253 cleanBuffer(gprsBuffer, 30);
tony63 0:f7598e776b3c 254 while(count < 3){
tony63 0:f7598e776b3c 255 sendCmd("AT+CPIN?\r\n");
tony63 0:f7598e776b3c 256 readBuffer(gprsBuffer,30);
tony63 0:f7598e776b3c 257 if((NULL != strstr(gprsBuffer,"+CPIN: READY"))){
tony63 0:f7598e776b3c 258 break;
tony63 0:f7598e776b3c 259 }
tony63 0:f7598e776b3c 260 count++;
tony63 0:f7598e776b3c 261 wait(1);
tony63 0:f7598e776b3c 262 }
tony63 0:f7598e776b3c 263
tony63 0:f7598e776b3c 264 if(count == 3){
tony63 0:f7598e776b3c 265 return -1;
tony63 0:f7598e776b3c 266 }
tony63 0:f7598e776b3c 267 return 0;
tony63 0:f7598e776b3c 268 }
tony63 0:f7598e776b3c 269 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 270 // Esta función de abajo chequea la calidad de la señal
tony63 0:f7598e776b3c 271 // y si todo sale bien retorna con el valor de señal útil o un -1 si no es aceptable, en la programacion hay que validar
tony63 0:f7598e776b3c 272 // con alguna expresión lógica.
tony63 0:f7598e776b3c 273 int checkSignalStrength(void){
tony63 0:f7598e776b3c 274 char gprsBuffer[100];
tony63 0:f7598e776b3c 275 int index, count = 0;
tony63 0:f7598e776b3c 276 cleanBuffer(gprsBuffer,100);
tony63 0:f7598e776b3c 277 while(count < 3){
tony63 0:f7598e776b3c 278 sendCmd("AT+CSQ\r\n");
tony63 0:f7598e776b3c 279 readBuffer(gprsBuffer,25);
tony63 0:f7598e776b3c 280 if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
tony63 0:f7598e776b3c 281 break;
tony63 0:f7598e776b3c 282 }
tony63 0:f7598e776b3c 283 count++;
tony63 0:f7598e776b3c 284 wait(1);
tony63 0:f7598e776b3c 285 }
tony63 0:f7598e776b3c 286 if(count == 3){
tony63 0:f7598e776b3c 287 return -1;
tony63 0:f7598e776b3c 288 }
tony63 0:f7598e776b3c 289 return index;
tony63 0:f7598e776b3c 290 }
tony63 0:f7598e776b3c 291 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 292 // Esta funcion de abajo inicaliza el módem. Se compone de un grupo de subfunciones ya definidas previamente
tony63 0:f7598e776b3c 293 // primero chequea que este vivo,
tony63 0:f7598e776b3c 294 // segundo chequea el estado de la simcard,
tony63 0:f7598e776b3c 295 // tercero chequea la intencidad de señal celular,
tony63 0:f7598e776b3c 296 // cuarto aplica la configuracion
tony63 0:f7598e776b3c 297 // y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:f7598e776b3c 298 // con alguna expresión lógica.
tony63 0:f7598e776b3c 299 int init(){
tony63 0:f7598e776b3c 300 if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){
tony63 0:f7598e776b3c 301 return -1;
tony63 0:f7598e776b3c 302 }
tony63 0:f7598e776b3c 303 if (0 != sendCmdAndWaitForResp("AT+CNMI=1,1\r\n", "OK", 3)){
tony63 0:f7598e776b3c 304 return -1;
tony63 0:f7598e776b3c 305 }
tony63 0:f7598e776b3c 306 if (0 != sendCmdAndWaitForResp("AT+CMGF=0\r\n", "OK", 3)){
tony63 0:f7598e776b3c 307 return -1;
tony63 0:f7598e776b3c 308 }
tony63 0:f7598e776b3c 309 if (0 != sendCmdAndWaitForResp("AT+CBST=7,0,1\r\n", "OK", 3)){ //velocidad fija a 9600, modem asincronico no transparente
tony63 0:f7598e776b3c 310 return -1;
tony63 0:f7598e776b3c 311 }
tony63 0:f7598e776b3c 312 if (0 != sendCmdAndWaitForResp("ATE\r\n", "OK", 3)){ //se le quita el eco al modem GSM
tony63 0:f7598e776b3c 313 return -1;
tony63 0:f7598e776b3c 314 }
tony63 0:f7598e776b3c 315 LedVerde=0;
tony63 0:f7598e776b3c 316 return 0;
tony63 0:f7598e776b3c 317 }
tony63 0:f7598e776b3c 318 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 319 // Esta funcion de abajo intenta leer un mensaje de texto en formato PDU o HEX
tony63 0:f7598e776b3c 320 // y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:f7598e776b3c 321 // con alguna expresión lógica.
tony63 0:f7598e776b3c 322 int readSMSpdu(char *message, int index){
tony63 0:f7598e776b3c 323 int i = 0;
tony63 0:f7598e776b3c 324 char gprsBuffer[100];
tony63 0:f7598e776b3c 325 char *p,*s;
tony63 0:f7598e776b3c 326 GSM.printf("AT+CMGR=%d\r\n",index);
tony63 0:f7598e776b3c 327 cleanBuffer(gprsBuffer,100);
tony63 0:f7598e776b3c 328 readBuffer(gprsBuffer,100);
tony63 0:f7598e776b3c 329 if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) {
tony63 0:f7598e776b3c 330 return -1;
tony63 0:f7598e776b3c 331 }
tony63 0:f7598e776b3c 332 if(NULL != ( s = strstr(gprsBuffer,"+32"))) {
tony63 0:f7598e776b3c 333 p = s + 6;
tony63 0:f7598e776b3c 334 while((*p != '$')&&(i < 5)) {
tony63 0:f7598e776b3c 335 message[i++] = *(p++);
tony63 0:f7598e776b3c 336 }
tony63 0:f7598e776b3c 337 message[i] = '\0';
tony63 0:f7598e776b3c 338 }
tony63 0:f7598e776b3c 339 return 0;
tony63 0:f7598e776b3c 340 }
tony63 0:f7598e776b3c 341 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 342 // Esta función de abajo borra mensajes SMS del modem
tony63 0:f7598e776b3c 343 // y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:f7598e776b3c 344 // con alguna expresion logica.
tony63 0:f7598e776b3c 345 int deleteSMS(int index){
tony63 0:f7598e776b3c 346 char cmd[32];
tony63 0:f7598e776b3c 347 snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
tony63 0:f7598e776b3c 348 sendCmd(cmd);
tony63 0:f7598e776b3c 349 return 0;
tony63 0:f7598e776b3c 350 }
tony63 0:f7598e776b3c 351 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:f7598e776b3c 352 // Esta función devuelve la confirmacion del mensaje a quien lo envio.
tony63 0:f7598e776b3c 353 int recibe_ok(){
tony63 0:f7598e776b3c 354 pc.printf("AT+CMGS=27\n\r");
tony63 0:f7598e776b3c 355 GSM.printf("AT+CMGS=27\n\r");
tony63 0:f7598e776b3c 356 wait(1);
tony63 0:f7598e776b3c 357 GSM.printf("0011000A91%s0000AA10CDB27B1E569741F2F2382D4E93DF",tel);
tony63 0:f7598e776b3c 358 GSM.printf("\n\r");
tony63 0:f7598e776b3c 359 pc.printf("0011000A91%s0000AA10CDB27B1E569741F2F2382D4E93DF\n\r",tel);
tony63 0:f7598e776b3c 360 pc.printf("\n\r");//control+Z
tony63 0:f7598e776b3c 361 wait(1);
tony63 0:f7598e776b3c 362 return 0;
tony63 0:f7598e776b3c 363 }
tony63 0:f7598e776b3c 364 //*******************************************************************************************************************************
tony63 0:f7598e776b3c 365 // Programas a ejecutar.
tony63 0:f7598e776b3c 366 int main(){
tony63 0:f7598e776b3c 367 //configuramos los puertos seriales
tony63 0:f7598e776b3c 368 GSM.baud(9600);//configura los baudios de la FRDMKL25Z en 9600
tony63 0:f7598e776b3c 369 GSM.format(8,Serial::None,1); //configura el formato de los datos de la UART
tony63 0:f7598e776b3c 370 LedVerde = 1; // APAGO LOS LEDS
tony63 0:f7598e776b3c 371 LedRojo = 1;
tony63 0:f7598e776b3c 372 LedAzul = 1;
tony63 0:f7598e776b3c 373 LedRojo = 0; // PRENDO EL LED ROJO
tony63 0:f7598e776b3c 374 valvula=1; // se enciende la valvula por defecto
tony63 0:f7598e776b3c 375
tony63 0:f7598e776b3c 376 //****************** CONFIGURACIÓN DEL MODEM GSM (TELEFONO CELULAR SIEMENS A56i).
tony63 0:f7598e776b3c 377 inicio1:
tony63 0:f7598e776b3c 378 ret = init();
tony63 0:f7598e776b3c 379 if(ret==0){ // esta bien conectado el modem GSM.........................................................................
tony63 0:f7598e776b3c 380 LedRojo = 1; // apagar led rojo
tony63 0:f7598e776b3c 381 LedVerde = 0; // Enciende LED Verde para confirmar la comunicación OK con el módem.
tony63 0:f7598e776b3c 382 pc.printf("Modem configurado\n");//envia mensaje a la terminal........................................................
tony63 0:f7598e776b3c 383 }
tony63 0:f7598e776b3c 384 else{
tony63 0:f7598e776b3c 385 wait(1);
tony63 0:f7598e776b3c 386 goto inicio1; // se hace un reintento de conexion o el sistema no funcionara
tony63 0:f7598e776b3c 387 }
tony63 0:f7598e776b3c 388
tony63 0:f7598e776b3c 389 //Luego se verifica GPS bien conectado (si esta habilitado por dip sw)y recibiendo satelites
tony63 0:f7598e776b3c 390 if(!sin_gps){
tony63 0:f7598e776b3c 391 pc.printf("SIN GPS\n\r");//confirma con teminal que no se habilito el gps
tony63 0:f7598e776b3c 392 goto seguir9;// de inmediato funcionara sin gps
tony63 0:f7598e776b3c 393 }
tony63 0:f7598e776b3c 394 //*****************************************Test para un GPS bien instalado***********************************************
tony63 0:f7598e776b3c 395
tony63 0:f7598e776b3c 396 //******************************************esta bien el GPS*****************************************************************
tony63 0:f7598e776b3c 397 pc.printf("CON GPS\n\r");
tony63 0:f7598e776b3c 398 g=gps.sample();
tony63 0:f7598e776b3c 399 if(g){
tony63 0:f7598e776b3c 400 LedAzul=0;
tony63 0:f7598e776b3c 401 pc.printf("GPS--OK\n\r");
tony63 0:f7598e776b3c 402 }
tony63 0:f7598e776b3c 403
tony63 0:f7598e776b3c 404 seguir9:
tony63 0:f7598e776b3c 405
tony63 0:f7598e776b3c 406 //**********************inicia codigo ciclico**********************************************
tony63 0:f7598e776b3c 407 //**********************inicia codigo ciclico**********************************************
tony63 0:f7598e776b3c 408 //**********************inicia codigo ciclico**********************************************
tony63 0:f7598e776b3c 409
tony63 0:f7598e776b3c 410 //****************DESDE ACA SE LEE CUALQUIER MENSAJE SMS ENTRANTE**************************
tony63 0:f7598e776b3c 411 while(1){
tony63 0:f7598e776b3c 412 if (GSM.readable()){
tony63 0:f7598e776b3c 413 readBuffer(buffer,110);
tony63 0:f7598e776b3c 414 pc.printf("%s\r\n",buffer);
tony63 0:f7598e776b3c 415 for(i=0; i<5; i++){
tony63 0:f7598e776b3c 416 resp[i] = buffer[i];
tony63 0:f7598e776b3c 417 }
tony63 0:f7598e776b3c 418
tony63 0:f7598e776b3c 419 pc.printf("%s\r\n", resp);
tony63 0:f7598e776b3c 420 if(strcmp("$$+CM", resp) == 0){ //COMPARA resp con "+CMTI"
tony63 0:f7598e776b3c 421 pc.printf("Llego MSG\r\n");
tony63 0:f7598e776b3c 422 cleanBuffer(buffer,10);
tony63 0:f7598e776b3c 423 GSM.printf("AT+CMGL=0\r\n"); // Envío comando para leer mensaje
tony63 0:f7598e776b3c 424 pc.printf("AT+CMGL=0\r\n");
tony63 0:f7598e776b3c 425 //GSM.printf("AT+CMGD=0\r\n"); // Envío comando para borrar el mensaje.
tony63 0:f7598e776b3c 426 readBuffer(buffer,110);
tony63 0:f7598e776b3c 427 pc.printf("%s\r\n",buffer);
tony63 0:f7598e776b3c 428
tony63 0:f7598e776b3c 429 // Lectura el teléfono emisor
tony63 0:f7598e776b3c 430 for(i=0; i<10; i++){
tony63 0:f7598e776b3c 431 tel[i] = buffer[i+40];
tony63 0:f7598e776b3c 432 }
tony63 0:f7598e776b3c 433 pc.printf("Telefono: %c%c%c%c%c%c%c%c%c%c\r\n", tel[1], tel[0], tel[3], tel[2], tel[5], tel[4], tel[7], tel[6], tel[9], tel[8]);
tony63 0:f7598e776b3c 434
tony63 0:f7598e776b3c 435 // Lectura del tamaño
tony63 0:f7598e776b3c 436 for(i=0;i<2;i++){
tony63 0:f7598e776b3c 437 tam[i] = buffer[i + 68];
tony63 0:f7598e776b3c 438 }
tony63 0:f7598e776b3c 439 pc.printf("%s-\r\n", tam);
tony63 0:f7598e776b3c 440
tony63 0:f7598e776b3c 441 // Lectura del mensaje
tony63 0:f7598e776b3c 442 for(i=0;i<26;i++){
tony63 0:f7598e776b3c 443 msg[i] = buffer[i+70]; // Lee un mensaje de 26 caracteres máximo desde la posición 70 del buffer.
tony63 0:f7598e776b3c 444 }
tony63 0:f7598e776b3c 445 pc.printf("%s-\r\n", msg);
tony63 0:f7598e776b3c 446
tony63 0:f7598e776b3c 447 // Decodificación del mensaje
tony63 0:f7598e776b3c 448
tony63 0:f7598e776b3c 449
tony63 0:f7598e776b3c 450 // Comparar el mensaje
tony63 0:f7598e776b3c 451 deleteSMS(1); // Se borran los mensajes por medio de una función
tony63 0:f7598e776b3c 452 readBuffer(buffer, 110);
tony63 0:f7598e776b3c 453 //*************************SEFGUNDO CASO ACTIVAR SALIDAS************************************ }
tony63 0:f7598e776b3c 454 //.................activar valvula de combustible...............On..on.......................
tony63 0:f7598e776b3c 455 if((strncmp("4F37", msg, 4) == 0) || (strncmp("6F37", msg, 4) == 0)){
tony63 0:f7598e776b3c 456 recibe_ok();
tony63 0:f7598e776b3c 457 valvula = 1; // Encender valvula.
tony63 0:f7598e776b3c 458 cleanBuffer(buffer, 110);
tony63 0:f7598e776b3c 459
tony63 0:f7598e776b3c 460 }
tony63 0:f7598e776b3c 461 // ...................................................... off y Off........................
tony63 0:f7598e776b3c 462 if((strncmp("4FB319", msg, 6) == 0) || (strncmp("6FB319", msg, 6) == 0)){
tony63 0:f7598e776b3c 463 recibe_ok();
tony63 0:f7598e776b3c 464 valvula = 0; // apagar valvula.
tony63 0:f7598e776b3c 465 cleanBuffer(buffer, 110);
tony63 0:f7598e776b3c 466 }
tony63 0:f7598e776b3c 467
tony63 0:f7598e776b3c 468 //............................Envia un Pulso Para Puerta Pulso...D03A7BFE06 pulso.F03A7BFE06..............
tony63 0:f7598e776b3c 469 if((strncmp("D03A7BFE06", msg, 10) == 0) || (strncmp("F03A7BFE06", msg, 10) == 0)){
tony63 0:f7598e776b3c 470 recibe_ok();//CONFIRMACION DE RECEPCION REMOTA
tony63 0:f7598e776b3c 471 puerta = 1; // Encender Puerta.
tony63 0:f7598e776b3c 472 wait(7);//pulso de 7 segundos
tony63 0:f7598e776b3c 473 puerta = 0;//apaga puerta
tony63 0:f7598e776b3c 474 cleanBuffer(buffer, 110);
tony63 0:f7598e776b3c 475 }
tony63 0:f7598e776b3c 476
tony63 0:f7598e776b3c 477 // COMPARA resp con "E3F75B4E2EBBC3E4F01C" que es "coordenadas", o "C3F75B4E2EBBC3E4F01C" que es "Coordenadas".
tony63 0:f7598e776b3c 478 if((strncmp("E3F75B4E2EBBC3E4F01C", msg, 20) == 0) || (strncmp("C3F75B4E2EBBC3E4F01C", msg, 20) == 0)){
tony63 0:f7598e776b3c 479 recibe_ok();
tony63 0:f7598e776b3c 480 LedVerde = 1; // Encender LED azul.
tony63 0:f7598e776b3c 481 LedAzul = 0;
tony63 0:f7598e776b3c 482 wait(2);
tony63 0:f7598e776b3c 483
tony63 0:f7598e776b3c 484 if(gps.sample()){
tony63 0:f7598e776b3c 485 lo = gps.longitude;
tony63 0:f7598e776b3c 486 la = gps.latitude;
tony63 0:f7598e776b3c 487 pc.printf("\nLongitud entera = %f, Latitud entera = %f\n", lo, la);
tony63 0:f7598e776b3c 488 //wait(0.5);
tony63 0:f7598e776b3c 489
tony63 0:f7598e776b3c 490 //LONGITUD
tony63 0:f7598e776b3c 491 sprintf (clo, "%f", lo);
tony63 0:f7598e776b3c 492 pc.printf ("\nLongitud = %s\n",clo);
tony63 0:f7598e776b3c 493 //wait(0.5);
tony63 0:f7598e776b3c 494
tony63 0:f7598e776b3c 495 // LATITUD
tony63 0:f7598e776b3c 496 sprintf (cla, "%f", la);
tony63 0:f7598e776b3c 497 pc.printf ( "\nLatitud = %s\n",cla);
tony63 0:f7598e776b3c 498 //wait(0.5);
tony63 0:f7598e776b3c 499
tony63 0:f7598e776b3c 500 // Concatenando las cadenas de Latitud y Longitud
tony63 0:f7598e776b3c 501 strcpy(la_lo,cla);
tony63 0:f7598e776b3c 502 strcat(la_lo,",");
tony63 0:f7598e776b3c 503 strcat(la_lo,clo);
tony63 0:f7598e776b3c 504 pc.printf("\nLatitud, Longitud: %s\n",la_lo);
tony63 0:f7598e776b3c 505
tony63 0:f7598e776b3c 506 //Ahora se juntan las cadenas obtenidas y se agrega el protocolo de transferencia de hipertextos http
tony63 0:f7598e776b3c 507 strcpy(DE1,http);
tony63 0:f7598e776b3c 508 strcat(DE1,la_lo);
tony63 0:f7598e776b3c 509 pc.printf("\nDireccion: %s\n",DE1);
tony63 0:f7598e776b3c 510 pc.printf("\n");
tony63 0:f7598e776b3c 511 LENIN1 = strlen(DE1);
tony63 0:f7598e776b3c 512
tony63 0:f7598e776b3c 513 //Conversión a octetos.
tony63 0:f7598e776b3c 514 K = 0;
tony63 0:f7598e776b3c 515 C = 0;
tony63 0:f7598e776b3c 516 for (i = 0; i < LENIN1; i++){
tony63 0:f7598e776b3c 517 DS1[i] = DE1[i + C] >> K | DE1[i + C + 1] << (7 - K);
tony63 0:f7598e776b3c 518 if(DS1[i] == 0x00) {LENOUT1 = i; goto salir1;}
tony63 0:f7598e776b3c 519 K++;
tony63 0:f7598e776b3c 520 if (K == 7) {K = 0; C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion.
tony63 0:f7598e776b3c 521 }
tony63 0:f7598e776b3c 522
tony63 0:f7598e776b3c 523 salir1:
tony63 0:f7598e776b3c 524 for (i = 0; i < LENIN1; i++){
tony63 0:f7598e776b3c 525 pc.printf("%X", DE1[i]);
tony63 0:f7598e776b3c 526 }
tony63 0:f7598e776b3c 527
tony63 0:f7598e776b3c 528 pc.printf(":\r\n");
tony63 0:f7598e776b3c 529 for (i = 0; i < LENOUT1; i++){
tony63 0:f7598e776b3c 530 pc.printf("%2X", DS1[i]&0x000000FF);
tony63 0:f7598e776b3c 531 }
tony63 0:f7598e776b3c 532 pc.printf("\r\nLENOUT GPS: %d, LENIN GPS: %2X\r\n", LENOUT1, LENIN1);
tony63 0:f7598e776b3c 533
tony63 0:f7598e776b3c 534 // Concatenación del mensaje en formato PDU y envío del mismo.
tony63 0:f7598e776b3c 535 ind = 14 + LENOUT1 - 1;
tony63 0:f7598e776b3c 536
tony63 0:f7598e776b3c 537 GSM.printf("AT+CMGS=%d\r\n",ind);
tony63 0:f7598e776b3c 538 pc.printf("AT+CMGS=%d\r\n",ind);
tony63 0:f7598e776b3c 539 pc.printf(relle1);
tony63 0:f7598e776b3c 540 GSM.printf(relle1);
tony63 0:f7598e776b3c 541
tony63 0:f7598e776b3c 542 for (i=0 ;i<=9; i++) {
tony63 0:f7598e776b3c 543 pc.printf("%c",tel[i]);
tony63 0:f7598e776b3c 544 GSM.printf("%c",tel[i]);
tony63 0:f7598e776b3c 545 }
tony63 0:f7598e776b3c 546
tony63 0:f7598e776b3c 547 pc.printf(relle2);
tony63 0:f7598e776b3c 548 GSM.printf(relle2);
tony63 0:f7598e776b3c 549 pc.printf("%2X", LENIN1);
tony63 0:f7598e776b3c 550 GSM.printf("%2X", LENIN1);
tony63 0:f7598e776b3c 551
tony63 0:f7598e776b3c 552 for (i = 0; i < LENOUT1; i++){
tony63 0:f7598e776b3c 553 pc.printf("%02X", DS1[i]&0x000000FF);
tony63 0:f7598e776b3c 554 GSM.printf("%02X", DS1[i]&0x000000FF);
tony63 0:f7598e776b3c 555 }
tony63 0:f7598e776b3c 556 wait(1);
tony63 0:f7598e776b3c 557 GSM.putc((char)0x1A); // Ctrl - Z.
tony63 0:f7598e776b3c 558 GSM.scanf("%s",buf); // Estado del mensaje (Envió o Error).
tony63 0:f7598e776b3c 559 pc.printf(">%s\n",buf);
tony63 0:f7598e776b3c 560 pc.printf("\n");
tony63 0:f7598e776b3c 561 }
tony63 0:f7598e776b3c 562
tony63 0:f7598e776b3c 563 wait(2);
tony63 0:f7598e776b3c 564 LedAzul = 1;
tony63 0:f7598e776b3c 565 LedVerde = 0;
tony63 0:f7598e776b3c 566 GSM.printf("AT+CMGD=0\r\n"); // Borra el mensaje actual (Posición "0").
tony63 0:f7598e776b3c 567 //pc.printf("\n%s\n\n", "Borro mensaje");
tony63 0:f7598e776b3c 568 }
tony63 0:f7598e776b3c 569
tony63 0:f7598e776b3c 570 // COMPARA resp con "F6379B1E569701" que es "voltaje", o "F6379B1E569701" que es "Voltaje".
tony63 0:f7598e776b3c 571 if((strncmp("F6379B1E569701", msg, 14) == 0) || (strncmp("D6379B1E569701", msg, 14) == 0)){
tony63 0:f7598e776b3c 572 //recibe_ok();
tony63 0:f7598e776b3c 573 LedRojo = 0; // Encender LED amarillo.
tony63 0:f7598e776b3c 574 LedVerde = 0;
tony63 0:f7598e776b3c 575 LedAzul = 1;
tony63 0:f7598e776b3c 576 wait(2);
tony63 0:f7598e776b3c 577
tony63 0:f7598e776b3c 578 med = v.read()*3.3;
tony63 0:f7598e776b3c 579 medi = v.read();
tony63 0:f7598e776b3c 580 pc.printf("\n%f\n", medi);
tony63 0:f7598e776b3c 581
tony63 0:f7598e776b3c 582 cleanBuffer(outmed, 16);
tony63 0:f7598e776b3c 583 if (med < 1){ // Se convierte la Medida a caracter.
tony63 0:f7598e776b3c 584 strcat(outmed, "0");
tony63 0:f7598e776b3c 585 ftoa(med, outmedn, 5);
tony63 0:f7598e776b3c 586 strcat(outmed, outmedn);
tony63 0:f7598e776b3c 587 }
tony63 0:f7598e776b3c 588 else{
tony63 0:f7598e776b3c 589 ftoa(med, outmed, 5);
tony63 0:f7598e776b3c 590 }
tony63 0:f7598e776b3c 591 strcpy(DE2,"Voltaje: ");
tony63 0:f7598e776b3c 592 strcat(DE2,outmed);
tony63 0:f7598e776b3c 593 pc.printf("\n%s\n\n", DE2);
tony63 0:f7598e776b3c 594 LENIN2 = strlen(DE2);
tony63 0:f7598e776b3c 595
tony63 0:f7598e776b3c 596 //Conversión a octetos.
tony63 0:f7598e776b3c 597 K = 0;
tony63 0:f7598e776b3c 598 C = 0;
tony63 0:f7598e776b3c 599 for (i = 0; i < LENIN2; i++){
tony63 0:f7598e776b3c 600 DS2[i] = DE2[i + C] >> K | DE2[i + C + 1] << (7 - K);
tony63 0:f7598e776b3c 601 if(DS2[i] == 0x00) {LENOUT2 = i; goto salir2;}
tony63 0:f7598e776b3c 602 K++;
tony63 0:f7598e776b3c 603 if (K == 7) {K = 0; C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion.
tony63 0:f7598e776b3c 604 }
tony63 0:f7598e776b3c 605
tony63 0:f7598e776b3c 606 salir2:
tony63 0:f7598e776b3c 607 for (i = 0; i < LENIN2; i++){
tony63 0:f7598e776b3c 608 pc.printf("%X", DE2[i]);
tony63 0:f7598e776b3c 609 }
tony63 0:f7598e776b3c 610
tony63 0:f7598e776b3c 611 pc.printf(":\r\n");
tony63 0:f7598e776b3c 612 for (i = 0; i < LENOUT2; i++){
tony63 0:f7598e776b3c 613 pc.printf("%2X", DS2[i]&0x000000FF);
tony63 0:f7598e776b3c 614 }
tony63 0:f7598e776b3c 615 pc.printf("\r\nLENOUT VOLTAJE: %d, LENIN VOLTAJE: %2X\r\n", LENOUT2, LENIN2);
tony63 0:f7598e776b3c 616
tony63 0:f7598e776b3c 617 // Concatenación del mensaje en formato PDU y envío del mismo.
tony63 0:f7598e776b3c 618 ind = 14 + LENOUT2 - 1;
tony63 0:f7598e776b3c 619
tony63 0:f7598e776b3c 620 GSM.printf("AT+CMGS=%d\r\n",ind);
tony63 0:f7598e776b3c 621 pc.printf("AT+CMGS=%d\r\n",ind);
tony63 0:f7598e776b3c 622 pc.printf(relle1);
tony63 0:f7598e776b3c 623 GSM.printf(relle1);
tony63 0:f7598e776b3c 624
tony63 0:f7598e776b3c 625 for (i=0; i <= 9; i++) {
tony63 0:f7598e776b3c 626 pc.printf("%c",tel[i]);
tony63 0:f7598e776b3c 627 GSM.printf("%c",tel[i]);
tony63 0:f7598e776b3c 628 }
tony63 0:f7598e776b3c 629
tony63 0:f7598e776b3c 630 pc.printf(relle2);
tony63 0:f7598e776b3c 631 GSM.printf(relle2);
tony63 0:f7598e776b3c 632 pc.printf("%2X", LENIN2);
tony63 0:f7598e776b3c 633 GSM.printf("%2X", LENIN2);
tony63 0:f7598e776b3c 634 /*pc.printf("0F");
tony63 0:f7598e776b3c 635 GSM.printf("0F");*/
tony63 0:f7598e776b3c 636
tony63 0:f7598e776b3c 637 for (i = 0; i < LENOUT2; i++){
tony63 0:f7598e776b3c 638 pc.printf("%02X", DS2[i]&0x000000FF);
tony63 0:f7598e776b3c 639 GSM.printf("%02X", DS2[i]&0x000000FF);
tony63 0:f7598e776b3c 640 }
tony63 0:f7598e776b3c 641
tony63 0:f7598e776b3c 642 wait(1);
tony63 0:f7598e776b3c 643 GSM.putc((char)0x1A); // Ctrl - Z
tony63 0:f7598e776b3c 644 GSM.scanf("%s",buf); // Estado del mensaje (Envió o Error).
tony63 0:f7598e776b3c 645 pc.printf(">%s\n\n",buf);
tony63 0:f7598e776b3c 646 pc.printf("\n");
tony63 0:f7598e776b3c 647
tony63 0:f7598e776b3c 648 wait(2);
tony63 0:f7598e776b3c 649 LedRojo=1;
tony63 0:f7598e776b3c 650 LedVerde=0;
tony63 0:f7598e776b3c 651 GSM.printf("AT+CMGD=0\r\n"); // Borra el mensaje actual (Posición "0").
tony63 0:f7598e776b3c 652 //pc.printf("\n%s\n\n", "Borro mensaje");
tony63 0:f7598e776b3c 653 }
tony63 0:f7598e776b3c 654 }
tony63 0:f7598e776b3c 655 }
tony63 0:f7598e776b3c 656 }
tony63 0:f7598e776b3c 657 }