Hello,
I'm writing a small library for my Quectel BG95.
Below you see my getGPS function.
I normally don't write code in arduino much, so don't laugh about how ridiculous devious the code looks like.
I tried many different ways but this seems to be the only way, as far as I figured.
As you can see below I split the _buffer which is holding the GPS data (I fill the buffer manually just for debugging).
It seems to be working for the most part, however at the end the outcome is wrong.
The outcome of the time and date should be :
_h = 18;
_m = 42;
_s = 41;
_da = 11;
_mo = 11;
_ye = 20;
But it is:
18
4218
414218
11414218
1111414218
201111414218
I don't see what is going wrong, someone perhaps does?
Thanks.
bool Quectel::getGPS(float *lat, float *lng, int time[])
{
if (sendAndWaitForReply("AT+QGPSLOC=2", 2000))
{
////+QGPSLOC: 184241.0,51.53045,5.99622,1.9,11.0,2,97.49,0.0,0.0,111120,04
sprintf(_buffer,"+QGPSLOC: 184241.0,51.53045,5.99622,1.9,11.0,2,97.49,0.0,0.0,111120,04");
char _response[8];
char _time[7]="0";
char _date[6]= "0";
char _lat[8]= "0";
char _lng[8]= "0";
int _step = 0;
int _step_i = 0;
for (int i = 0; i < sizeof(_buffer) - 1; i++) {
if(_buffer[i] == ':') {
_step = 1;
_step_i = 0;
}
else if(_buffer[i] == ',') {
_step++;
_step_i = 0;
}
else {
if(_step == 0) _response[_step_i] = _buffer[i];
if(_step == 1) _time[_step_i] = _buffer[i];
if(_step == 2) _lat[_step_i] = _buffer[i];
if(_step == 3) _lng[_step_i] = _buffer[i];
if(_step == 10) _date[_step_i] = _buffer[i];
_step_i++;
}
}
char _h[2], _m[2], _s[2], _da[2], _mo[2], _ye[2];
_h[0] = _time[1];
_h[1] = _time[2];
_m[0] = _time[3];
_m[1] = _time[4];
_s[0] = _time[5];
_s[1] = _time[6];
_da[0] = _date[0];
_da[1] = _date[1];
_mo[0] = _date[2];
_mo[1] = _date[3];
_ye[0] = _date[4];
_ye[1] = _date[5];
_debug->println(_h);
_debug->println(_m);
_debug->println(_s);
_debug->println(_da);
_debug->println(_mo);
_debug->println(_ye);
time[0] = atoi(_h);
time[1] = atoi(_m);
time[2] = atoi(_s);
time[3] = atoi(_da);
time[4] = atoi(_mo);
time[5] = atoi(_ye);
_debug->println(time[0]);
*lat = atof(_lat);
*lng = atof(_lng);
return true;
}
return false;
}