Libelium is offering new technical support channels, to contact with de Technical Support team to solve any issue our doubt please contact with your sales agent or visit our contact site



Post a new topicPost a reply Page 1 of 1   [ 2 posts ]
Author Message
 Post subject: Código A-GPS
PostPosted: Tue Apr 05, 2016 9:33 am 

Joined: Tue Apr 05, 2016 9:25 am
Posts: 1
Buenos días,

En el apartado GPS de la siguiente página https://www.cooking-hacks.com/documentation/tutorials/3g-gps-shield-arduino-raspberry-pi-tutorial/#step9 veo que falta el código del modo A-GPS, pone "Here is the example code" pero solo aparece una tabla. ¿Podrías añadirlo?.

Muchas gracias.


Top
 Profile  
 
 Post subject: Re: Código A-GPS
PostPosted: Wed Apr 06, 2016 7:50 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hola Drabor,

Aquí lo tienes:

Code:
/*
 *  Description: This example shows how to use the MS-assited GPS
 *  This example shows the AT commands (and the answers of the module) used
 *  to work with the MS-assited GPS. For more information about the AT commands,
 *  refer to the AT command manual.
 *
 *  Copyright (C) 2013 Libelium Comunicaciones Distribuidas S.L.
 *  http://www.libelium.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Version 0.2
 *  Author: Alejandro Gallego
 */


int8_t answer;
int onModulePin= 2;
char gps_data[100];
int counter;

void setup(){

    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);   
   
    Serial.println("Starting...");
    power_on();
   
    delay(5000);
   
    Serial.println("Connecting to the network...");

    while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

    sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"apn\"","OK",1000);
    // if not authentication requiered comment or remove the next line
    sendATcommand("AT+CSOCKAUTH=1,1,,\"username\",\"password\"","OK",1000);
    sendATcommand("AT+CGPSURL=\"supl.google.com:7276\"","OK",1000);    // sets GPS server
    sendATcommand("AT+CGPSSSL=0","OK",1000);    // without certificate
   
   
}
void loop(){
   
    answer = sendATcommand("AT+CGPS=1,3","OK",1000);    // starts GPS session in assisted mode
    if (answer == 1)
    {
        answer = sendATcommand("","+CAGPSINFO:",30000);
        if (answer == 1)
        {
            counter = 0;
            do{
                while(Serial.available() == 0);
                gps_data[counter] = Serial.read();
                counter++;
            }while(gps_data[counter - 1] != '\r');
            gps_data[counter] = '\0';
            Serial.print("GPS data: ");
            Serial.println(gps_data); 
            Serial.println("");       
        }
        else
        {
            Serial.println("Error");
        }
    }
    else
    {
        Serial.println("Error");
    }
   
    delay(5000);
}

void power_on(){

    uint8_t answer=0;

    // checks if the module is started
    answer = sendATcommand("AT", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);

        // waits for an answer from the module
        while(answer == 0){   
            // Send AT every two seconds and wait for the answer
            answer = sendATcommand("AT", "OK", 2000);   
        }
    }

}


int8_t sendATcommand(char* ATcommand, char* expected_answer1,
unsigned int timeout)
{

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string

    delay(100);

    while( Serial.available() > 0) Serial.read();    // Clean the input buffer

    Serial.println(ATcommand);    // Send the AT command


        x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial.available() != 0){   
            response[x] = Serial.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer1) != NULL)   
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }
    while((answer == 0) && ((millis() - previous) < timeout));   

    return answer;
}



Un saludo


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 2 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.