Go Down

Topic: How to convert coordinates from AT+CGPSINFO returned value to redable format. (Read 195 times) previous topic - next topic

nayank9

Hi Guys,

I am using SIM7600 Module, after executing "AT+CGPSINFO" this command getting location in following format, Also I have included TinyGPS++ library & used "gps.encode" function to convert coordinates of lat long but that function is not working.

AT+CGPSINFO; 1831.991044,N,07352.807453,E,141008,112307.0,553.9,0.0,113


Anyone knows how I can convert coordinates into actual lat long.

Thanks!

srnet

What format are the co-ordinates in ?

You presumably know where you are in the World (we dont) so how closely do the numbers;

1831.991044,N,07352.807453,E

represent your actual latitude and longitude ?

Oh, and its likley the co-ordinates are already 'actual lat long' but represented in one of the several formats used.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

nayank9

Hi, thanks for your reply. Latitude & longitude is getting you can see in the response which I posted but that format is different, degrees & minutes parameter is also included in the latitude & longitude, I want to remove those parameters (degrees & minute value) is there any available function?

srnet

Dont know if there is a direct function and TinyGPS++ is expecting as full GPS NMEA style sentence.


What was the anwer to the question  I asked, you did not reply ?
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

nayank9

+CGPSINFO: [<lat>],[<N/S>],[<log>],[<E/W>],[<date>],[<UTC time>],[<alt>],[<speed>],[<course>]
+CGPSINFO:1831.991202,N,073.8801252,E,250311,072809.3,44.1,0.0,0


What format are the co-ordinates in ?

Answer: ddmm.mmmmmm

Example (Lat : 1831.991202, Long: 07352.807509)


represent your actual latitude and longitude ?

Answer: dd.dddddd

Example:    18.5331867, 073.8801252

srnet

Its is the standard GPS NMEA format, I dont myself know of a ready made function to convert that, most GPS libraries will likley throw it out, they expect a full GPS NMEA sentence with checksum on the end.

However given that the format is;

DDMM.MMMMMMMM if you extract that from the buffer as a number then some sums will allow you to convert it in decimal degrees for instance.

Its effectivly the degrees digits then the minutes as a decimal, 0 to 59.99999999.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

jremington

I wrote this function to convert a GPS latitude or longitude character string to degrees x 10^6, since with Arduino, 32 bit float variables cannot be used to store GPS coordinates accurately.

Code: [Select]
//
// decode individual NMEA lat/lon character strings in format DDDMM.MMMMM
// result is returned as long integer as degrees*10^6
// p is pointer to character string to be converted.
//
long parse_degrees(char* p) {
    char* minutes;
    char deg[]={0,0,0,0};  //up to 3 digits character  string for integer degrees
    double x;
    long d;

    if (strlen(p) == 0) return 0L;  //invalid input string
 
    if ((minutes = strchr(p,'.')) == NULL) return 0L;  //'.' not found, invalid

    minutes -= 2; //back up pointer to include two digits of minutes+decimal fraction
    x = strtod(minutes,NULL); //make into double
    memcpy(deg,p,minutes-p); //copy degrees, works OK with zero length string
    d = strtol(deg,NULL,10)*1000000UL;  //degrees to long int
    d += (long)(x*16666.667 + 0.5); //*1.e6/60.  add in minutes

    return d;
}

srnet

I wrote this function to convert a GPS latitude or longitude character string to degrees x 10^6, since with Arduino, 32 bit float variables cannot be used to store GPS coordinates accurately.

Code: [Select]
//
// decode individual NMEA lat/lon character strings in format DDDMM.MMMMM
// result is returned as long integer as degrees*10^6
// p is pointer to character string to be converted.
//
long parse_degrees(char* p) {
    char* minutes;
    char deg[]={0,0,0,0};
    double x;
    long d;

if (strlen(p) == 0) return 0L;  //invalid input string

    if ((minutes = strchr(p,'.')) == NULL) return 0L;  //'.' not found, invalid
    minutes -= 2; //back up pointer to include two digits of minutes+decimal fraction
    x = strtod(minutes,NULL); //make into double
    memcpy(deg,p,minutes-p); //copy degrees, works OK with zero length string
    d = strtol(deg,NULL,10)*1000000UL;  //degrees to long int
    d += (long)(x*16666.667 + 0.5); //*1.e6/60.  add in minutes

    return d;
}

Thanks, that could be useful in the future.

 
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

Go Up