Hello,
I am currently messing w/ gpsd and trying to make a file in python3 or C.
The file(s) are giving me connection issues w/ gpsd. I do not know where to turn so far. Here or there, anyway, please see the below file in C.
This file was take from here: https://gpsd.io/example1.c.txt
// example gpsd client
// compile this way:
// gcc example1.c -o example1 -lgps -lm
#include <gps.h> // for gps_*()
#include <math.h> // for isfinite()
#define MODE_STR_NUM 4
static char *mode_str[MODE_STR_NUM] = {
"n/a",
"None",
"2D",
"3D"
};
int main(int argc, char *argv[])
{
struct gps_data_t gps_data;
if (0 != gps_open("localhost", "2947", &gps_data)) {
printf("Open error. Bye, bye\n");
return 1;
}
(void)gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
while (gps_waiting(&gps_data, 5000000)) {
if (-1 == gps_read(&gps_data, NULL, 0)) {
printf("Read error. Bye, bye\n");
break;
}
if (MODE_SET != (MODE_SET & gps_data.set)) {
// did not even get mode, nothing to see here
continue;
}
if (0 > gps_data.fix.mode ||
MODE_STR_NUM <= gps_data.fix.mode) {
gps_data.fix.mode = 0;
}
printf("Fix mode: %s (%d) Time: ",
mode_str[gps_data.fix.mode],
gps_data.fix.mode);
if (TIME_SET == (TIME_SET & gps_data.set)) {
// not 32 bit safe
printf("%ld.%09ld ", gps_data.fix.time.tv_sec,
gps_data.fix.time.tv_nsec);
} else {
puts("n/a ");
}
if (isfinite(gps_data.fix.latitude) &&
isfinite(gps_data.fix.longitude)) {
// Display data from the GPS receiver if valid.
printf("Lat %.6f Lon %.6f\n",
gps_data.fix.latitude, gps_data.fix.longitude);
} else {
printf("Lat n/a Lon n/a\n");
}
}
// When you are done...
(void)gps_stream(&gps_data, WATCH_DISABLE, NULL);
(void)gps_close(&gps_data);
return 0;
}
The error reports in output this idea: Open error. Bye, bye
.
Seth
P.S. The python3 output is far worse but says about the same thing. If I run gpsd w/ required arguments, the gpsd daemon works well. It spews tons of info. per second.
Update
I got the python3 example to work…
The python3 example located here, https://gpsd.io/example2.py.txt, works but one would have to install libgps-dev and restart the daemon to make the file correctly display.