OpenWrt Forum Archive

Topic: almost working - openwrt + $12 usb gps dongle

The content of this topic has been archived on 30 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

First post to the forum, be gentle.

While trying to get my wrt1900acs working (sigh, troublesome), I messed around with a cheap GPS dongle I had bought.

The dongle is a vk-172, available for $12 on ebay or $15 on amazon.  It appears to be a U-blox 7 usb gps (+other gnss) dongle.

I tried a lot of things, basically trial and error to get things working with no luck.
gpsd, ugps, etc.  Searching for information didn't help.


Then I found this application note from u-blox that gave me the hint I needed.

https://www2.u-blox.com/images/download … 059%29.pdf

I installed kmod-usb-acm and the device shows up as /dev/ttyACM0

This matches with the config file of the "ugps" app, which references ttyACM0
It even seems to (almost) work.

ugps is simple but does one job very well -- it will read nmea data from a
GPS device and set the clock from the date/time values in the datastream.

However, it didn't work for me.  But it ALMOST did, so I continued.

checking the log I got a lot of errors:

RMC datagram has wrong parameter count got 10 but expected 11
VTG datagram has wrong parameter count got 8 but expected 9
GGA datagram has wrong parameter count got 13 but expected 14

So I found my way to the source code and located the problem.

The ublox nmea output leaves out some values, which leads to rows of
commas.  The ugps code uses strtok which treats multiple delimiters
as one.  (an error in this case)

so ugps/nmea.c should have this routine:

static int
nmea_tokenize(char *msg)
{
        int cnt = 0;
        char *tok = strtok(msg, ",");

        while (tok && cnt < MAX_NMEA_PARAM) {
                nmea_params[cnt].str = tok;
                nmea_params[cnt].num = atoi(tok);
                cnt++;
                tok = strtok(NULL, ",");
        }

        return cnt;
}

look more like this (or something better):

static int
nmea_tokenize(char *msg)
{
        int cnt = 0;
        char *tok = strchr(msg, ',');

        while (tok && cnt < MAX_NMEA_PARAM) {
            *tok = '\0';
            tok++;
            nmea_params[cnt].str = tok;
            nmea_params[cnt].num = atoi(tok);
            cnt++;
            tok = strchr(tok, ',');
        }

        return cnt;
}


I may figure out how to recompile the ugps openwrt binary, but
until then I thought I'd pass off my findings.

Oh, I also tried getting gpsd + ntpd working.  That didn't work
either, but I think requires a lot more configuring.

Can you please provide the link to the source code you found?

Sorry, the source is found here: git://git.openwrt.org/project/ugps.git

Thank you.

I set up docker, got an openwrt build system going, compiled ugps and got it working, but it needs more work.  It seems to be hard-coded to the author's GPS output format.  Also, ugps doesn't really help share the system clock or keep it very accurate (system clock set if difference > 2 seconds)


So I tried gpsd + ntpd and it appears to work.

opkg install kmod-usb-acm  # for vk-172 gps dongle
opkg install gpsd          # supports various nmea/binary gps protocols
opkg install ntpd          # real ntpd to replace busybox

to configure gpsd, you have to change the gps device in /etc/config/gpsd:

config gpsd core
    option device    "/dev/ttyACM0"
    option port    "2947"
    option listen_globally    "false"
    option enabled    "true"

to configure ntpd, you need to uncomment these lines at the end of /etc/ntpd.conf:

# GPS(NMEA)+PPS
server 127.127.20.0 minpoll 4 prefer
fudge 127.127.20.0 flag3 1 flag2 0

# SMA PPS
server 127.127.28.0 minpoll 4 prefer
fudge 127.127.28.0 refid PPS flag3 1

When I check the system, the clock is now correct, so I'm happy it's working.
(router is not connected to anything, so it's not the ntp pool)

note that I don't understand all of this - I'm unsure how ntpd is communicating with gpsd because /proc/sysvipc is empty and there's no ntp-utils available in trunk (need ntpq to check)

(Last edited by mike866 on 29 Nov 2015, 02:54)

Hey Mike, do you mind sharing what you did to get ugps working? Also where did you get the source code for gpsd?

rajiv,  off the top of my head...

the changes I made to ugps are already given in comment 1, and I downloaded it from the source in comment 3: git://git.openwrt.org/project/ugps.git

I gave up on ugps because while it worked, it set the clock very abruptly, and after that it could drift for a long time and would only reset it again if it got way out of sync.


On the other hand, as described in comment 5, I got gpsd and ntpd working together.  They are part of openwrt and you can install them directly as binaries using "opkg" as shown.

Also I should mention, all of this applies to the dongle I purchased, a vk-172 dongle with a ublox-7 chip.

One limitation of this chip appears to be that it will report the time, but I don't think it will do PPS which will interrupt exactly at the second.  NTP does slightly better with pps.

(Last edited by mike866 on 6 Apr 2016, 00:37)

mike, can you please post the output of

ntpq -p

?

The discussion might have continued from here.