Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use a GPS dongle (Bluenext - BN903S) connected to the USB port of a TP-Link TL-WR703N running OpenWRT (Attitude Adjustment 12.09) and GPSD (3.7) along with my C program to receive and display coordinates.

When I go out to test it, clear sky and all, the GPS dongle's LED flashes, which indicates it has a fix, and while running my application, the coordinates displayed every 5-7 seconds or so seem to be constantly changing. However, as you can see in the screenshot below, even though I move around the area (displayed in red line in the image), the program logged that I was in the spots where there are markers. So the coordinates change, but they are wrong and all concentrated in one small area...

GPS coords image: http://i40.tinypic.com/2ex5x7d.jpg

This is the source code I had last. Nothing complex as far as the source-code goes, that's why I am wondering that it might not even be the source code's fault. I have tried so many "techniques" to receive them but all have similar result.

Can anyone help out what might the problem be here?

Help is much appreciated.

C++
if(gps_open("127.0.0.1", "2947", &gpsdata)<0)   // Check if GPS initialized ok ports: 2947
{
    printf("GPS open failed with error: %d\n", gps_open("127.0.0.1", "2947", &gpsdata));
    exit(EXIT_FAILURE);
}
else
{
    printf("GPS open OK\n");
    if(gps_stream(&gpsdata, WATCH_ENABLE, NULL) != 0)
    {
        printf("Data stream failed\n");
    }
    else
    {
        printf("GPS stream OK\n");
    }
}

AGAIN:while(1)
{
    double lat, longi;

    if(gps_waiting(&gpsdata, 2000)) // Checks if there is new data from the GPS. True means data, false no data or error
    {
        printf("there is data waiting\n");
        if(gps_read(&gpsdata) == -1)
        {
            printf("gps_read error\n");
        }
        else if(gpsdata.status > 0)     // GPS does have a fix
        {
                printf("Using %d satellites of %d visible\n", gpsdata.satellites_used, gpsdata.satellites_visible);

                lat = gpsdata.fix.latitude;
                longi = gpsdata.fix.longitude;

                if((isnan(lat) != 0) && (isnan(longi) != 0))        // To check if values are NaN (Not A Number)
                {
                    curTime = time(NULL);           // Update the current time
                    printf("Time %s : GPS fix is NaN %f, %f\n", ctime(&curTime), lat, longi);
                }
                else
                {
                    printf("MY Latitude %f and Longitude %f\n", lat, longi);
                }
        }
    } //END OF IF WAITING
    sleep(5);
}   //end of while(1)
Posted

1 solution

Quote:
So the coordinates change, but they are wrong and all concentrated in one small area...


This is not a precise statement. It seems to me the gps knows exactly where you are within a specifiable error bar.

The first thing I would do is compare your results with a handheld gps - eg Garmin etrex.

I have not used GPSD and probably would not. I prefer to know what is going on. Almost all gps modules can be configured to send NMEA records and these are very easy to parse. I prefer to use these because they come directly from the gps and provide a very comprehensive picture of what the gps is doing. Each record gives gps status at the time. I don't know what GPSD is doing in this regard.

Writing Your Own GPS Applications: Part I[^]

What you need to establish is the HDOP. This is a measure of the horizontal quality of the fix. If you can do this with GPSD do it and learn how to interpret the result. All gps fixes have an error - they are not exact. Some geometries of visible satellites will allow a fix to be established but of very poor quality.

http://en.wikipedia.org/wiki/Dilution_of_precision_(GPS)[^]

I would do all this before concluding there is a problem with your code.

I would however comment that in my opinion it is a poor library that returns a nan. A valid fix should always be valid data. It should return the status of the fix - valid or invalid.
Also time() is never used for gps data. The time value from the gps associated with each reading is far more accurate than host computer time - it comes from atomic clock.

Also I see gpsd is nmea based and you can output a log. I suggest you do this.
 
Share this answer
 
v5
Comments
Iniquitas 22-Aug-13 7:33am    
Thank you for the prompt and careful response.
You're saying that the GPSD library might not be communicating correctly with the device itself??
[no name] 22-Aug-13 7:38am    
No that's not what I mean. I said I don't know how GPSD works. You need to establish the error of your readings. Whether you do that with GPSD or something else doesn't matter. For me personally I trust NMEA records therefore I would not rely on GPSD. That's a personal view.
Iniquitas 22-Aug-13 8:19am    
Okay thanks anyway. Unfortunately I do not have time to look into NMEA records and figure it out that way. I was hoping someone who has dealt with GPSD before might be able to exclude the source code as the issue.
[no name] 22-Aug-13 10:17am    
Well then determine HDOP using GPSD - simple.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900