Access to /dev/ttyS2 in Python3 but not C?


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:

// 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] = {

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");
        if (MODE_SET != (MODE_SET & gps_data.set)) {
            // did not even get mode, nothing to see here
        if (0 > gps_data.fix.mode ||
            MODE_STR_NUM <= gps_data.fix.mode) {
            gps_data.fix.mode = 0;
        printf("Fix mode: %s (%d) Time: ",
        if (TIME_SET == (TIME_SET & gps_data.set)) {
            // not 32 bit safe
            printf("%ld.%09ld ", gps_data.fix.time.tv_sec,
        } 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);
    return 0;

The error reports in output this idea: Open error. Bye, bye .


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.


I got the python3 example to work…

The python3 example located here,, works but one would have to install libgps-dev and restart the daemon to make the file correctly display.

Hi Seth,

Is the gpsd service running and connected to port 2947 ?

Run to check on the port

netstat -antup

The last time I tried using gpsd I had some issues, decided to skip it and just talk serial to the gps chip.


I noticed that in the files for gpsd and gps from libgps-dev and gpsd, there are some files that can be altered.

They say to not hand-hack them as they are produced by scons.

I also found the file. I changed it a bit but it has not one change from netstat -antup.

netstat -antup still shows that, well...after a restart w/ systemctl of gpsd.service, that gpsd or is located at

I know I can hand hack it to say something else, i.e. my local address or or whatever.


P.S. But yes sir…

@benedict.hewson , I see gpsd is having an issue w/ having to be restarted to work during a fresh boot of the BBGW. I will try to talk to the chip directly.


Yeppers. It seems if I uninstall gpsd, things go smoothly. So far, I only stopped the gpsd.service file w/ systemctl but I think I may have to uninstall it.

It has a .socket file also w/ many different files associated w/ it.