if ((rc = gps_open("localhost", "2947", &gpsdata)) == -1) {
printf("code: %d, reason: %s\n", rc, gps_errstr(rc));
return EXIT_FAILURE;
}
gps_stream(&gpsdata, WATCH_ENABLE | WATCH_JSON, NULL);
while (1) {
/* wait for 2 seconds to receive data */
if (gps_waiting (&gpsdata, 2000)) {
/* read data */
if ((rc = gps_read(&gpsdata)) == -1) {
printf("error occured reading gps data. code: %d, reason: %s\n", rc, gps_errstr(rc));
} else {
/* Display data from the GPS receiver. */
if ((gpsdata.fix.mode >= MODE_2D) && !isnan(gpsdata.fix.latitude) && !isnan(gpsdata.fix.longitude)) {
if(!isnan(gpsdata.fix.time))
(void)unix_to_iso8601(gpsdata.fix.time, scr, sizeof(scr));
printf("latitude: %f, longitude: %f, speed: %.1f %s, timestamp: %s altitude: %f climb %.1f %s/min \n", gpsdata.fix.latitude, gpsdata.fix.longitude, gpsdata.fix.speed * speedfactor, speedunits, scr, gpsdata.fix.altitude, gpsdata.fix.climb * altfactor * 60, altunits);
} else {
printf("no GPS data available\n");
}
}
printf(" Wait ");
}
sleep(1);
printf("status %d \n",gpsdata.status);
}
Thanks,
Lokesh