I want to read my GPS coordinates with libgps.
This is my code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <gps.h>
int main(void){
struct gps_data_t gps_data;
int ret = 0;
ret = gps_open("localhost", "2947", &gps_data);
gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
if (gps_waiting (&gps_data, 500)) {
if (gps_read (&gps_data) == -1) {
fprintf(stdout, "Error #3: No GPS data available! Retrying ...\n");
}
else {
fprintf(stdout, "GPS-Data: Latitude: %f, Longitude: %f, Altitude: %.1f, Timestamp: %ld\n", gps_data.fix.latitude, gps_data.fix.longitude, gps_data.fix.altitude);
}
}
/* When you are done... */
gps_stream(&gps_data, WATCH_DISABLE, NULL);
gps_close (&gps_data);
return 0;
}
Unfortunately, I always get this result:
GPS-Data: Latitude: nan, Longitude: nan, Altitude: nan, Timestamp: 301989888
So gpsd isn't returning any GPS coordinates ...
But if I execute sudo gpscat -s 4800 /dev/ttyACM0
:
$GPGGA,190238.00,4819.14754,N,01512.57069,E,2,11,0.83,469.6,M,43.1,M,,0000*53
Does anyone know what could be wrong?