gpsd-users
[Top][All Lists]
Advanced

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

Re: powering on gps device


From: Nachiket Gokhale
Subject: Re: powering on gps device
Date: Thu, 24 Jun 2021 17:28:06 +0530

Yo Gary!

Thank you for your patience with me. 

Some background on what I want to do. Maybe I should have explained this to begin with. Would have saved you trouble. 

I want to get latitude and longitude information out of my gps. I wrote a small client and tested it with gpsfake. This client was based on the one in https://pypi.org/project/gps/  (see end of gps.py). The input to gpsfake was a nmea file generated via nmeagen.org. I can see the following information every half-second 

{'class': 'TPV', 'device': '/dev/pts/9', 'mode': 3, 'time': '2021-04-26T09:58:52.573Z', 'ept': 0.005, 'lat': 18.516816667, 'lon': 73.834533333, 'alt': 0.0, 'epv': 23.0, 'track': 198.4, 'speed': 15.999, 'climb': 0.0, 'epc': 46.0}

Now that I have access to a real physical gps, I'd like to get lat/lon out of it using the same (or similar) client I wrote for use with gpsfake. Notice that in response to your comments, I have added  gps.WATCH_NMEA in the client.

Based on your suggestions, here is what I am doing now, in sequence:

1) as root, Kill all previous gpsds
2) as root, gpsd -n -N -D3  /dev/ttyS0
3) as root, run the script to power on
4) as non root-user, start the client

Detailed output follows

1) As root, begin with 
    a) killall -9 gpsd 
    b) service gpsd stop
    c) rm /run/gpsd.sock
    
2) As root, gpsd -n -N -D3  /dev/ttyS0  which yields

gpsd:INFO: launching (Version 3.17)
gpsd:INFO: listening on port gpsd
gpsd:INFO: stashing device /dev/ttyS0 at slot 0
gpsd:INFO: SER: opening GPS data source type 2 at '/dev/ttyS0'
gpsd:INFO: SER: speed 115200, 8N1
gpsd:INFO: SER: speed 9600, 8O1
gpsd:INFO: SER: speed 115200, 8N1
gpsd:INFO: SER: speed 9600, 8N1
gpsd:INFO: SER: speed 115200, 8N1
gpsd:INFO: gpsd_activate(2): activated GPS (fd 6)
gpsd:INFO: KPPS:/dev/ttyS0 RFC2783 path:/dev/pps0, fd is 7
gpsd:INFO: KPPS:/dev/ttyS0 pps_caps 0x1133
gpsd:INFO: KPPS:/dev/ttyS0 have PPS_CANWAIT
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS will be used
gpsd:INFO: PPS:/dev/ttyS0 ntpshm_link_activate: 1
gpsd:INFO: device /dev/ttyS0 activated
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Interrupted system call
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Interrupted system call
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Interrupted system call
gpsd:INFO: running with effective group ID 20
gpsd:INFO: running with effective user ID 115
gpsd:INFO: startup at 2021-06-24T11:09:19.000Z (1624532959)
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: PPS:/dev/ttyS0 unchanged state, ppsmonitor sleeps 10

3) As root, run the power on script in a separate terminal. gpsd identifies the gps device and outputs

gpsd:INFO: /dev/ttyS0 identified as type NMEA0183, 79 sec @ 115200bps
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year.
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:INFO: KPPS:/dev/ttyS0 kernel PPS timeout Connection timed out
gpsd:WARN: PPS:/dev/ttyS0 unchanged state, ppsmonitor sleeps 10
 
4) As non-root user, start the client. gpsd detects that a client has connected because it outputs the following

gpsd:CLIENT: => client(0): {"class":"VERSION","release":"3.17","rev":"3.17","proto_major":3,"proto_minor":12}\x0d\x0a
gpsd:CLIENT: <= client(0): ?WATCH={"enable":true,"json":true}\x0a
gpsd:CLIENT: => client(0): {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyS0","driver":"NMEA0183","activated":"2021-06-24T11:10:54.712Z","flags":1,"native":0,"bps":115200,"parity":"N","stopbits":1,"cycle":1.00}]}\x0d\x0a{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}\x0d\x0a
gpsd:CLIENT: <= client(0): ?WATCH={"enable":true,"nmea":true}\x0a
gpsd:CLIENT: => client(0): {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyS0","driver":"NMEA0183","activated":"2021-06-24T11:10:54.712Z","flags":1,"native":0,"bps":115200,"parity":"N","stopbits":1,"cycle":1.00}]}\x0d\x0a{"class":"WATCH","enable":true,"json":true,"nmea":true,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}\x0d\x0a

The client gets the following data

connected to tcp://127.0.0.1:2947
----------------------------------------
{'class': 'VERSION', 'release': '3.17', 'rev': '3.17', 'proto_major': 3, 'proto_minor': 12}
----------------------------------------
{'class': 'DEVICES', 'devices': [{'class': 'DEVICE', 'path': '/dev/ttyS0', 'driver': 'NMEA0183', 'activated': '2021-06-24T11:10:54.712Z', 'flags': 1, 'native': 0, 'bps': 115200, 'parity': 'N', 'stopbits': 1, 'cycle': 1.0}]}
----------------------------------------
{'class': 'WATCH', 'enable': True, 'json': True, 'nmea': False, 'raw': 0, 'scaled': False, 'timing': False, 'split24': False, 'pps': False}
----------------------------------------
{'class': 'DEVICES', 'devices': [{'class': 'DEVICE', 'path': '/dev/ttyS0', 'driver': 'NMEA0183', 'activated': '2021-06-24T11:10:54.712Z', 'flags': 1, 'native': 0, 'bps': 115200, 'parity': 'N', 'stopbits': 1, 'cycle': 1.0}]}
----------------------------------------
{'class': 'WATCH', 'enable': True, 'json': True, 'nmea': True, 'raw': 0, 'scaled': False, 'timing': False, 'split24': False, 'pps': False}

'nmea': True in the last data received by the client. 

Notice there is no TPV information sent to the client, which was present when I was faking the gps using gpsfake. I would like TPV classes or something else that holds latitude/longitude information.

Finally, if gpsd is not running, I get sentences like the following using cat /dev/ttyS0. If gpsd is running I do not get output from cat /dev/ttyS0, presumably because gpsd is reading it. 

$GPGGA,112736.947,1829.7791,N,07349.0327,E,1,4,1.64,582.6,M,-64.7,M,,*75
$GPGGA,112737.947,1829.7837,N,07349.0297,E,1,5,1.50,585.3,M,-64.7,M,,*79
$GPGGA,112739.000,1829.7767,N,07349.0256,E,1,6,1.14,581.4,M,-64.7,M,,*7A
$GPGGA,112740.000,1829.7803,N,07349.0281,E,1,7,1.03,585.8,M,-64.7,M,,*7C
$GPGGA,112741.000,1829.7821,N,07349.0285,E,1,8,0.88,585.6,M,-64.7,M,,*7A

I'd like for gpsd to make available latitude/longitude information in some form on 127.0.0.1:2947

Scripts used in this work follow. 

Again, thank you for your help and time.

Nachiket

######## Script to power on GPS begins ################
from time import sleep
import serial

ser = serial.Serial(
    port='/dev/ttyS0', #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0
    baudrate = 115200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1,
    exclusive=False
)

bool_power_up = False
print ("Turn ON GPS Power (AT+CGPSPWR=1)")
ser.write(bytes("AT+CGPSPWR=1\n", 'utf-8')) #turn on the GPS module
# Reading response has been commented because
# gpsd might be reading at the same time and this causes
# serial.serialutil.SerialException
# device reports readiness to read but returned no data
# rx = ser.readline()
# print (rx.decode('utf-8'))

# sleep(30) # Wait till the module gets a fix. This typically takes between 20-60s.
sleepsecs = 15
print ("Waiting for {}s to get a GPS fix...".format(sleepsecs))
while sleepsecs:
    mins, secs = divmod(sleepsecs, 60)
    timer = '{:02d}:{:02d}'.format(mins, secs)
    print(timer, end="\r")
    sleep(1)
    sleepsecs -= 1
#
print ("\nGPS output set to GGA (AT+CGPSOUT=2)")
ser.write(bytes("AT+CGPSOUT=2\n", 'utf-8'))
# readline turned off - see notes above
# rx = ser.readline()
# print (rx.decode('utf-8'))
#print ("\n")

try:
    while True:
        print('Staying alive')
        sleep(5)
except KeyboardInterrupt as e:
    print('Caught KeyboardInterrupt....turning off GPS')
    print ("Turn OFF GPS Power (AT+CGPSPWR=0)")
    ser.write(bytes("AT+CGPSPWR=0\n", 'utf-8'))
    #readline turned off - see notes above
    #rx = ser.readline()
    #print (rx.decode('utf-8'))
    print ("\n")
    ser.close() # close serial port
    sleep(5)
####### Script to power on GPS ends ###############################

####### Client to read data from 127.0.0.1:2947 begins #################
import gps
import sys
import argparse
import time

def getargs():
    parser = argparse.ArgumentParser(description='args for fake_gps')
    parser.add_argument('--host',help='address of host',
                        required=False,type=str,default='127.0.0.1'
                        )
    parser.add_argument('--port',help='listening port',
                        required=False,type=int,default=2947
                        )

    args = parser.parse_args()
    return args

if __name__ == '__main__':

    args = getargs()
    host = args.host
    port = args.port
    opts = {}
    opts['verbose'] = True
    opts['host']    = host
    opts['port']    = port
 
   
    session = gps.gps(**opts)
    session.stream(gps.WATCH_ENABLE)
    session.stream(gps.WATCH_NMEA)

    ictr = 0

    while True:
        dd = next(session)
        dd = dict(dd)            
        print('-'*40)            
        print(dd)
        time.sleep(0.5)
####### Client to read data from 127.0.0.1:2947 ends #################


On Wed, Jun 23, 2021 at 10:24 PM Gary E. Miller <gem@rellim.com> wrote:
Yo Nachiket!

On Wed, 23 Jun 2021 14:28:46 +0530
Nachiket Gokhale <gokhalen@gmail.com> wrote:

> I think I was able to get gpsd to open the serial port /dev/ttyS0 and
> read from it. I think the problem was that there were other gpsds
> listening. However, gpsmon still cannot open /dev/ttyS0. And gpsd
> cannot open /dev/ttyS0 after "gpsmon /dev/ttyS0" is used. However, if
> gpsmon is not used before gpsd, gpsd seems to access /dev/ttyS0.

Use this to see who else has a port open: lsof /dev/ttyS0

An easy way to help us help you debug is to download, and run, gpsdebuginfo:

https://gpsd.io/gpsdebuginfo

Then show us the results.

> >   So we need to know what model of receiver you have to help. 
>
> I believe it is a SIMCom SIM808

My condolences.  It has minimal doc on the GPS funcions.

> >  Good.  Are you installing a package, from a tar ball, or from git?
> > 
>
> I'm installing on a Raspberry Pi using apt. So it must be the
> Ubuntu/Debian package.

Then it is not from us.  We do not create packages.

> >  And you forgot to run as root? 
>
> No, I'm running everything as root.

Odd.

> My problem now is that gpsd does not seem to read the NMEA (GPGGA)
> sentences sent by the GPS unit to /dev/ttyS0.  When gpsd is not
> running I can cat /dev/ttyS0 and see the GPGGA sentences. If I
> terminate gpsd using ctrl+C the sentences stop coming to /dev/ttyS0

I don't understand...  You say they stop coming to gpsd, so they were
coming to gpsd?

> The following is the output of my GPSD
>
> gpsd -N -D3  /dev/ttyS0

You forgot to use -n.  Witht -n, gpsd ony connects to the recevier
when it has a client connection.

> gpsd:INFO: launching (Version 3.17)

Very old.  Older than your SIMCOM.  Can you try something newer?

> gpsd:INFO: listening on port gpsd
> gpsd:INFO: stashing device /dev/ttyS0 at slot 0
> gpsd:INFO: running with effective group ID 20
> gpsd:INFO: running with effective user ID 115
> gpsd:INFO: startup at 2021-06-23T06:59:03.000Z (1624431543)
> gpsd:CLIENT: => client(0):
> {"class":"VERSION","release":"3.17","rev":"3.17","proto_major":3,"proto_minor":12}\x0d\x0a
> gpsd:CLIENT: <= client(0): ?WATCH={"enable":true,"json":true}\x0a

You said nothing of running a gpsd client??

> {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyS0","activated":"2021-06-23T06:59:15.245Z","native":0,"bps":115200,"parity":"N","stopbits":1,"cycle":1.00}]}\x0d\x0a{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}\x0d\x0a

Did it stop there?  It was just getting interesting.

> I don't understand why it runs with an effective group ID of 20 and
> effective user ID of 115. Shouldn't these IDs be 0 for processes
> started by root? I am launching gpsd as root.

No.  gpsd starts as root, then drops priviledges for better security.
gpsd only needs root to start, so safer to drop root after it is needed.

> Also, as you can see, clients seem to connect to it.

Actually, I do not see that.

> However, the
> client only receives the following data.

What client??

> There is no GPGGA data
> forwarded to the client.

Not least because the client did not ask for NMEA.

> {'class': 'VERSION', 'release': '3.17', 'rev': '3.17', 'proto_major':
> 3, 'proto_minor': 12}
> ----------------------------------------
> {'class': 'DEVICES', 'devices': [{'class': 'DEVICE', 'path':
> '/dev/ttyS0', 'activated': '2021-06-23T07:15:34.175Z', 'native': 0,
> 'bps': 115200, 'parity': 'N', 'stopbits': 1, 'cycle': 1.0}]}
> ----------------------------------------
> {'class': 'WATCH', 'enable': True, 'json': True, 'nmea': False,
> 'raw': 0, 'scaled': False, 'timing': False, 'split24': False, 'pps':
> False}

notice the "nmea": False?  NMEA was not requested.

> CGPS shows only the following output
>
> {"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"
> 115200,"parity":"N","stopbits":1,"cycle":1.00}]}
> {"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"
> timing":false,"split24":false,"pps":false}

I assume you mean cgps?  How long did you wait?  It can take a GPS
over 13 munutes to wake from a cold boot.

> Any help would be much appreciated. It almost seems that the receiver
> stops sending the GPGGA data once gpsd is connected to /dev/ttyS0.

Did you try to rerun your AT commands after gpsd is running?

The SIMCOM chips are a PITA.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
        gem@rellim.com  Tel:+1 541 382 8588

            Veritas liberabit vos. -- Quid est veritas?
    "If you can't measure it, you can't improve it." - Lord Kelvin

reply via email to

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