GPSD socket from Python

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

GPSD socket from Python

Post by JeffThompson »

I've got the Ultimate GPS board setup with my Raspberry Pi via the USB to TTL Serial cable and it works great. I've also built a Python script that reads the data. But...

It seems that on reboot I first have to run this command:

Code: Select all

sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock
How can I make this connection directly in Python? I tried using subprocess to run the above command but get this error:

Code: Select all

gpsd:ERROR: can't listen on local socket /var/run/gpsd.sock
gpsd:ERROR: control socket create failed, netlib error -1

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPSD socket from Python

Post by adafruit_support_mike »

The easiest way is to add this line to the end of /etc/rc.local

Code: Select all

gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock

User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

Re: GPSD socket from Python

Post by JeffThompson »

Hmm, doesn't seem to be working. I tried a few Python socket examples with little success, but now I can't get a fix at all.

I've restarted a few times and tried both your suggestion and the tutorial, but I just get the blinking red FIX light.

Could I have done something bad trying to communicate directly via a Python socket? Is there a way to reset the GPS?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPSD socket from Python

Post by adafruit_support_mike »

Okay, let's see..

Are you using a USB-to-Serial adapter between the RasPi and the GPS module, or connecting through the hardware UART?

User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

Re: GPSD socket from Python

Post by JeffThompson »

The Adafruit USB-to-serial cable, yes.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPSD socket from Python

Post by adafruit_support_mike »

Good.. that's the easier way to do it. Let's check hardware recognition and make sure the OS has created a serial port for the adapter.

What do you get from:

Code: Select all

ls -l /dev/USB*
sudo lsusb

User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

Re: GPSD socket from Python

Post by JeffThompson »

Sorry, been away from my Pi!

If I run the ls command I get:

Code: Select all

ls: cannot access /dev/USB*: No such file or directory
If I run lsub I get:

Code: Select all

-bash: lsub: command not found
Looks like maybe I did break something? I wasn't getting this error before.

User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

Re: GPSD socket from Python

Post by JeffThompson »

Or do you mean /dev/ttyUSB* like in the tutorial? For that, I get the expected /dev/ttyUSB0.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPSD socket from Python

Post by adafruit_support_mike »

Looks like you have a typo on the second command.. it's `lsusb`.

You can check whether the GPS module is making a connection through /dev/ttyUSB0 with the following command:

Code: Select all

sudo screen /dev/ttyUSB0 9600
That will open a serial connection on the specified device, and if the connection is good you should see the NMEA sentences scrolling past.

To exit the `screen` session, hit ctrl-A, then 'k'. You should get a prompt asking if you want to kill the window. Press 'y' and you'll drop back to the command line.

User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

Re: GPSD socket from Python

Post by JeffThompson »

Ah, good catch! From lsusb I get:

Code: Select all

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
From screen (after installing it), I get this:

Code: Select all

$GPGGA,000606.800,,,,,0,00,,,M,,M,,*70
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,000606.800,V,,,,,0.00,0.00,060180,,,N*4A
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPSD socket from Python

Post by adafruit_support_mike »

Okay good.. the second listing shows the GPS module emitting NMEA sentences, which confirms the USB-TTL cable is working.

The sentences say the module isn't seeing any satellites though.. do you have the module in a location where it can get a clear view of the sky?

User avatar
JeffThompson
 
Posts: 42
Joined: Mon Jun 14, 2010 3:05 pm

Re: GPSD socket from Python

Post by JeffThompson »

Not exactly (near-ish to a window) but it was working great before.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPSD socket from Python

Post by adafruit_support_mike »

If it worked before, we know it's at least possible for the module to get a fix at that location.

Try letting the thing run for a while and see if the $GPGSA sentences change. Those list the satellites the module has found so far.

If you can, try running the module in a different location for a while, ideally outside in a place where there isn't much radio noise. let's see if the module can make any connections at all.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”