Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"getGPS()" does not return actual GPS coordinates. #13

Open
TheForeignMan opened this issue Feb 18, 2018 · 9 comments
Open

"getGPS()" does not return actual GPS coordinates. #13

TheForeignMan opened this issue Feb 18, 2018 · 9 comments

Comments

@TheForeignMan
Copy link

Hi,

This is a great library which has quickened my development with the SIM808 module. Many thanks for this!

Just as a heads-up, the "getGPS()" function doesn't actually return the GPS coordinates. The function simply divides the return N/S and E/W coordinates by 100 (DFRobot_sim808.cpp:1059 and DFRobot_sim808.cpp:1062) as below:

GPSdata.lat = latitude/100;

// convert longitude from minutes to decimal  
GPSdata.lon= longitude/100;

The above returns really inaccurate coordinates, and does not take into account N/S and E/W (positive and negative) coordinates. I have implemented a more accurate conversion, which converts the GPRMC message to actual coordinates. Please freely replace the code above with the code below (or simplify it!) :

int a, b;
float lat, lon;
float latitude = atof(latp);
float longitude = atof(longp);

// convert latitude from minutes to decimal 
a = latitude / 100;
lat = ((latitude / 100) - a) * 100;
lat /= 60;
lat += a;
if(*latdir == 'S') lat *= -1;
GPSdata.lat = lat;

// convert longitude from minutes to decimal  
b = longitude / 100;
lon = ((longitude / 100) - b) * 100;
lon /= 60;
lon += b;
if(*longdir == 'W') lon *= -1;
GPSdata.lon= lon;

Hope this helps!

@ikihi
Copy link

ikihi commented Nov 29, 2018

Hi Foreign man

Yes I have now a big issue with that problem.

My code is a bit different that what you describe, I’m attaching it..

But, will you help me telling me were your code goes?

I mean Void setup, void loop, before that?...

I’m not very professional yet at this

thank you in advance

My e-mail in case is easyer is [email protected]

GPS Tracking.txt

@harry1227
Copy link

i am also getting wrong position. what should i do ?

@ikihi
Copy link

ikihi commented Mar 22, 2019 via email

@harry1227
Copy link

Any one know how to send sms to multiple numbers

@harry1227
Copy link

Hi.... It turns out that what was wrong it was the dfrobot library download Uninstall from arduino ide Download it again from github and reinstall All the troubles went away... Something goes wrong when download that library (i have no idea what!!.. as it shows right data download, installs and all).. but that was my problem Now working perfectly Hope it helps Cheers!! El 22 mar 2019, a la(s) 3:22 a. m., harry1227 <[email protected]mailto:[email protected]> escribió: i am also getting wrong position. what should i do ? — You are receiving this because you commented. Reply to this email directly, view it on GitHub<#13 (comment)>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Aqr7IvL5R1vKkPaYwRdR7u6Qs8U530CZks5vZKDRgaJpZM4SJoxq.

hey can u help me to send the location to server using sim808 i have tried its not working
here is my code

#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

#define PIN_TX 7
#define PIN_RX 8
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

//make sure that the baud rate of SIM900 is 9600!
//you can use the AT Command(AT+IPR=9600) to set it through SerialDebug

//DFRobot_SIM808 sim808(&Serial);

char buffer[512];

void setup(){
mySerial.begin(9600);
Serial.begin(9600);

//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
delay(3000);

//*********** Attempt DHCP *******************
while(!sim808.join(F("SIM3g"))) {
Serial.println("Sim808 join network error");
delay(2000);
}

//************ Successful DHCP ****************
Serial.print("IP Address is ");
Serial.println(sim808.getIPAddress());

//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");
delay(2000);
}

void loop(){

tcp();
delay(2000);
}

void tcp()
{
// Update the GPS data
float lati, longi;
if (sim808.getGPS()) {
lati = sim808.GPSdata.lat;
longi = sim808.GPSdata.lon;
sim808.detachGPS();
}
else {
// No gps, abort
return;
}

//*********** Establish a TCP connection ************

if (!sim808.connect(TCP,"localhost", 80)) {
   Serial.println("Connect error");
   return;
}
else {
   Serial.println("Connect success");
}

//*********** Send a GET request *****************

char http_cmd[100];
sprintf(http_cmd, "GET /http://localhost/GPSEA/server.php?latitude=%f&longitude=%f HTTP/1.0\r\n\r\n\0", lati, longi);
sim808.send(http_cmd, strlen(http_cmd));

/*
int ret = sim808.recv(buffer, sizeof(buffer) - 1);
if (ret <= 0){
    Serial.println("error receiving");
}
else {
    buffer[ret] = '\0';
    Serial.print(buffer);
}
*/

php code

please help if u can
thanks in advanced

@acu18ar
Copy link

acu18ar commented Aug 5, 2020

la libreria, esta mal, ya probe en base a comandos AT y me muestra las coordenadas correctas pero con puro comandos AT...

@cuzcatleco
Copy link

Hi,

This is a great library which has quickened my development with the SIM808 module. Many thanks for this!

Just as a heads-up, the "getGPS()" function doesn't actually return the GPS coordinates. The function simply divides the return N/S and E/W coordinates by 100 (DFRobot_sim808.cpp:1059 and DFRobot_sim808.cpp:1062) as below:

GPSdata.lat = latitude/100;

// convert longitude from minutes to decimal  
GPSdata.lon= longitude/100;

The above returns really inaccurate coordinates, and does not take into account N/S and E/W (positive and negative) coordinates. I have implemented a more accurate conversion, which converts the GPRMC message to actual coordinates. Please freely replace the code above with the code below (or simplify it!) :

int a, b;
float lat, lon;
float latitude = atof(latp);
float longitude = atof(longp);

// convert latitude from minutes to decimal 
a = latitude / 100;
lat = ((latitude / 100) - a) * 100;
lat /= 60;
lat += a;
if(*latdir == 'S') lat *= -1;
GPSdata.lat = lat;

// convert longitude from minutes to decimal  
b = longitude / 100;
lon = ((longitude / 100) - b) * 100;
lon /= 60;
lon += b;
if(*longdir == 'W') lon *= -1;
GPSdata.lon= lon;

Hope this helps!

It works ! Thanks a lot!

@cuzcatleco
Copy link

Hi Foreign man

Yes I have now a big issue with that problem.

My code is a bit different that what you describe, I’m attaching it..

But, will you help me telling me were your code goes?

I mean Void setup, void loop, before that?...

I’m not very professional yet at this

thank you in advance

My e-mail in case is easyer is [email protected]

GPS Tracking.txt

You need to put this new peace of code in the library .cpp

@vitalbthmugisho
Copy link

Hi,

This is a great library which has quickened my development with the SIM808 module. Many thanks for this!

Just as a heads-up, the "getGPS()" function doesn't actually return the GPS coordinates. The function simply divides the return N/S and E/W coordinates by 100 (DFRobot_sim808.cpp:1059 and DFRobot_sim808.cpp:1062) as below:

GPSdata.lat = latitude/100;

// convert longitude from minutes to decimal  
GPSdata.lon= longitude/100;

The above returns really inaccurate coordinates, and does not take into account N/S and E/W (positive and negative) coordinates. I have implemented a more accurate conversion, which converts the GPRMC message to actual coordinates. Please freely replace the code above with the code below (or simplify it!) :

int a, b;
float lat, lon;
float latitude = atof(latp);
float longitude = atof(longp);

// convert latitude from minutes to decimal 
a = latitude / 100;
lat = ((latitude / 100) - a) * 100;
lat /= 60;
lat += a;
if(*latdir == 'S') lat *= -1;
GPSdata.lat = lat;

// convert longitude from minutes to decimal  
b = longitude / 100;
lon = ((longitude / 100) - b) * 100;
lon /= 60;
lon += b;
if(*longdir == 'W') lon *= -1;
GPSdata.lon= lon;

Hope this helps!

Thanks @TheForeignMan . It was very Helpfull!!!
I've the same problem before seeing your post. To fix it i just edited my getGPS() function in the DFRobot_SIM808.cpp file by adding this 👇 at the end before the last return. If someone else got this problem, can fix it too by adding this code:

if(*latdir == 'S') GPSdata.lat *= -1;
if(*longdir == 'W') GPSdata.lon *= -1;

Or can just copy this function 👇 and replace the DFRobot_SIM808::getGPS() function in the DFRobot_SIM808.cpp file

        
bool DFRobot_SIM808::getGPS() 
{
	 if(!getGPRMC())    //没有得到$GPRMC字符串开头的GPS信息
		 return false;
	// Serial.println(receivedStack);
	 if(!parseGPRMC(receivedStack))  //不是$GPRMC字符串开头的GPS信息
		 return false;  
		
	// skip mode
    char *tok = strtok(receivedStack, ",");     //起始引导符
    if (! tok) return false;

   // grab time                                  //<1> UTC时间,格式为hhmmss.sss;
   // tok = strtok(NULL, ",");
	char *time = strtok(NULL, ",");
    if (! time) return false;
	uint32_t newTime = (uint32_t)parseDecimal(time);
	getTime(newTime);

    // skip fix
    tok = strtok(NULL, ",");              //<2> 定位状态,A=有效定位,V=无效定位
    if (! tok) return false;

    // grab the latitude
    char *latp = strtok(NULL, ",");       //<3> 纬度ddmm.mmmm(度分)格式(前面的0也将被传输)
    if (! latp) return false;

    // grab latitude direction              // <4> 纬度半球N(北半球)或S(南半球)
    char *latdir = strtok(NULL, ",");
    if (! latdir) return false;

    // grab longitude                       //<5> 经度dddmm.mmmm(度分)格式(前面的0也将被传输)
    char *longp = strtok(NULL, ",");
    if (! longp) return false;

    // grab longitude direction            //<6> 经度半球E(东经)或W(西经)
    char *longdir = strtok(NULL, ",");
    if (! longdir) return false;

    float latitude = atof(latp);
    float longitude = atof(longp);

    // convert latitude from minutes to decimal
	GPSdata.lat = (int)(latitude / 100) + (latitude - (int)(latitude / 100) * 100) / 60;
	if(*latdir == 'S') GPSdata.lat *= -1;
	
    // convert longitude from minutes to decimal
	GPSdata.lon = (int)(longitude / 100) + (longitude - (int)(longitude / 100) * 100) / 60;
	if(*longdir == 'W') GPSdata.lon *= -1;
  
    // only grab speed if needed                  //<7> 地面速率(000.0~999.9节,前面的0也将被传输)
   // if (speed_kph != NULL) {

      // grab the speed in knots
      char *speedp = strtok(NULL, ",");
      if (! speedp) return false;

      // convert to kph
      //*speed_kph = atof(speedp) * 1.852;
	  GPSdata.speed_kph= atof(speedp) * 1.852;

   // }

    // only grab heading if needed
   // if (heading != NULL) {

      // grab the speed in knots
      char *coursep = strtok(NULL, ",");
      if (! coursep) return false;

      //*heading = atof(coursep);
		GPSdata.heading = atof(coursep);
   // }
	
	// grab date
	char *date = strtok(NULL, ",");
    if (! date) return false;
	uint32_t newDate = atol(date);
	getDate(newDate);

    // no need to continue
   // if (altitude == NULL){
   //   return true;
	//}
	return true;
}

The DFRobot_SIM808.cpp file can be located in the DFRobot_SIM808 library
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants