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.
Revision 3:cd97b1ddaa23, committed 2019-09-03
- Comitter:
- tony63
- Date:
- Tue Sep 03 08:00:18 2019 +0000
- Parent:
- 2:f4483748eee0
- Commit message:
- ok
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Aug 30 04:47:49 2019 +0000 +++ b/main.cpp Tue Sep 03 08:00:18 2019 +0000 @@ -2,9 +2,9 @@ PROGRAMA PARA HACER SEGUIMIENTO DE FLOTAS CON GPS Y CONEXION A LA RED GPRS se pueden simular trayectorias gravando archivos kml en google earth y usando SatGen -version 1.0, abril 2019 +version 2.0, sep 3 / 2019 -se asigna un APN segun el servicio GPRS de la SIMCARD +se asigna un APN segun el servicio GPRS de la SIMCARD (claro Colombia) se asigna un nombre de host de su pagina web se asigna el path de los archivos y mapas ejecutables en su servidor se asigna un ciclo de repeticion de lecturas de GPS. @@ -202,19 +202,19 @@ int init_gprs(void){ - if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){ + if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 5)){ return -1; } - if (0 != sendCmdAndWaitForResp("ATE0\r\n", "OK", 3)){ //sin eco + if (0 != sendCmdAndWaitForResp("ATE0\r\n", "OK", 5)){ //sin eco return -1; } - if (0 != sendCmdAndWaitForResp("AT+CGATT=1\r\n", "OK", 3)){//inicia conexion GPRS + if (0 != sendCmdAndWaitForResp("AT+CGATT=1\r\n", "OK", 5)){//inicia conexion GPRS return -1; } - if (0 != sendCmdAndWaitForResp("AT+CSTT=internet.comcel.com.co,comcel,comcel\r\n", "OK", 3)){ //set apn + if (0 != sendCmdAndWaitForResp("AT+CSTT=internet.comcel.com.co,comcel,comcel\r\n", "OK", 5)){ //set apn return -1; } - if (0 != sendCmdAndWaitForResp("AT+CIICR\r\n", "OK", 3)){ //habilitar conexion inalambrica + if (0 != sendCmdAndWaitForResp("AT+CIICR\r\n", "OK", 5)){ //habilitar conexion inalambrica return -1; } @@ -232,10 +232,10 @@ //ESTA FUNCION DE ABAJO CIERRA UNA CONEXION GPRS int end_gprs(void){ - if (0 != sendCmdAndWaitForResp("AT+CIPSHUT\r\n", "OK", 3)){ + if (0 != sendCmdAndWaitForResp("AT+CIPSHUT\r\n", "OK", 5)){ return -1; } - if (0 != sendCmdAndWaitForResp("AT+CGATT=0\r\n", "SHUT OK", 3)){ + if (0 != sendCmdAndWaitForResp("AT+CGATT=0\r\n", "SHUT OK", 5)){ return -1; } LedVerde=0; @@ -265,8 +265,7 @@ } goto loop1; //chequeo infinito de un GPS bien instalado... lop1: - - if(init_gprs()<0){ + if(init_gprs()<0){ LedRojo=0;//PRENDE ROJO, APAGA VERDE LedVerde=1; goto lop1;//NO SE PUEDE RECONECTAR INFINITAMENTE ESTE SALTO ES PROVISIONAL @@ -275,29 +274,74 @@ 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()){ + LedAzul=1; //APAGAMOS LED AZUL + if(gps.sample()){ //UN GPS RESPONDE! LedAzul=0; lo = gps.longitude; la = gps.latitude; sprintf (lon, "%f", lo);//pasa de flotante a caracter sprintf (lat, "%f", la);//pasa de flotante a caracter - repetir1:if (0 != sendCmdAndWaitForResp("AT+CIPSTART=TCP,unrobotica.com,80\r\n","OK", 3)){ + cleanBuffer(gprsBuffer,10); + + envio1: + GSM.printf("AT+CIPSTART=\"TCP\",\"unrobotica.com\",\"80\"\r\n"); + //respuesta a este comando debe ser "CONNECT OK" + wait(6);//espero un poquito a que conteste y luego leo el buffer + if (GSM.readable()){ + readBuffer(gprsBuffer,20); + pc.printf("%s\r\n",gprsBuffer); + for(i=8;i<18;i++) + { + resp[i]=gprsBuffer[i]; + } + if(strcmp("CONNECT OK",resp) == 0){ + goto envio2; + } + goto envio1; //no llego connect ok + } + goto envio1;//se repite comando 1. si no encontro respuesta + envio2: + if(0 = sendCmdAndWaitForResp("AT+CIPSEND\r\n","",5)){ //devuelve control+Z + goto envio3; + } + goto envio2;//no llego control Z volver a enviar comando AT + envio3: + GSM.printf("GET /gpstracker/gps1.php?lat=%s&lon=%s HTTP/1.0\r\n",lat,lon); wait(3); - LedVerde=1; - LedRojo=0; - goto repetir1;//salto provisional debe contar intentos y no hacer nada ya que es imposible conectarse - } + envio4: + GSM.printf("Host: unrobotica.com\n\n"); + wait(3); + envio5: + GSM.printf("\r\n"); + wait(3); + envio6: + GSM.printf("\n\r"); + wait(6);//espero un poquito a que conteste y luego leo el buffer + if (GSM.readable()){ + readBuffer(gprsBuffer,12); + pc.printf("%s\r\n",gprsBuffer); + for(i=2;i<9;i++) + { + resp[i]=gprsBuffer[i]; //send ok + } + if(strcmp("SEND OK",resp) == 0){ + wait(50); + goto envio2;//reenviar mas datos, todo salio bien + + } + if(end_gprs()=0){ //desconexion correcta reconectar de nuevo todo + goto lop1; + } + goto lop1; - repetir2:cleanBuffer(gprsBuffer,10); - if(0 !=sendCmdAndWaitForResp("AT+CIPSEND\r\n","",3)){ //devuelve control+Z - wait(1); - goto repetir2;//salto provisional debe contar intentos y no hacer nada ya que es imposible conectarse - } + + + - 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"); + + + + ................ if(0 !=sendCmdAndWaitForResp("\n\r","SEND OK",10)) { @@ -305,7 +349,8 @@ //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" - + // GSM.printf("AT+CIPSTART=\"TCP\",\"unrobotica.com\",\"80\"\r\n"); + // pc.printf("AT+CIPSTART=\"TCP\",\"unrobotica.com\",\"80\"\r\n"); //readBuffer(gprsBuffer,10); //if((NULL = strstr(gprsBuffer,""))){ // wait(1);