![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Equipo Azul
Dependencies: mbed RASTREO_GPRS DebouncedIn GPS_G
main.cpp@0:627d6e86a48e, 2019-04-12 (annotated)
- Committer:
- tony63
- Date:
- Fri Apr 12 05:58:48 2019 +0000
- Revision:
- 0:627d6e86a48e
- Child:
- 1:3e0a9c577f09
PROGRAMA PARA HACER SEGUIMIENTO DE FLOTAS CON GPS Y CONEXION A LA RED GPRS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:627d6e86a48e | 1 | /* |
tony63 | 0:627d6e86a48e | 2 | PROGRAMA PARA HACER SEGUIMIENTO DE FLOTAS CON GPS Y CONEXION A LA RED GPRS |
tony63 | 0:627d6e86a48e | 3 | se pueden simular trayectorias gravando archivos kml en google earth y usando |
tony63 | 0:627d6e86a48e | 4 | SatGen |
tony63 | 0:627d6e86a48e | 5 | version 1.0, abril 2019 |
tony63 | 0:627d6e86a48e | 6 | |
tony63 | 0:627d6e86a48e | 7 | se asigna un APN segun el servicio GPRS de la SIMCARD |
tony63 | 0:627d6e86a48e | 8 | se asigna un nombre de host de su pagina web |
tony63 | 0:627d6e86a48e | 9 | se asigna el path de los archivos y mapas ejecutables en su servidor |
tony63 | 0:627d6e86a48e | 10 | se asigna un ciclo de repeticion de lecturas de GPS. |
tony63 | 0:627d6e86a48e | 11 | |
tony63 | 0:627d6e86a48e | 12 | */ |
tony63 | 0:627d6e86a48e | 13 | |
tony63 | 0:627d6e86a48e | 14 | #include "mbed.h" |
tony63 | 0:627d6e86a48e | 15 | #include "stdio.h" |
tony63 | 0:627d6e86a48e | 16 | #include "string.h" |
tony63 | 0:627d6e86a48e | 17 | #include "GPS.h" |
tony63 | 0:627d6e86a48e | 18 | |
tony63 | 0:627d6e86a48e | 19 | Timer t; |
tony63 | 0:627d6e86a48e | 20 | DigitalOut LedVerde(LED2); |
tony63 | 0:627d6e86a48e | 21 | DigitalOut LedRojo(LED1); |
tony63 | 0:627d6e86a48e | 22 | DigitalOut LedAzul(LED3); |
tony63 | 0:627d6e86a48e | 23 | InterruptIn button(PTA13); |
tony63 | 0:627d6e86a48e | 24 | |
tony63 | 0:627d6e86a48e | 25 | |
tony63 | 0:627d6e86a48e | 26 | float lo,la; |
tony63 | 0:627d6e86a48e | 27 | char lon[15], lat[15]; // Cadenas a capturar para latitud y longitud. |
tony63 | 0:627d6e86a48e | 28 | char gprsBuffer[20]; |
tony63 | 0:627d6e86a48e | 29 | char resp[15]; |
tony63 | 0:627d6e86a48e | 30 | Serial GSM(PTE0,PTE1); // Puertos del FRDM para el Módem. |
tony63 | 0:627d6e86a48e | 31 | Serial pc(USBTX,USBRX); |
tony63 | 0:627d6e86a48e | 32 | GPS gps(PTE22, PTE23); // Puerto del FDRM para el GPS. |
tony63 | 0:627d6e86a48e | 33 | int result; |
tony63 | 0:627d6e86a48e | 34 | int z=0; |
tony63 | 0:627d6e86a48e | 35 | int i=0; |
tony63 | 0:627d6e86a48e | 36 | int count=0; |
tony63 | 0:627d6e86a48e | 37 | |
tony63 | 0:627d6e86a48e | 38 | //----------------------------------------------------------------------------------------------------------------------------- |
tony63 | 0:627d6e86a48e | 39 | // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de |
tony63 | 0:627d6e86a48e | 40 | // $, count es lo que va a leer. Lo leido lo mete en buffer que es una cadena previamente definida |
tony63 | 0:627d6e86a48e | 41 | // incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1 |
tony63 | 0:627d6e86a48e | 42 | int readBuffer(char *buffer,int count){ |
tony63 | 0:627d6e86a48e | 43 | int i=0; |
tony63 | 0:627d6e86a48e | 44 | t.start(); // start timer |
tony63 | 0:627d6e86a48e | 45 | while(1) { |
tony63 | 0:627d6e86a48e | 46 | while (GSM.readable()) { |
tony63 | 0:627d6e86a48e | 47 | char c = GSM.getc(); |
tony63 | 0:627d6e86a48e | 48 | if (c == '\r' || c == '\n') c = '$'; |
tony63 | 0:627d6e86a48e | 49 | buffer[i++] = c; |
tony63 | 0:627d6e86a48e | 50 | if(i > count)break; |
tony63 | 0:627d6e86a48e | 51 | } |
tony63 | 0:627d6e86a48e | 52 | if(i > count)break; |
tony63 | 0:627d6e86a48e | 53 | if(t.read() > 3) { |
tony63 | 0:627d6e86a48e | 54 | t.stop(); |
tony63 | 0:627d6e86a48e | 55 | t.reset(); |
tony63 | 0:627d6e86a48e | 56 | break; |
tony63 | 0:627d6e86a48e | 57 | } |
tony63 | 0:627d6e86a48e | 58 | } |
tony63 | 0:627d6e86a48e | 59 | wait(0.5); |
tony63 | 0:627d6e86a48e | 60 | while(GSM.readable()){ // display the other thing.. |
tony63 | 0:627d6e86a48e | 61 | char c = GSM.getc(); |
tony63 | 0:627d6e86a48e | 62 | } |
tony63 | 0:627d6e86a48e | 63 | return 0; |
tony63 | 0:627d6e86a48e | 64 | } |
tony63 | 0:627d6e86a48e | 65 | //-------------------------------------------------------------------------------------------------------------- |
tony63 | 0:627d6e86a48e | 66 | // Esta función de abajo limpia o borra todo un "buffer" de tamaño "count", |
tony63 | 0:627d6e86a48e | 67 | // lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena. |
tony63 | 0:627d6e86a48e | 68 | // No retorna nada. |
tony63 | 0:627d6e86a48e | 69 | void cleanBuffer(char *buffer, int count){ |
tony63 | 0:627d6e86a48e | 70 | for(int i=0; i < count; i++) { |
tony63 | 0:627d6e86a48e | 71 | buffer[i] = '\0'; |
tony63 | 0:627d6e86a48e | 72 | } |
tony63 | 0:627d6e86a48e | 73 | } |
tony63 | 0:627d6e86a48e | 74 | |
tony63 | 0:627d6e86a48e | 75 | //-------------------------------------------------------------------------------------------------------------- |
tony63 | 0:627d6e86a48e | 76 | // Esta función de abajo envia un comando parametrizado como cadena |
tony63 | 0:627d6e86a48e | 77 | // puede ser un comando tipo AT. |
tony63 | 0:627d6e86a48e | 78 | void sendCmd(char *cmd){ |
tony63 | 0:627d6e86a48e | 79 | GSM.puts(cmd); |
tony63 | 0:627d6e86a48e | 80 | } |
tony63 | 0:627d6e86a48e | 81 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 82 | // 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:627d6e86a48e | 83 | // si todo sale bien retorna un cero que en la programacion hay que validar, |
tony63 | 0:627d6e86a48e | 84 | // si algo sale mal (no se parece o se demora mucho) retorna -1 que debera validarse con alguna expresion logica. |
tony63 | 0:627d6e86a48e | 85 | int waitForResp(char *resp, int timeout){ |
tony63 | 0:627d6e86a48e | 86 | int len = strlen(resp); |
tony63 | 0:627d6e86a48e | 87 | int sum=0; |
tony63 | 0:627d6e86a48e | 88 | t.start(); |
tony63 | 0:627d6e86a48e | 89 | |
tony63 | 0:627d6e86a48e | 90 | while(1) { |
tony63 | 0:627d6e86a48e | 91 | if(GSM.readable()) { |
tony63 | 0:627d6e86a48e | 92 | char c = GSM.getc(); |
tony63 | 0:627d6e86a48e | 93 | sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c |
tony63 | 0:627d6e86a48e | 94 | if(sum == len)break; //ya acabo se sale |
tony63 | 0:627d6e86a48e | 95 | } |
tony63 | 0:627d6e86a48e | 96 | if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo |
tony63 | 0:627d6e86a48e | 97 | t.stop(); |
tony63 | 0:627d6e86a48e | 98 | t.reset(); |
tony63 | 0:627d6e86a48e | 99 | return -1; |
tony63 | 0:627d6e86a48e | 100 | } |
tony63 | 0:627d6e86a48e | 101 | } |
tony63 | 0:627d6e86a48e | 102 | t.stop(); // stop timer antes de retornar |
tony63 | 0:627d6e86a48e | 103 | t.reset(); // clear timer |
tony63 | 0:627d6e86a48e | 104 | while(GSM.readable()) { // display the other thing.. |
tony63 | 0:627d6e86a48e | 105 | char c = GSM.getc(); |
tony63 | 0:627d6e86a48e | 106 | } |
tony63 | 0:627d6e86a48e | 107 | return 0; |
tony63 | 0:627d6e86a48e | 108 | } |
tony63 | 0:627d6e86a48e | 109 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 110 | // Esta función de abajo es muy completa y útil, se encarga de enviar el comando y esperar la respuesta. |
tony63 | 0:627d6e86a48e | 111 | // Si todo sale bien retorna un cero (herencia de las funciones contenedoras) que en la programacion hay que validar |
tony63 | 0:627d6e86a48e | 112 | // con alguna expresion lógica. |
tony63 | 0:627d6e86a48e | 113 | int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout){ |
tony63 | 0:627d6e86a48e | 114 | sendCmd(cmd); |
tony63 | 0:627d6e86a48e | 115 | return waitForResp(resp,timeout); |
tony63 | 0:627d6e86a48e | 116 | } |
tony63 | 0:627d6e86a48e | 117 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 118 | // Esta función de abajo chequea que el módem este vivo, envia AT, le contesta con OK y espera 2 segundos. |
tony63 | 0:627d6e86a48e | 119 | int powerCheck(void){ // Este comando se manda para verificar si el módem esta vivo o conectado. |
tony63 | 0:627d6e86a48e | 120 | return sendCmdAndWaitForResp("AT\r\n", "OK", 2); |
tony63 | 0:627d6e86a48e | 121 | } |
tony63 | 0:627d6e86a48e | 122 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 123 | // Esta función de abajo chequea el estado de la sim card |
tony63 | 0:627d6e86a48e | 124 | // y si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:627d6e86a48e | 125 | // con alguna expresión lógica. |
tony63 | 0:627d6e86a48e | 126 | int checkSIMStatus(void){ |
tony63 | 0:627d6e86a48e | 127 | char gprsBuffer[30]; |
tony63 | 0:627d6e86a48e | 128 | int count = 0; |
tony63 | 0:627d6e86a48e | 129 | cleanBuffer(gprsBuffer, 30); |
tony63 | 0:627d6e86a48e | 130 | while(count < 3){ |
tony63 | 0:627d6e86a48e | 131 | sendCmd("AT+CPIN?\r\n"); |
tony63 | 0:627d6e86a48e | 132 | readBuffer(gprsBuffer,30); |
tony63 | 0:627d6e86a48e | 133 | if((NULL != strstr(gprsBuffer,"+CPIN: READY"))){ |
tony63 | 0:627d6e86a48e | 134 | break; |
tony63 | 0:627d6e86a48e | 135 | } |
tony63 | 0:627d6e86a48e | 136 | count++; |
tony63 | 0:627d6e86a48e | 137 | wait(1); |
tony63 | 0:627d6e86a48e | 138 | } |
tony63 | 0:627d6e86a48e | 139 | |
tony63 | 0:627d6e86a48e | 140 | if(count == 3){ |
tony63 | 0:627d6e86a48e | 141 | return -1; |
tony63 | 0:627d6e86a48e | 142 | } |
tony63 | 0:627d6e86a48e | 143 | return 0; |
tony63 | 0:627d6e86a48e | 144 | } |
tony63 | 0:627d6e86a48e | 145 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 146 | |
tony63 | 0:627d6e86a48e | 147 | // Esta función de abajo chequea la calidad de la señal |
tony63 | 0:627d6e86a48e | 148 | // 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:627d6e86a48e | 149 | // con alguna expresión lógica. |
tony63 | 0:627d6e86a48e | 150 | int checkSignalStrength(void){ |
tony63 | 0:627d6e86a48e | 151 | char gprsBuffer[100]; |
tony63 | 0:627d6e86a48e | 152 | int index, count = 0; |
tony63 | 0:627d6e86a48e | 153 | cleanBuffer(gprsBuffer,100); |
tony63 | 0:627d6e86a48e | 154 | while(count < 3){ |
tony63 | 0:627d6e86a48e | 155 | sendCmd("AT+CSQ\r\n"); |
tony63 | 0:627d6e86a48e | 156 | readBuffer(gprsBuffer,25); |
tony63 | 0:627d6e86a48e | 157 | if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) { |
tony63 | 0:627d6e86a48e | 158 | break; |
tony63 | 0:627d6e86a48e | 159 | } |
tony63 | 0:627d6e86a48e | 160 | count++; |
tony63 | 0:627d6e86a48e | 161 | wait(1); |
tony63 | 0:627d6e86a48e | 162 | } |
tony63 | 0:627d6e86a48e | 163 | if(count == 3){ |
tony63 | 0:627d6e86a48e | 164 | return -1; |
tony63 | 0:627d6e86a48e | 165 | } |
tony63 | 0:627d6e86a48e | 166 | return index; |
tony63 | 0:627d6e86a48e | 167 | } |
tony63 | 0:627d6e86a48e | 168 | |
tony63 | 0:627d6e86a48e | 169 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 170 | |
tony63 | 0:627d6e86a48e | 171 | // detectar direcion ip |
tony63 | 0:627d6e86a48e | 172 | int ip_detect(){ |
tony63 | 0:627d6e86a48e | 173 | if (GSM.readable()){ |
tony63 | 0:627d6e86a48e | 174 | readBuffer(gprsBuffer,15); |
tony63 | 0:627d6e86a48e | 175 | for(i=0;i<15;i++) |
tony63 | 0:627d6e86a48e | 176 | { |
tony63 | 0:627d6e86a48e | 177 | resp[i]=gprsBuffer[i]; |
tony63 | 0:627d6e86a48e | 178 | } |
tony63 | 0:627d6e86a48e | 179 | cleanBuffer(gprsBuffer,20); |
tony63 | 0:627d6e86a48e | 180 | for(i=0;i<15;i++){ |
tony63 | 0:627d6e86a48e | 181 | if(resp[i]== '.'){ |
tony63 | 0:627d6e86a48e | 182 | z++; |
tony63 | 0:627d6e86a48e | 183 | } |
tony63 | 0:627d6e86a48e | 184 | } |
tony63 | 0:627d6e86a48e | 185 | if(z==3){ |
tony63 | 0:627d6e86a48e | 186 | pc.printf("llego ip=%d\r\n",z); |
tony63 | 0:627d6e86a48e | 187 | z=0; |
tony63 | 0:627d6e86a48e | 188 | return 0; |
tony63 | 0:627d6e86a48e | 189 | } |
tony63 | 0:627d6e86a48e | 190 | }//fin check GSM modem |
tony63 | 0:627d6e86a48e | 191 | z=0; |
tony63 | 0:627d6e86a48e | 192 | return -1; |
tony63 | 0:627d6e86a48e | 193 | }//fin funcion |
tony63 | 0:627d6e86a48e | 194 | |
tony63 | 0:627d6e86a48e | 195 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 196 | // Esta funcion de abajo inicia la comunicacion GPRS con la red celular, Se compone de un grupo de subfunciones ya definidas previamente |
tony63 | 0:627d6e86a48e | 197 | // envia las secuencias de forma ordenada esparando la respuesta adecuada |
tony63 | 0:627d6e86a48e | 198 | // si todo sale bien retorna un cero que en la programacion hay que validar |
tony63 | 0:627d6e86a48e | 199 | // con alguna expresión lógica. |
tony63 | 0:627d6e86a48e | 200 | //********************************************************************************************************* |
tony63 | 0:627d6e86a48e | 201 | |
tony63 | 0:627d6e86a48e | 202 | int init_gprs(void){ |
tony63 | 0:627d6e86a48e | 203 | |
tony63 | 0:627d6e86a48e | 204 | if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){ |
tony63 | 0:627d6e86a48e | 205 | return -1; |
tony63 | 0:627d6e86a48e | 206 | } |
tony63 | 0:627d6e86a48e | 207 | if (0 != sendCmdAndWaitForResp("ATE0\r\n", "OK", 3)){ //sin eco |
tony63 | 0:627d6e86a48e | 208 | return -1; |
tony63 | 0:627d6e86a48e | 209 | } |
tony63 | 0:627d6e86a48e | 210 | if (0 != sendCmdAndWaitForResp("AT+CGATT=1\r\n", "OK", 3)){//inicia conexion GPRS |
tony63 | 0:627d6e86a48e | 211 | return -1; |
tony63 | 0:627d6e86a48e | 212 | } |
tony63 | 0:627d6e86a48e | 213 | if (0 != sendCmdAndWaitForResp("AT+CSTT=internet.comcel.com.co,comcel,comcel\r\n", "OK", 3)){ //set apn |
tony63 | 0:627d6e86a48e | 214 | return -1; |
tony63 | 0:627d6e86a48e | 215 | } |
tony63 | 0:627d6e86a48e | 216 | if (0 != sendCmdAndWaitForResp("AT+CIICR\r\n", "OK", 3)){ //habilitar conexion inalambrica |
tony63 | 0:627d6e86a48e | 217 | return -1; |
tony63 | 0:627d6e86a48e | 218 | } |
tony63 | 0:627d6e86a48e | 219 | |
tony63 | 0:627d6e86a48e | 220 | cleanBuffer(gprsBuffer,25); |
tony63 | 0:627d6e86a48e | 221 | sendCmd("AT+CIFSR\r\n"); //obtener direccion ip |
tony63 | 0:627d6e86a48e | 222 | if(0 != ip_detect()){ //esperar la llegada de un direccion IP |
tony63 | 0:627d6e86a48e | 223 | return -1; |
tony63 | 0:627d6e86a48e | 224 | } |
tony63 | 0:627d6e86a48e | 225 | wait(1); |
tony63 | 0:627d6e86a48e | 226 | LedVerde=0; |
tony63 | 0:627d6e86a48e | 227 | return 0; |
tony63 | 0:627d6e86a48e | 228 | } |
tony63 | 0:627d6e86a48e | 229 | |
tony63 | 0:627d6e86a48e | 230 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 231 | |
tony63 | 0:627d6e86a48e | 232 | int end_gprs(void){ |
tony63 | 0:627d6e86a48e | 233 | if (0 != sendCmdAndWaitForResp("AT+CIPSHUT\r\n", "OK", 3)){ |
tony63 | 0:627d6e86a48e | 234 | return -1; |
tony63 | 0:627d6e86a48e | 235 | } |
tony63 | 0:627d6e86a48e | 236 | if (0 != sendCmdAndWaitForResp("AT+CGATT=0\r\n", "SHUT OK", 3)){ |
tony63 | 0:627d6e86a48e | 237 | return -1; |
tony63 | 0:627d6e86a48e | 238 | } |
tony63 | 0:627d6e86a48e | 239 | LedVerde=0; |
tony63 | 0:627d6e86a48e | 240 | LedRojo=1; |
tony63 | 0:627d6e86a48e | 241 | return 0; |
tony63 | 0:627d6e86a48e | 242 | } |
tony63 | 0:627d6e86a48e | 243 | |
tony63 | 0:627d6e86a48e | 244 | //++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 245 | //interupcion perdida de energia |
tony63 | 0:627d6e86a48e | 246 | //++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 247 | |
tony63 | 0:627d6e86a48e | 248 | void off_gprs(){ |
tony63 | 0:627d6e86a48e | 249 | end_gprs(); |
tony63 | 0:627d6e86a48e | 250 | } |
tony63 | 0:627d6e86a48e | 251 | |
tony63 | 0:627d6e86a48e | 252 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 253 | //inicio del programa principal |
tony63 | 0:627d6e86a48e | 254 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++ |
tony63 | 0:627d6e86a48e | 255 | int main(){ |
tony63 | 0:627d6e86a48e | 256 | |
tony63 | 0:627d6e86a48e | 257 | lop1: |
tony63 | 0:627d6e86a48e | 258 | if(init_gprs()<0){ |
tony63 | 0:627d6e86a48e | 259 | LedRojo=0; |
tony63 | 0:627d6e86a48e | 260 | LedVerde=1; |
tony63 | 0:627d6e86a48e | 261 | goto lop1; |
tony63 | 0:627d6e86a48e | 262 | } |
tony63 | 0:627d6e86a48e | 263 | button.fall(&off_gprs);//perdida de alimentacion,apagaron carro |
tony63 | 0:627d6e86a48e | 264 | while(1){ //si el GPS tiene conexion y datos se envian coordenadas a pagina web |
tony63 | 0:627d6e86a48e | 265 | LedAzul=1; |
tony63 | 0:627d6e86a48e | 266 | if(gps.sample()){ |
tony63 | 0:627d6e86a48e | 267 | LedAzul=0; |
tony63 | 0:627d6e86a48e | 268 | lo = gps.longitude; |
tony63 | 0:627d6e86a48e | 269 | la = gps.latitude; |
tony63 | 0:627d6e86a48e | 270 | sprintf (lon, "%f", lo);//pasa de flotante a caracter |
tony63 | 0:627d6e86a48e | 271 | sprintf (lat, "%f", la);//pasa de flotante a caracter |
tony63 | 0:627d6e86a48e | 272 | repetir1:if (0 != sendCmdAndWaitForResp("AT+CIPSTART=TCP,unrobotica.com,80\r\n","OK", 3)){ |
tony63 | 0:627d6e86a48e | 273 | wait(3); |
tony63 | 0:627d6e86a48e | 274 | LedVerde=1; |
tony63 | 0:627d6e86a48e | 275 | LedRojo=0; |
tony63 | 0:627d6e86a48e | 276 | goto repetir1; |
tony63 | 0:627d6e86a48e | 277 | } |
tony63 | 0:627d6e86a48e | 278 | |
tony63 | 0:627d6e86a48e | 279 | repetir2:cleanBuffer(gprsBuffer,10); |
tony63 | 0:627d6e86a48e | 280 | //sendCmd("AT+CIPSEND\r\n"); |
tony63 | 0:627d6e86a48e | 281 | if(0 !=sendCmdAndWaitForResp("AT+CIPSEND\r\n","",3)){ |
tony63 | 0:627d6e86a48e | 282 | wait(1); |
tony63 | 0:627d6e86a48e | 283 | goto repetir2; |
tony63 | 0:627d6e86a48e | 284 | } |
tony63 | 0:627d6e86a48e | 285 | //aca el servidor contesta con contol+z y hay que verificar eso. |
tony63 | 0:627d6e86a48e | 286 | //readBuffer(gprsBuffer,10); |
tony63 | 0:627d6e86a48e | 287 | //if((NULL = strstr(gprsBuffer,""))){ |
tony63 | 0:627d6e86a48e | 288 | // wait(1); |
tony63 | 0:627d6e86a48e | 289 | // goto repetir2; |
tony63 | 0:627d6e86a48e | 290 | GSM.printf("GET /gpstracker/gps1.php?lat=%s&lon=%s HTTP/1.0\r\n",lat,lon); |
tony63 | 0:627d6e86a48e | 291 | GSM.printf("Host: unrobotica.com\n\n"); |
tony63 | 0:627d6e86a48e | 292 | GSM.printf("\r\n"); |
tony63 | 0:627d6e86a48e | 293 | GSM.printf("\n\r"); |
tony63 | 0:627d6e86a48e | 294 | //cleanBuffer(gprsBuffer,20); |
tony63 | 0:627d6e86a48e | 295 | //leer bufer y encontrar respuesta exitosa devuelve "SEND OK" |
tony63 | 0:627d6e86a48e | 296 | |
tony63 | 0:627d6e86a48e | 297 | //readBuffer(gprsBuffer,10); |
tony63 | 0:627d6e86a48e | 298 | //if((NULL = strstr(gprsBuffer,""))){ |
tony63 | 0:627d6e86a48e | 299 | // wait(1); |
tony63 | 0:627d6e86a48e | 300 | // goto repetir2; |
tony63 | 0:627d6e86a48e | 301 | LedRojo=1; |
tony63 | 0:627d6e86a48e | 302 | LedVerde=0; //envio OK |
tony63 | 0:627d6e86a48e | 303 | }// del test del gps |
tony63 | 0:627d6e86a48e | 304 | LedRojo=0; // hay problemas |
tony63 | 0:627d6e86a48e | 305 | LedVerde=1; |
tony63 | 0:627d6e86a48e | 306 | |
tony63 | 0:627d6e86a48e | 307 | }//del while col 13 |
tony63 | 0:627d6e86a48e | 308 | |
tony63 | 0:627d6e86a48e | 309 | }//del main col 11 |
tony63 | 0:627d6e86a48e | 310 | |
tony63 | 0:627d6e86a48e | 311 | |
tony63 | 0:627d6e86a48e | 312 | |
tony63 | 0:627d6e86a48e | 313 | |
tony63 | 0:627d6e86a48e | 314 |