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.
Diff: main.cpp
- Revision:
- 1:3e0a9c577f09
- Parent:
- 0:627d6e86a48e
- Child:
- 2:f4483748eee0
--- a/main.cpp Fri Apr 12 05:58:48 2019 +0000 +++ b/main.cpp Thu Aug 29 07:37:07 2019 +0000 @@ -34,6 +34,7 @@ int z=0; int i=0; int count=0; +int g=0; //----------------------------------------------------------------------------------------------------------------------------- // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de @@ -182,14 +183,14 @@ z++; } } - if(z==3){ + if(z==3){ //CUENTO TRES PUNTOS LO MAS PROBABLE ES QUE SEA UNA DIRECCION ip pc.printf("llego ip=%d\r\n",z); z=0; - return 0; + return 0; //RETORNA CON CERO SI LLEGARON TRES PUNTOS } }//fin check GSM modem z=0; - return -1; + return -1; //NO LLEGARON 3 PUNTOS RETORNA CON -1 }//fin funcion //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -223,11 +224,12 @@ return -1; } wait(1); - LedVerde=0; + LedVerde=0;//CONEXION OK... PRENDE LED VERDE.. return 0; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//ESTA FUNCION DE ABAJO CIERRA UNA CONEXION GPRS int end_gprs(void){ if (0 != sendCmdAndWaitForResp("AT+CIPSHUT\r\n", "OK", 3)){ @@ -253,14 +255,25 @@ //inicio del programa principal //+++++++++++++++++++++++++++++++++++++++++++++++++++++ int main(){ - + +loop1:g=gps.sample(); //GPS bien conectado???? de primero antes que todo!!!! + if(g){ + LedAzul=0;//prende led azul GPS ok!!! + pc.printf("GPS--OK\n\r"); + //si no hay GPS no intentar dada, ni conexion ni envio de datos y esperar el GPS + goto lop1; + } + goto loop1; //chequeo infinito de un GPS bien instalado... lop1: + if(init_gprs()<0){ - LedRojo=0; + LedRojo=0;//PRENDE ROJO, APAGA VERDE LedVerde=1; - goto lop1; + goto lop1;//NO SE PUEDE RECONECTAR INFINITAMENTE ESTE SALTO ES PROVISIONAL + //CONTAR LOS INTENTOS Y DAR SEÑAL DE ERROR PERMANENTE } - button.fall(&off_gprs);//perdida de alimentacion,apagaron carro + button.fall(&off_gprs);//perdida de alimentacion,apagaron carro ejecuta interupcion + que desconecta la conexion GPRS while(1){ //si el GPS tiene conexion y datos se envian coordenadas a pagina web LedAzul=1; if(gps.sample()){ @@ -273,24 +286,23 @@ wait(3); LedVerde=1; LedRojo=0; - goto repetir1; + goto repetir1;//salto provisional debe contar intentos y no hacer nada ya que es imposible conectarse } repetir2:cleanBuffer(gprsBuffer,10); - //sendCmd("AT+CIPSEND\r\n"); - if(0 !=sendCmdAndWaitForResp("AT+CIPSEND\r\n","",3)){ + if(0 !=sendCmdAndWaitForResp("AT+CIPSEND\r\n","",3)){ //devuelve control+Z wait(1); - goto repetir2; + goto repetir2;//salto provisional debe contar intentos y no hacer nada ya que es imposible conectarse } - //aca el servidor contesta con contol+z y hay que verificar eso. - //readBuffer(gprsBuffer,10); - //if((NULL = strstr(gprsBuffer,""))){ - // wait(1); - // goto repetir2; + GSM.printf("GET /gpstracker/gps1.php?lat=%s&lon=%s HTTP/1.0\r\n",lat,lon); GSM.printf("Host: unrobotica.com\n\n"); GSM.printf("\r\n"); - GSM.printf("\n\r"); + if(0 !=sendCmdAndWaitForResp("\n\r","SEND OK",10)) + { + + } + //mas tarde devuelve SEND OK ...esto es suficiente para indicarnos que los datos se fueron a la nube //cleanBuffer(gprsBuffer,20); //leer bufer y encontrar respuesta exitosa devuelve "SEND OK"