PROGRAMA PARA HACER SEGUIMIENTO DE FLOTAS CON GPS Y CONEXION A LA RED GPRS

Dependencies:   mbed DebouncedIn GPS_G

Dependents:   61_RASTREO_GPRS_copy

PROGRAMA PARA HACER SEGUIMIENTO DE FLOTAS CON GPS Y CONEXION A LA RED GPRS

Emplea modem gprs SIM900

vea pagina completa del proyecto.:

https://www.unrobotica.com/proyectos/rastreadorgsm.html

se implementa en una FRDMKL25Z y un modulo Bluepill STM32F103.

/media/uploads/tony63/img6.jpg

Committer:
tony63
Date:
Tue Sep 03 08:00:18 2019 +0000
Revision:
3:cd97b1ddaa23
Parent:
2:f4483748eee0
ok

Who changed what in which revision?

UserRevisionLine numberNew 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 3:cd97b1ddaa23 5 version 2.0, sep 3 / 2019
tony63 0:627d6e86a48e 6
tony63 3:cd97b1ddaa23 7 se asigna un APN segun el servicio GPRS de la SIMCARD (claro Colombia)
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 1:3e0a9c577f09 37 int g=0;
tony63 0:627d6e86a48e 38
tony63 0:627d6e86a48e 39 //-----------------------------------------------------------------------------------------------------------------------------
tony63 0:627d6e86a48e 40 // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de
tony63 0:627d6e86a48e 41 // $, count es lo que va a leer. Lo leido lo mete en buffer que es una cadena previamente definida
tony63 0:627d6e86a48e 42 // incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1
tony63 0:627d6e86a48e 43 int readBuffer(char *buffer,int count){
tony63 0:627d6e86a48e 44 int i=0;
tony63 0:627d6e86a48e 45 t.start(); // start timer
tony63 0:627d6e86a48e 46 while(1) {
tony63 0:627d6e86a48e 47 while (GSM.readable()) {
tony63 0:627d6e86a48e 48 char c = GSM.getc();
tony63 0:627d6e86a48e 49 if (c == '\r' || c == '\n') c = '$';
tony63 0:627d6e86a48e 50 buffer[i++] = c;
tony63 0:627d6e86a48e 51 if(i > count)break;
tony63 0:627d6e86a48e 52 }
tony63 0:627d6e86a48e 53 if(i > count)break;
tony63 0:627d6e86a48e 54 if(t.read() > 3) {
tony63 0:627d6e86a48e 55 t.stop();
tony63 0:627d6e86a48e 56 t.reset();
tony63 0:627d6e86a48e 57 break;
tony63 0:627d6e86a48e 58 }
tony63 0:627d6e86a48e 59 }
tony63 0:627d6e86a48e 60 wait(0.5);
tony63 0:627d6e86a48e 61 while(GSM.readable()){ // display the other thing..
tony63 0:627d6e86a48e 62 char c = GSM.getc();
tony63 0:627d6e86a48e 63 }
tony63 0:627d6e86a48e 64 return 0;
tony63 0:627d6e86a48e 65 }
tony63 0:627d6e86a48e 66 //--------------------------------------------------------------------------------------------------------------
tony63 0:627d6e86a48e 67 // Esta función de abajo limpia o borra todo un "buffer" de tamaño "count",
tony63 0:627d6e86a48e 68 // lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena.
tony63 0:627d6e86a48e 69 // No retorna nada.
tony63 0:627d6e86a48e 70 void cleanBuffer(char *buffer, int count){
tony63 0:627d6e86a48e 71 for(int i=0; i < count; i++) {
tony63 0:627d6e86a48e 72 buffer[i] = '\0';
tony63 0:627d6e86a48e 73 }
tony63 0:627d6e86a48e 74 }
tony63 0:627d6e86a48e 75
tony63 0:627d6e86a48e 76 //--------------------------------------------------------------------------------------------------------------
tony63 0:627d6e86a48e 77 // Esta función de abajo envia un comando parametrizado como cadena
tony63 0:627d6e86a48e 78 // puede ser un comando tipo AT.
tony63 0:627d6e86a48e 79 void sendCmd(char *cmd){
tony63 0:627d6e86a48e 80 GSM.puts(cmd);
tony63 0:627d6e86a48e 81 }
tony63 0:627d6e86a48e 82 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 83 // 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 84 // si todo sale bien retorna un cero que en la programacion hay que validar,
tony63 0:627d6e86a48e 85 // si algo sale mal (no se parece o se demora mucho) retorna -1 que debera validarse con alguna expresion logica.
tony63 0:627d6e86a48e 86 int waitForResp(char *resp, int timeout){
tony63 0:627d6e86a48e 87 int len = strlen(resp);
tony63 0:627d6e86a48e 88 int sum=0;
tony63 0:627d6e86a48e 89 t.start();
tony63 0:627d6e86a48e 90
tony63 0:627d6e86a48e 91 while(1) {
tony63 0:627d6e86a48e 92 if(GSM.readable()) {
tony63 0:627d6e86a48e 93 char c = GSM.getc();
tony63 0:627d6e86a48e 94 sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c
tony63 0:627d6e86a48e 95 if(sum == len)break; //ya acabo se sale
tony63 0:627d6e86a48e 96 }
tony63 0:627d6e86a48e 97 if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo
tony63 0:627d6e86a48e 98 t.stop();
tony63 0:627d6e86a48e 99 t.reset();
tony63 0:627d6e86a48e 100 return -1;
tony63 0:627d6e86a48e 101 }
tony63 0:627d6e86a48e 102 }
tony63 0:627d6e86a48e 103 t.stop(); // stop timer antes de retornar
tony63 0:627d6e86a48e 104 t.reset(); // clear timer
tony63 0:627d6e86a48e 105 while(GSM.readable()) { // display the other thing..
tony63 0:627d6e86a48e 106 char c = GSM.getc();
tony63 0:627d6e86a48e 107 }
tony63 0:627d6e86a48e 108 return 0;
tony63 0:627d6e86a48e 109 }
tony63 0:627d6e86a48e 110 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 111 // Esta función de abajo es muy completa y útil, se encarga de enviar el comando y esperar la respuesta.
tony63 0:627d6e86a48e 112 // Si todo sale bien retorna un cero (herencia de las funciones contenedoras) que en la programacion hay que validar
tony63 0:627d6e86a48e 113 // con alguna expresion lógica.
tony63 0:627d6e86a48e 114 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout){
tony63 0:627d6e86a48e 115 sendCmd(cmd);
tony63 0:627d6e86a48e 116 return waitForResp(resp,timeout);
tony63 0:627d6e86a48e 117 }
tony63 0:627d6e86a48e 118 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 119 // 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 120 int powerCheck(void){ // Este comando se manda para verificar si el módem esta vivo o conectado.
tony63 0:627d6e86a48e 121 return sendCmdAndWaitForResp("AT\r\n", "OK", 2);
tony63 0:627d6e86a48e 122 }
tony63 0:627d6e86a48e 123 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 124 // Esta función de abajo chequea el estado de la sim card
tony63 0:627d6e86a48e 125 // y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:627d6e86a48e 126 // con alguna expresión lógica.
tony63 0:627d6e86a48e 127 int checkSIMStatus(void){
tony63 0:627d6e86a48e 128 char gprsBuffer[30];
tony63 0:627d6e86a48e 129 int count = 0;
tony63 0:627d6e86a48e 130 cleanBuffer(gprsBuffer, 30);
tony63 0:627d6e86a48e 131 while(count < 3){
tony63 0:627d6e86a48e 132 sendCmd("AT+CPIN?\r\n");
tony63 0:627d6e86a48e 133 readBuffer(gprsBuffer,30);
tony63 0:627d6e86a48e 134 if((NULL != strstr(gprsBuffer,"+CPIN: READY"))){
tony63 0:627d6e86a48e 135 break;
tony63 0:627d6e86a48e 136 }
tony63 0:627d6e86a48e 137 count++;
tony63 0:627d6e86a48e 138 wait(1);
tony63 0:627d6e86a48e 139 }
tony63 0:627d6e86a48e 140
tony63 0:627d6e86a48e 141 if(count == 3){
tony63 0:627d6e86a48e 142 return -1;
tony63 0:627d6e86a48e 143 }
tony63 0:627d6e86a48e 144 return 0;
tony63 0:627d6e86a48e 145 }
tony63 0:627d6e86a48e 146 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 147
tony63 0:627d6e86a48e 148 // Esta función de abajo chequea la calidad de la señal
tony63 0:627d6e86a48e 149 // 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 150 // con alguna expresión lógica.
tony63 0:627d6e86a48e 151 int checkSignalStrength(void){
tony63 0:627d6e86a48e 152 char gprsBuffer[100];
tony63 0:627d6e86a48e 153 int index, count = 0;
tony63 0:627d6e86a48e 154 cleanBuffer(gprsBuffer,100);
tony63 0:627d6e86a48e 155 while(count < 3){
tony63 0:627d6e86a48e 156 sendCmd("AT+CSQ\r\n");
tony63 0:627d6e86a48e 157 readBuffer(gprsBuffer,25);
tony63 0:627d6e86a48e 158 if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
tony63 0:627d6e86a48e 159 break;
tony63 0:627d6e86a48e 160 }
tony63 0:627d6e86a48e 161 count++;
tony63 0:627d6e86a48e 162 wait(1);
tony63 0:627d6e86a48e 163 }
tony63 0:627d6e86a48e 164 if(count == 3){
tony63 0:627d6e86a48e 165 return -1;
tony63 0:627d6e86a48e 166 }
tony63 0:627d6e86a48e 167 return index;
tony63 0:627d6e86a48e 168 }
tony63 0:627d6e86a48e 169
tony63 0:627d6e86a48e 170 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 171
tony63 0:627d6e86a48e 172 // detectar direcion ip
tony63 0:627d6e86a48e 173 int ip_detect(){
tony63 0:627d6e86a48e 174 if (GSM.readable()){
tony63 0:627d6e86a48e 175 readBuffer(gprsBuffer,15);
tony63 0:627d6e86a48e 176 for(i=0;i<15;i++)
tony63 0:627d6e86a48e 177 {
tony63 0:627d6e86a48e 178 resp[i]=gprsBuffer[i];
tony63 0:627d6e86a48e 179 }
tony63 0:627d6e86a48e 180 cleanBuffer(gprsBuffer,20);
tony63 0:627d6e86a48e 181 for(i=0;i<15;i++){
tony63 0:627d6e86a48e 182 if(resp[i]== '.'){
tony63 0:627d6e86a48e 183 z++;
tony63 0:627d6e86a48e 184 }
tony63 0:627d6e86a48e 185 }
tony63 1:3e0a9c577f09 186 if(z==3){ //CUENTO TRES PUNTOS LO MAS PROBABLE ES QUE SEA UNA DIRECCION ip
tony63 0:627d6e86a48e 187 pc.printf("llego ip=%d\r\n",z);
tony63 0:627d6e86a48e 188 z=0;
tony63 1:3e0a9c577f09 189 return 0; //RETORNA CON CERO SI LLEGARON TRES PUNTOS
tony63 0:627d6e86a48e 190 }
tony63 0:627d6e86a48e 191 }//fin check GSM modem
tony63 0:627d6e86a48e 192 z=0;
tony63 1:3e0a9c577f09 193 return -1; //NO LLEGARON 3 PUNTOS RETORNA CON -1
tony63 0:627d6e86a48e 194 }//fin funcion
tony63 0:627d6e86a48e 195
tony63 0:627d6e86a48e 196 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 197 // 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 198 // envia las secuencias de forma ordenada esparando la respuesta adecuada
tony63 0:627d6e86a48e 199 // si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:627d6e86a48e 200 // con alguna expresión lógica.
tony63 0:627d6e86a48e 201 //*********************************************************************************************************
tony63 0:627d6e86a48e 202
tony63 0:627d6e86a48e 203 int init_gprs(void){
tony63 0:627d6e86a48e 204
tony63 3:cd97b1ddaa23 205 if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 5)){
tony63 0:627d6e86a48e 206 return -1;
tony63 0:627d6e86a48e 207 }
tony63 3:cd97b1ddaa23 208 if (0 != sendCmdAndWaitForResp("ATE0\r\n", "OK", 5)){ //sin eco
tony63 0:627d6e86a48e 209 return -1;
tony63 0:627d6e86a48e 210 }
tony63 3:cd97b1ddaa23 211 if (0 != sendCmdAndWaitForResp("AT+CGATT=1\r\n", "OK", 5)){//inicia conexion GPRS
tony63 0:627d6e86a48e 212 return -1;
tony63 0:627d6e86a48e 213 }
tony63 3:cd97b1ddaa23 214 if (0 != sendCmdAndWaitForResp("AT+CSTT=internet.comcel.com.co,comcel,comcel\r\n", "OK", 5)){ //set apn
tony63 0:627d6e86a48e 215 return -1;
tony63 0:627d6e86a48e 216 }
tony63 3:cd97b1ddaa23 217 if (0 != sendCmdAndWaitForResp("AT+CIICR\r\n", "OK", 5)){ //habilitar conexion inalambrica
tony63 0:627d6e86a48e 218 return -1;
tony63 0:627d6e86a48e 219 }
tony63 0:627d6e86a48e 220
tony63 0:627d6e86a48e 221 cleanBuffer(gprsBuffer,25);
tony63 0:627d6e86a48e 222 sendCmd("AT+CIFSR\r\n"); //obtener direccion ip
tony63 0:627d6e86a48e 223 if(0 != ip_detect()){ //esperar la llegada de un direccion IP
tony63 0:627d6e86a48e 224 return -1;
tony63 0:627d6e86a48e 225 }
tony63 0:627d6e86a48e 226 wait(1);
tony63 1:3e0a9c577f09 227 LedVerde=0;//CONEXION OK... PRENDE LED VERDE..
tony63 0:627d6e86a48e 228 return 0;
tony63 0:627d6e86a48e 229 }
tony63 0:627d6e86a48e 230
tony63 1:3e0a9c577f09 231 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 1:3e0a9c577f09 232 //ESTA FUNCION DE ABAJO CIERRA UNA CONEXION GPRS
tony63 0:627d6e86a48e 233
tony63 0:627d6e86a48e 234 int end_gprs(void){
tony63 3:cd97b1ddaa23 235 if (0 != sendCmdAndWaitForResp("AT+CIPSHUT\r\n", "OK", 5)){
tony63 0:627d6e86a48e 236 return -1;
tony63 0:627d6e86a48e 237 }
tony63 3:cd97b1ddaa23 238 if (0 != sendCmdAndWaitForResp("AT+CGATT=0\r\n", "SHUT OK", 5)){
tony63 0:627d6e86a48e 239 return -1;
tony63 0:627d6e86a48e 240 }
tony63 0:627d6e86a48e 241 LedVerde=0;
tony63 0:627d6e86a48e 242 LedRojo=1;
tony63 0:627d6e86a48e 243 return 0;
tony63 0:627d6e86a48e 244 }
tony63 0:627d6e86a48e 245
tony63 0:627d6e86a48e 246 //++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 247 //interupcion perdida de energia
tony63 0:627d6e86a48e 248 //++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 249
tony63 0:627d6e86a48e 250 void off_gprs(){
tony63 0:627d6e86a48e 251 end_gprs();
tony63 0:627d6e86a48e 252 }
tony63 0:627d6e86a48e 253
tony63 0:627d6e86a48e 254 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 255 //inicio del programa principal
tony63 0:627d6e86a48e 256 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
tony63 0:627d6e86a48e 257 int main(){
tony63 1:3e0a9c577f09 258
tony63 1:3e0a9c577f09 259 loop1:g=gps.sample(); //GPS bien conectado???? de primero antes que todo!!!!
tony63 1:3e0a9c577f09 260 if(g){
tony63 1:3e0a9c577f09 261 LedAzul=0;//prende led azul GPS ok!!!
tony63 1:3e0a9c577f09 262 pc.printf("GPS--OK\n\r");
tony63 1:3e0a9c577f09 263 //si no hay GPS no intentar dada, ni conexion ni envio de datos y esperar el GPS
tony63 1:3e0a9c577f09 264 goto lop1;
tony63 1:3e0a9c577f09 265 }
tony63 1:3e0a9c577f09 266 goto loop1; //chequeo infinito de un GPS bien instalado...
tony63 0:627d6e86a48e 267 lop1:
tony63 3:cd97b1ddaa23 268 if(init_gprs()<0){
tony63 1:3e0a9c577f09 269 LedRojo=0;//PRENDE ROJO, APAGA VERDE
tony63 0:627d6e86a48e 270 LedVerde=1;
tony63 1:3e0a9c577f09 271 goto lop1;//NO SE PUEDE RECONECTAR INFINITAMENTE ESTE SALTO ES PROVISIONAL
tony63 1:3e0a9c577f09 272 //CONTAR LOS INTENTOS Y DAR SEÑAL DE ERROR PERMANENTE
tony63 0:627d6e86a48e 273 }
tony63 1:3e0a9c577f09 274 button.fall(&off_gprs);//perdida de alimentacion,apagaron carro ejecuta interupcion
tony63 2:f4483748eee0 275 //que desconecta la conexion GPRS
tony63 0:627d6e86a48e 276 while(1){ //si el GPS tiene conexion y datos se envian coordenadas a pagina web
tony63 3:cd97b1ddaa23 277 LedAzul=1; //APAGAMOS LED AZUL
tony63 3:cd97b1ddaa23 278 if(gps.sample()){ //UN GPS RESPONDE!
tony63 0:627d6e86a48e 279 LedAzul=0;
tony63 0:627d6e86a48e 280 lo = gps.longitude;
tony63 0:627d6e86a48e 281 la = gps.latitude;
tony63 0:627d6e86a48e 282 sprintf (lon, "%f", lo);//pasa de flotante a caracter
tony63 0:627d6e86a48e 283 sprintf (lat, "%f", la);//pasa de flotante a caracter
tony63 3:cd97b1ddaa23 284 cleanBuffer(gprsBuffer,10);
tony63 3:cd97b1ddaa23 285
tony63 3:cd97b1ddaa23 286 envio1:
tony63 3:cd97b1ddaa23 287 GSM.printf("AT+CIPSTART=\"TCP\",\"unrobotica.com\",\"80\"\r\n");
tony63 3:cd97b1ddaa23 288 //respuesta a este comando debe ser "CONNECT OK"
tony63 3:cd97b1ddaa23 289 wait(6);//espero un poquito a que conteste y luego leo el buffer
tony63 3:cd97b1ddaa23 290 if (GSM.readable()){
tony63 3:cd97b1ddaa23 291 readBuffer(gprsBuffer,20);
tony63 3:cd97b1ddaa23 292 pc.printf("%s\r\n",gprsBuffer);
tony63 3:cd97b1ddaa23 293 for(i=8;i<18;i++)
tony63 3:cd97b1ddaa23 294 {
tony63 3:cd97b1ddaa23 295 resp[i]=gprsBuffer[i];
tony63 3:cd97b1ddaa23 296 }
tony63 3:cd97b1ddaa23 297 if(strcmp("CONNECT OK",resp) == 0){
tony63 3:cd97b1ddaa23 298 goto envio2;
tony63 3:cd97b1ddaa23 299 }
tony63 3:cd97b1ddaa23 300 goto envio1; //no llego connect ok
tony63 3:cd97b1ddaa23 301 }
tony63 3:cd97b1ddaa23 302 goto envio1;//se repite comando 1. si no encontro respuesta
tony63 3:cd97b1ddaa23 303 envio2:
tony63 3:cd97b1ddaa23 304 if(0 = sendCmdAndWaitForResp("AT+CIPSEND\r\n","",5)){ //devuelve control+Z
tony63 3:cd97b1ddaa23 305 goto envio3;
tony63 3:cd97b1ddaa23 306 }
tony63 3:cd97b1ddaa23 307 goto envio2;//no llego control Z volver a enviar comando AT
tony63 3:cd97b1ddaa23 308 envio3:
tony63 3:cd97b1ddaa23 309 GSM.printf("GET /gpstracker/gps1.php?lat=%s&lon=%s HTTP/1.0\r\n",lat,lon);
tony63 0:627d6e86a48e 310 wait(3);
tony63 3:cd97b1ddaa23 311 envio4:
tony63 3:cd97b1ddaa23 312 GSM.printf("Host: unrobotica.com\n\n");
tony63 3:cd97b1ddaa23 313 wait(3);
tony63 3:cd97b1ddaa23 314 envio5:
tony63 3:cd97b1ddaa23 315 GSM.printf("\r\n");
tony63 3:cd97b1ddaa23 316 wait(3);
tony63 3:cd97b1ddaa23 317 envio6:
tony63 3:cd97b1ddaa23 318 GSM.printf("\n\r");
tony63 3:cd97b1ddaa23 319 wait(6);//espero un poquito a que conteste y luego leo el buffer
tony63 3:cd97b1ddaa23 320 if (GSM.readable()){
tony63 3:cd97b1ddaa23 321 readBuffer(gprsBuffer,12);
tony63 3:cd97b1ddaa23 322 pc.printf("%s\r\n",gprsBuffer);
tony63 3:cd97b1ddaa23 323 for(i=2;i<9;i++)
tony63 3:cd97b1ddaa23 324 {
tony63 3:cd97b1ddaa23 325 resp[i]=gprsBuffer[i]; //send ok
tony63 3:cd97b1ddaa23 326 }
tony63 3:cd97b1ddaa23 327 if(strcmp("SEND OK",resp) == 0){
tony63 3:cd97b1ddaa23 328 wait(50);
tony63 3:cd97b1ddaa23 329 goto envio2;//reenviar mas datos, todo salio bien
tony63 3:cd97b1ddaa23 330
tony63 3:cd97b1ddaa23 331 }
tony63 3:cd97b1ddaa23 332 if(end_gprs()=0){ //desconexion correcta reconectar de nuevo todo
tony63 3:cd97b1ddaa23 333 goto lop1;
tony63 3:cd97b1ddaa23 334 }
tony63 3:cd97b1ddaa23 335 goto lop1;
tony63 0:627d6e86a48e 336
tony63 3:cd97b1ddaa23 337
tony63 3:cd97b1ddaa23 338
tony63 3:cd97b1ddaa23 339
tony63 1:3e0a9c577f09 340
tony63 3:cd97b1ddaa23 341
tony63 3:cd97b1ddaa23 342
tony63 3:cd97b1ddaa23 343
tony63 3:cd97b1ddaa23 344 ................
tony63 1:3e0a9c577f09 345 if(0 !=sendCmdAndWaitForResp("\n\r","SEND OK",10))
tony63 1:3e0a9c577f09 346 {
tony63 1:3e0a9c577f09 347
tony63 1:3e0a9c577f09 348 }
tony63 1:3e0a9c577f09 349 //mas tarde devuelve SEND OK ...esto es suficiente para indicarnos que los datos se fueron a la nube
tony63 0:627d6e86a48e 350 //cleanBuffer(gprsBuffer,20);
tony63 0:627d6e86a48e 351 //leer bufer y encontrar respuesta exitosa devuelve "SEND OK"
tony63 3:cd97b1ddaa23 352 // GSM.printf("AT+CIPSTART=\"TCP\",\"unrobotica.com\",\"80\"\r\n");
tony63 3:cd97b1ddaa23 353 // pc.printf("AT+CIPSTART=\"TCP\",\"unrobotica.com\",\"80\"\r\n");
tony63 0:627d6e86a48e 354 //readBuffer(gprsBuffer,10);
tony63 0:627d6e86a48e 355 //if((NULL = strstr(gprsBuffer,""))){
tony63 0:627d6e86a48e 356 // wait(1);
tony63 0:627d6e86a48e 357 // goto repetir2;
tony63 0:627d6e86a48e 358 LedRojo=1;
tony63 0:627d6e86a48e 359 LedVerde=0; //envio OK
tony63 0:627d6e86a48e 360 }// del test del gps
tony63 0:627d6e86a48e 361 LedRojo=0; // hay problemas
tony63 0:627d6e86a48e 362 LedVerde=1;
tony63 0:627d6e86a48e 363
tony63 0:627d6e86a48e 364 }//del while col 13
tony63 0:627d6e86a48e 365
tony63 0:627d6e86a48e 366 }//del main col 11
tony63 0:627d6e86a48e 367
tony63 0:627d6e86a48e 368
tony63 0:627d6e86a48e 369
tony63 0:627d6e86a48e 370
tony63 0:627d6e86a48e 371