SIM808 GPS With Library DFROBOT_SIM808 without rounded off latitude and longitude
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
I just tried this code
#include <DFRobot_sim808.h>
#define PIN_TX 10
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Sukses membuka daya GPS");
else
Serial.println("Gagal membuka daya GPS");
}
void loop() {
//************** Get GPS data *******************
while (sim808.getGPS()) {
Serial.print(sim808.GPSdata.year);
Serial.print("/");
Serial.print(sim808.GPSdata.month);
Serial.print("/");
Serial.print(sim808.GPSdata.day);
Serial.print(" ");
Serial.print(sim808.GPSdata.hour);
Serial.print(":");
Serial.print(sim808.GPSdata.minute);
Serial.print(":");
Serial.print(sim808.GPSdata.second);
Serial.print(":");
Serial.println(sim808.GPSdata.centisecond);
Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon);
Serial.print("speed_kph :");
Serial.println(sim808.GPSdata.speed_kph);
//************* matikan daya GPS ************
sim808.detachGPS();
}
}
and the result is
![Image](https://preview.ibb.dfrobot/mUa21T/hasil.png)
wich code i mustedit in the library?
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;
double latitude = atof(latp);
double longitude = atof(longp);
// convert latitude from minutes to decimal
double degrees = floor(latitude / 100);
double minutes = latitude - (100 * degrees);
minutes /= 60;
degrees += minutes;
// turn direction into + or -
if (latdir[0] == 'S') degrees *= -1;
//*lat = degrees;
GPSdata.lat = degrees;
// convert longitude from minutes to decimal
degrees = floor(longitude / 100);
minutes = longitude - (100 * degrees);
minutes /= 60;
degrees += minutes;
// turn direction into + or -
if (longdir[0] == 'W') degrees *= -1;
//*lon = degrees;
GPSdata.lon= degrees;
// 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 //地面航向(000.0~359.9度,以真北为参考基准,前面的0也将被传输)
// 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, ","); //<3> 纬度ddmm.mmmm(度分)格式(前面的0也将被传输)
if (! date) return false;
uint32_t newDate = atol(date);
getDate(newDate);
// no need to continue
// if (altitude == NULL){
// return true;
//}
return true;
}
#include <DFRobot_sim808.h>
#define PIN_TX 10
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Sukses membuka daya GPS");
else
Serial.println("Gagal membuka daya GPS");
}
void loop() {
//************** Get GPS data *******************
while (sim808.getGPS()) {
Serial.print(sim808.GPSdata.year);
Serial.print("/");
Serial.print(sim808.GPSdata.month);
Serial.print("/");
Serial.print(sim808.GPSdata.day);
Serial.print(" ");
Serial.print(sim808.GPSdata.hour);
Serial.print(":");
Serial.print(sim808.GPSdata.minute);
Serial.print(":");
Serial.print(sim808.GPSdata.second);
Serial.print(":");
Serial.println(sim808.GPSdata.centisecond);
Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon);
Serial.print("speed_kph :");
Serial.println(sim808.GPSdata.speed_kph);
//************* matikan daya GPS ************
sim808.detachGPS();
}
}
and the result is
![Image](https://preview.ibb.dfrobot/mUa21T/hasil.png)
wich code i mustedit in the library?
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;
double latitude = atof(latp);
double longitude = atof(longp);
// convert latitude from minutes to decimal
double degrees = floor(latitude / 100);
double minutes = latitude - (100 * degrees);
minutes /= 60;
degrees += minutes;
// turn direction into + or -
if (latdir[0] == 'S') degrees *= -1;
//*lat = degrees;
GPSdata.lat = degrees;
// convert longitude from minutes to decimal
degrees = floor(longitude / 100);
minutes = longitude - (100 * degrees);
minutes /= 60;
degrees += minutes;
// turn direction into + or -
if (longdir[0] == 'W') degrees *= -1;
//*lon = degrees;
GPSdata.lon= degrees;
// 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 //地面航向(000.0~359.9度,以真北为参考基准,前面的0也将被传输)
// 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, ","); //<3> 纬度ddmm.mmmm(度分)格式(前面的0也将被传输)
if (! date) return false;
uint32_t newDate = atol(date);
getDate(newDate);
// no need to continue
// if (altitude == NULL){
// return true;
//}
return true;
}
2018-05-30 13:40:30 Do you mean the GPS didn't give you a right position? Could you specify your problem?
robert.chen
![userHeadPic](https://dfimg.dfrobot.com/dfPortrait2.png)