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   [ 5 posts ]
Author Message
 Post subject: GPS+GPRS Tracker Not Parsing correctly
PostPosted: Mon Aug 07, 2017 4:20 pm 

Joined: Wed Jul 26, 2017 5:40 pm
Posts: 9
Hello libelium

I think I have found the same issue.
I set your GPS GPRS SIM908 module on an Arduino board, and tried your interesting

"Geolocation Tracker (GPRS + GPS) with SIM908 over Arduino and Raspberry Pi"

I uploaded the same code you show in your web, and I agree the function "convert2Degrees" has something wrong.
The function converts degrees properly, but something is happening to the minutes. Although the AT+CGPSINF=0 command is returning different lat and long coordinates (you can see small differences in the fractionary part of the minutes, the convert2Degrees function returns always the same values.

I added some verbose code to check what is happening and this is part of the result in the serial monitor:

AT+CGPSSTATUS?
AT+CREG?
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","telefonica"
AT+SAPBR=3,1,"USER","telefonica"
AT+SAPBR=3,1,"PWD","telefonica"
AT+SAPBR=1,1
AT+CGPSINF=0
0,-151.774046,3859.462586,0.785839,20170807095113.000,75,3,0.000000,0.000000


NMEA latitude: 3859.462586
NMEA longitude: -151.774046
converted latitude: 38.983333
converted longitude: -1.850000

AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://pruebas.libelium.com/demo_sim908.php?visor=false&latitude=38.983333&longitude=-1.850000&altitude=0&time=20170807095113&satellites=3&speedOTG=0.000000&course=0.000000"
AT+HTTPACTION=0
Done!
AT+HTTPTERM
AT+CGPSINF=0
0,-151.773289,3859.463373,0.837512,20170807095120.000,75,3,0.339872,48.279934


NMEA latitude: 3859.463373
NMEA longitude: -151.773289
converted latitude: 38.983333
converted longitude: -1.850000

AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://pruebas.libelium.com/demo_sim908.php?visor=false&latitude=38.983333&longitude=-1.850000&altitude=0&time=20170807095120&satellites=3&speedOTG=0.339872&course=48.279934"
AT+HTTPACTION=0
Done!
AT+HTTPTERM
AT+CGPSINF=0
0,-151.772129,3859.464536,2.457430,20170807095127.000,75,3,0.328714,45.627087


NMEA latitude: 3859.464536
NMEA longitude: -151.772129
converted latitude: 38.983333
converted longitude: -1.850000

AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://pruebas.libelium.com/demo_sim908.php?visor=false&latitude=38.983333&longitude=-1.850000&altitude=2&time=20170807095127&satellites=3&speedOTG=0.328714&course=45.627087"
AT+HTTPACTION=0
Done!
AT+HTTPTERM
AT+CGPSINF=0
0,-151.770723,3859.465417,3.786609,20170807095134.000,75,3,0.315327,48.411182


NMEA latitude: 3859.465417
NMEA longitude: -151.770723
converted latitude: 38.983333
converted longitude: -1.850000

AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://pruebas.libelium.com/demo_sim908.php?visor=false&latitude=38.983333&longitude=-1.850000&altitude=3&time=20170807095134&satellites=3&speedOTG=0.315327&course=48.411182"
AT+HTTPACTION=0
Done!
AT+HTTPTERM

Can you please help us?

thank you in advance
regards


Top
 Profile  
 
 Post subject: Re: GPS+GPRS Tracker Not Parsing correctly
PostPosted: Tue Aug 08, 2017 7:16 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hello newbie,

Our engineer specializing in that matter is on holidays. We will answer you as soon as possible. Thanks for your understanding.

Regards


Top
 Profile  
 
 Post subject: Re: GPS+GPRS Tracker Not Parsing correctly
PostPosted: Mon Aug 21, 2017 7:24 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi newbie,

We developed this code. It solves some issues with the convert2degrees function. Can you try it?

Code:
/*
 *  GPRS+GPS Quadband Module (SIM908)
 *
 *  Copyright (C) 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.
 *  a
 *  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:           3.0
 *  Design:            David Gascón
 *  Implementation:    Jorge Casanova & Ruben Martín
 */
 
 
int8_t answer;
int onModulePin= 2;
int counter;
long previous;

char Basic_str[100];

char latitude[15];
char longitude[15];

char aux;

char EW_indicator; //EW_indicator  //From basic, GGA, GLL and RMC
char NS_indicator; //NS_indicator  //From basic, GGA, GLL and RMC
char latitudeNS;       //NS_indicator
char longitudeEW;      //EW_indicator

int x = 0;

void setup(){
   
    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);   
   
    Serial.println("Starting...");
    power_on();
   
    delay(3000);
   
    sendATcommand("AT+CGPSPWR=1", "OK", 2000);
    sendATcommand("AT+CGPSRST=0", "OK", 2000);
   
   
    // waits for fix GPS
    while( (sendATcommand("AT+CGPSSTATUS?", "2D Fix", 5000) ||
            sendATcommand("AT+CGPSSTATUS?", "3D Fix", 5000)) == 0 );
   

}

void loop(){
    // Basic
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();   
    delay(100);
    // request Basic string
    sendATcommand("AT+CGPSINF=0", "AT+CGPSINF=0\r\n\r\n", 2000);
   
    counter = 0;
    answer = 0;
    memset(Basic_str, '\0', 100);    // Initialize the string
    previous = millis();
    // this loop waits for the NMEA string
    do{

        if(Serial.available() != 0){   
            Basic_str[counter] = Serial.read();
            counter++;
            // check if the desired answer is in the response of the module
            if (strstr(Basic_str, "OK") != NULL)   
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < 2000));
   
    Basic_str[counter-3] = '\0';
   
   
   //**********************************************************
    Serial.println("*************************************************");
    Serial.print("Basic string: ");
    Serial.println(Basic_str);
    Serial.print(" ");
   
   // Parses the string
    strtok(Basic_str, ",");
        strcpy(longitude,strtok(NULL, ",")); // Gets longitude
        strcpy(latitude,strtok(NULL, ",")); // Gets latitude
           
        aux = (strchr(longitude, '.') - longitude) - 5;
        EW_indicator = 'E';
        if (longitude[0] == '-')
        {
          longitude[0] = '0';
          EW_indicator = 'W';
        }

        if(aux > 0)
        {
          do{
            for(int8_t x = 1; x < 14; x++)
            {
              longitude[x-1] = longitude[x];
            }
            longitude[13] = '0';
            longitude[14] = '\0';
            aux--;
          }while(aux > 0);
        }
        else if(aux < 0)
        {
          do{
            for(int8_t x = 13; x >= 0; x--)
            {
              longitude[x+1] = longitude[x];
            }
            longitude[0] = '0';
            longitude[14] = '\0';
            aux++;
          }while(aux < 0);
        }
       
        if (EW_indicator == 'W')
        {
          longitude[0] = '-';
        }       
       
        NS_indicator = 'N';
        aux = (strchr(latitude, '.') - latitude) - 4;
        if (latitude[0] == '-')
        {
          latitude[0] = '0';
          NS_indicator = 'S';
        }

        if(aux > 0)
        {
          do{
            for(x = 1; x < 13; x++)
            {
              latitude[x-1] = latitude[x];
            }
            latitude[12] = '0';
            latitude[13] = '\0';
            aux--;
          }while(aux > 0);
        }
        else if(aux < 0)
        {
          do{
            for(x = 12; x >= 0; x--)
            {
              latitude[x+1] = latitude[x];
            }
            latitude[0] = '0';
            latitude[13] = '\0';
            aux++;
          }while(aux < 0);
        }

        if (NS_indicator == 'S')
        {
          latitude[0] = '-';
        }

    //**********************************************************   

    Serial.println("Original:");       
    Serial.println(latitude);
    Serial.println(longitude);
    Serial.print(" ");
   
    convert2Degrees(latitude, NS_indicator);
    convert2Degrees(longitude, EW_indicator);

    Serial.println("Converted:");
    Serial.println(convert2Degrees(latitude, NS_indicator), 6);
    Serial.println(convert2Degrees(longitude, EW_indicator), 6);
    Serial.print(" ");
   
    delay(10000);

}

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);
   
    // Clean the input buffer
    while( Serial.available() > 0) Serial.read();   
   
    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;
}
    /* convert2Degrees ( input ) - performs the conversion from input
 * parameters in  DD°MM.mmm’ notation to DD.dddddd° notation.
 *
 * Sign '+' is set for positive latitudes/longitudes (North, East)
 * Sign '-' is set for negative latitudes/longitudes (South, West)
 *
 */
float convert2Degrees(char* input, char indicator){

   // final latitude expresed in degrees
    float deg;
    float minutes;
   
    //auxiliar variable
    char aux[10] ="";
   
    // check if 'indicator' is a valid input
    if ((indicator != 'N') &&
        (indicator != 'S') &&
        (indicator != 'E') &&
        (indicator != 'W'))
    {
        // invalid indicator
        return 0;
    }   
   
    // get 'degrees' from input parameter
    if ((indicator == 'N') || (indicator == 'S'))
    {
        //latitude format: DDmm.mmmm'
        aux[0] = input[0];
        aux[1] = input[1];
        aux[2] = '\0';
    }
    else if ((indicator == 'E') || (indicator == 'W'))
    {
        //longitude format: DDDmm.mmmm'
        aux[0]=input[0];
        aux[1]=input[1];
        aux[2]=input[2];
        aux[3]='\0';
    }
   
    // convert string to integer and add it to final float variable
    deg = atoi(aux);
   
    // get 'minutes' from input parameter
    if ((indicator == 'N') || (indicator == 'S'))
    {
        //latitude format: DDmm.mmmm'
        for ( int i=0; i<7; i++ )
        {
            aux[i] = input[i+2];
        }
        aux[7] = '\0';
    }
    else if ((indicator == 'E') || (indicator == 'W'))
    {
        // longitude format: DDDmm.mmmm'
        for ( int i = 0; i < 7; i++ )
        {
            aux[i] = input[i+3];
        }
        aux[7] = '\0';
    }   
   
    // convert string to integer and add it to final float variable
    minutes = atof(aux);
   
    // add minutes to degrees
    deg = deg+minutes/60;
   
    // add sign: '+' for North/East; '-' for South/West
    if ((indicator == 'S') || (indicator == 'W'))
    {
        deg *= -1.0;
    }
   
    return deg;
}


regards


Top
 Profile  
 
 Post subject: Re: GPS+GPRS Tracker Not Parsing correctly
PostPosted: Mon Aug 28, 2017 10:19 am 

Joined: Wed Jul 26, 2017 5:40 pm
Posts: 9
Hello libelium

Tested!. Thank you !!

regards


Top
 Profile  
 
 Post subject: Re: GPS+GPRS Tracker Not Parsing correctly
PostPosted: Tue Aug 29, 2017 7:10 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi newbie,

Nice to read it!

Good luck with your project :)

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 5 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.