gpsd-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gpsd Example2.py


From: Dirk Beer
Subject: Re: gpsd Example2.py
Date: Wed, 21 Sep 2022 06:34:57 +0000

Thanks, Gary, appreciate the response!

------- Original Message -------
On Tuesday, September 20th, 2022 at 8:51 PM, Gary E. Miller <gem@rellim.com> 
wrote:

> Yo Dirk!
> 
> On Tue, 20 Sep 2022 12:46:23 +0000
> Dirk Beer rdbeer@pm.me wrote:
> 
> > I'm learning how to use gpsd in python, and I'm wondering about
> > discrepancies in the examples I see.
> 
> 
> Not discrepancies, just more than one way to do things.
> 
> > Can you point me in the right direction?
> 
> 
> You are already there: the gpsd doc and examples.
> 
> > Specifically, Example2.py shows something like:
> > 
> > session = gps.gps(mode=gps.WATCH_ENABLE)
> > while 0 == session.read():
> > print(session.fix.xxx)
> 
> 
> Not for a while. Check out the current example2.py:
> 
> https://gpsd.io/gpsd-client-example-code.html#_example_2python
> 
> > But https://gpsd.io/libgps.html shows:
> > 
> > session = gps.gps(host="localhost", port="2947")
> > session.stream(flags=gps.WATCH_JSON)
> > for report in session:
> > process(report)
> > del session
> 
> 
> That works too, except for the missing check that the proper message
> got read.
Ok, good to know, thanks. Since example2.py is a more complete example, I'll 
work with that.

> 
> > For me, Example2.py doesn't work, it shows repeated identical lat,
> > longs (but I suppose this could be a problem on my end).
> 
> 
> Try the latest example2.py, that should work. If it does not
> then send a capture of your raw data: gpspipe -R -w 30 > raw.log
Ok, tried it (with gpsd started as root, and running the example as root or 
regular user) and now I do get lat, lons that change (great!). 

Follow up question: why is the output pairs of exact duplicates? 

    root@pheromone:~# python3 example2.py
    Mode: 3D(3) Time: n/a Lat 32.729173 Lon -116.993810
    Mode: 3D(3) Time: n/a Lat 32.729174 Lon -116.993811
    Mode: 3D(3) Time: n/a Lat 32.729174 Lon -116.993811
    Mode: 3D(3) Time: n/a Lat 32.729170 Lon -116.993812
    Mode: 3D(3) Time: n/a Lat 32.729170 Lon -116.993812
    Mode: 3D(3) Time: n/a Lat 32.729169 Lon -116.993813
    Mode: 3D(3) Time: n/a Lat 32.729169 Lon -116.993813

If I set a measRate greater than the default 1000, I get more duplicates:

    root@pheromone:~# ubxtool -p CFG-RATE,100 | grep -A 2 CFG-RATE
    root@pheromone:~# ubxtool -p CFG-RATE | grep -A 2 CFG-RATE
    UBX-CFG-RATE:
     measRate 100 navRate 1 timeRef 1 (GPS)

    root@pheromone:~# python3 example2.py
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993805
    Mode: 3D(3) Time: n/a Lat 32.729236 Lon -116.993806

Is there a way to get a single fresh reading each time the gps device produces 
it instead of these duplicates? Ideally, I'd like to run code in response to a 
fresh gps output. 

This is the original reason I was comparing the two code examples, I thought 
that session.read() was supposed to be blocking and would get only fresh 
readings as they are output by the device, versus iterating on the session in 
the second example, which does not seem to be blocking.

I did try to get a raw log, but got this error after a few minutes:

    root@pheromone:~# gpspipe -R -w 30 > raw.log
    gpspipe: could not connect to gpsd 30:2947, can't connect to host/port 
pair(-6)

The attached raw.log is from running without the -w option and hitting ^C after 
30 seconds.

> 
> > I'm wondering, which approach is the right way to do things?
> 
> 
> Both work, except the later is missing the class check.
> 
> > (I'm using 3.24, gpsd started with sudo /usr/local/sbin/gpsd
> > /dev/ttyACM0 -F /var/run/gpsd.sock on a raspberry pi zero with
> > Bullseye)
> 
> 
> gpsd is meant to be run as root, not under sudo:
> 
> sudo is evil:
> 
> https://gpsd.io/ubxtool-examples.html#_sudo_sudont
> 
> Why are you supplying both a device and a socket?
> 
> Why are you not using the -n option?
> 

Haha, I misread "sock" as "lock". It's from an example somewhere on the web, 
thought it was a lock file. Ok, now running as root, without the socket, and 
with the -n option, which from the docs sounds like it helps get readings 
quicker.

    gpsd -s 115200 -n /dev/ttyACM0

Cheers,
Dirk



Attachment: raw.log
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]