How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
kshetline
 
Posts: 9
Joined: Wed Apr 01, 2020 3:00 pm

How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Post by kshetline »

The Adafruit GPS HAT supports an NMEA command, $CDCMD,33,1, which provides reports on the status of the GPS module's antenna connection.

I'd like to issue this command when my Pi's GPS daemon starts up. Can I configure that somehow in the /etc/default/gpsd config file? By some other means?

If I shut down gpsd I can use `minicom` to send this command and see that it works. But I'd like this to be automatic, without having to stop gpsd, send the command, then start gpsd again.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Post by mikeysklar »

Good question.

I think you have a few options.

1) If you have install the gpsd-clients package as the guide suggests it provides some tools to communicate directly with the daemon so you do not need to stop / start it.

https://learn.adafruit.com/adafruit-ult ... sd-1723492

2) The easiest tool included would be the recommend cgps. Which is a curses based summary of connection status.

Code: Select all

cgps -s
3) There is also a `gpsctl` utility which can talk to GPSD which might be more what you are looking for. You could add the command to /etc/rc.local for startup.

4) You can also generate a report by running gps_test.py example provided after install the gps python package

Code: Select all

pip3 install gps
gps_test.py

Code: Select all

import gps

# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
        report = session.next()
        # Wait for a 'TPV' report and display the current time
        # To see all report data, uncomment the line below
        # print(report)
        if report['class'] == 'TPV':
            if hasattr(report, 'time'):
                print(report.time)
    except KeyError:
        pass
    except KeyboardInterrupt:
        quit()
    except StopIteration:
        session = None
        print("GPSD has terminated")
        
https://learn.adafruit.com/adafruit-ult ... ut-1723503

User avatar
kshetline
 
Posts: 9
Joined: Wed Apr 01, 2020 3:00 pm

Re: How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Post by kshetline »

mikeysklar wrote: Wed Sep 14, 2022 5:48 pm 3) There is also a `gpsctl` utility which can talk to GPSD which might be more what you are looking for. You could add the command to /etc/rc.local for startup.
I had been hoping that gpsctl would do the trick, but when I try this:

Code: Select all

gpsctl -x "\$CDCMD,33,1*7C\r\n"
...the result I get is:

Code: Select all

gpsctl:ERROR: SER: device open of /dev/serial0 failed: Device or resource busy - retrying read-only
gpsctl:ERROR: SER: read-only device open of /dev/serial0 failed: Device or resource busy
gpsctl:ERROR: initial GPS device /dev/serial0 open failed
I thought the point of this command would be to talk to the GPS daemon and tell it to send a message using the access it already has to /dev/serial0. But gpsctl seems like it's trying to open /dev/serial0 by itself, and failing because it's obviously going to be busy.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Post by mikeysklar »

What serial device is your Ultimate GPS showing up on? I don't think it would be /dev/serial0 today. You can check the output of `dmesg` if you are not sure. My guess is your are using /dev/ttyUSB0

You might need to specify the serial port to help gpsctl.

What happens when you run:

Code: Select all

gpsctl /dev/ttyUSB0
If that works then you can go back to adding the -x <NMEA command> <serialport>

User avatar
kshetline
 
Posts: 9
Joined: Wed Apr 01, 2020 3:00 pm

Re: How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Post by kshetline »

mikeysklar wrote: Thu Sep 15, 2022 4:47 pm What happens when you run:

Code: Select all

gpsctl /dev/ttyUSB0

Code: Select all

pi@clock:~ $ gpsctl /dev/ttyUSB0
gpsctl:ERROR: specified device not found in device list.
pi@clock:~ $ gpsctl /dev/serial0
/dev/serial0 identified as a MTK-3301 AXN_5.1.6_3333_18041700-0005 at 9600 baud.
The Adafruit GPS HAT isn't a USB device. It connects via the GPIO RXD/TXD serial data pins. Besides the serial connection, the GPS HAT sends a PPS (Pulse Per Second) signal over GPIO pin 4 to create a more accurate time base than USB GPS devices provide.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: How can I send an NMEA command, by default, to GPS HAT when gpsd starts?

Post by mikeysklar »

My bad about this being a HAT vs USB based Ultimate GPS.

We should be able to resolve this quickly.

Are you able to access /dev/serial0? Maybe sudo? To see the raw data?

Code: Select all

cat /dev/serial0
If so, does gpsctl work with this command, rather than write a NMEA command?

Code: Select all

$ gpsctl -Q fix
Time (UTC): 2019-04-18 15:31:27 (yyyy-mm-dd hh:mm:ss)
Latitude: 52.05994980 N
Longitude: 2.72698960 W
Altitude: 198.789 feet
Motion: 0.338 mph at 53.114 degrees heading
Satellites: 5 used for computing this fix
Accuracy: time (39 ns), height (+/-18.199 feet), position (+/-103.911 feet), heading(+/-8.230 degrees), speed(+/-0.132 mph)

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”