Using the Sierra MC5725’s GPS on Linux
After not being able to get this card’s GPS to do anything, I forgot about it for a while. Now that I’ve had some time, I revisited it and was able to get it working. Read on to see how.
Test the GPS
The Sierra Wireless MC5725 exposes three USB serial ports: A control port, a data port, and an NMEA (GPS data) port. The control port and NMEA ports are the ones we’re interested in. I stumbled upon some documentation that describes how to activate the GPS. Essentially, you have to connect to the control port (should be ttyUSB0 if you don’t have other USB serial devices), and issue some AT commands. You can read up on all the commands in the document, but the one we’re interested in is ‘AT!GPSTRACK’. The arguments are fix type (1 is the only type supported), max time to acquire a fix, maximum preferred error (in meters), number of position fixes to get (1000=indefinitely until signal lost), and number of seconds between each fix. The example given in the document, which is what I recommend using, is ‘AT!GPSTRACK=1,255,30,1000,1’.
Let’s test it out first. Make sure you have GNU screen installed. Do not install gpsd yet. Open up two terminals, and run ‘screen /dev/ttyUSB0’ on one, and ‘screen /dev/ttyUSB2’ on the other.
First, move the laptop somewhere where it can pick up a good GPS signal, like near a window or outside. On the ttyUSB0 screen, enter the commands:
ATE1 AT!GPSLOCK=0 AT!GPSTRACK=1,255,30,1000,1
‘ATE1’ causes the modem to echo commands back at you, so that you can actually see what you type. The guide suggests running ‘AT!GPSLOCK=0’ to unlock the GPS. I didn’t have to run this, but you may have to. Note that this is different from the ‘AT!GPSLOC’ command, which returns the last known location. ‘AT!GPSTRACK’ initializes the tracking. After that, you caan run ‘AT!GPSSTATUS’. You should see ‘ACTIVE’ in the ‘Fix Session Status’ line.
Again, make sure the laptop is somewhere where it will be able to pick up a strong signal from the GPS satellites. Take a look at your ttyUSB2 terminal. Once the satellites have been acquired, you should see GPS data start to come out onto the terminal. This is NMEA data which should be interpreted by a program like ‘gpsd’.
Automating GPS Activation
Obviously, you won’t want to have to type in a bunch of Hayes commands every time you want to use your GPS. You can write a shell script to do it, with printf ‘AT!…’ > /dev/ttyUSB0. The one ‘gotcha’ here is that you have to finish your lines with a carriage return (\r) rather than a newline (\n). Just trying to ‘echo’ commands to the modem won’t work, since they will end with newlines. Here’s a simple script that can do it:
#!/bin/bash CMDTTY=/dev/ttyUSB0 case $1 in start) echo "Starting GPS on $CMDTTY" printf 'AT!GPSTRACK=1,255,30,1000,1\r' > $CMDTTY ;;
restart) echo "Restarting GPS on $CMDTTY" printf 'AT!GPSEND=0\r' > $CMDTTY sleep 1 printf 'AT!GPSTRACK=1,255,30,1000,1\r' > $CMDTTY ;;
stop) echo "Stopping GPS on $CMDTTY" printf 'AT!GPSEND=0\r' > $CMDTTY ;; -h) echo "Program to control a Sierra Wireless MC5725's GPS module." echo "Usage: sgpsc (start|restart|stop)" ;; *) echo "Incorrect syntax. Usage: sgpsc (start|restart|stop) or sgpsc -h" ;; esac
GPSD and Client Software
Now, install gpsd. Configuration is tricky, since different distros put the config file in different places. On Debian unstable, the systemd launcher for gpsd doesn’t even read the config file at all. Unless you know for certain that your distro provides a working way to configure it as a proper daemon, then completely disable the service from automatically starting. We’ll just be running gpsd manually. The arguments we want are ‘-b’ (makes the connection to the GPS read-only), -n (makes it poll even when a client isn’t connected, really makes no difference here), and /dev/ttyUSB2 (USB2, not USB0). You’ll want to either run the daemon as root or make sure your account has permission to read the serial ports.
# gpsd -bnN /dev/ttyUSB2
The -N option causes it to run in the foreground so we can see any issues. If you get a message saying ‘gpsd:ERROR: PPS iotctl(TIOCMIWAIT) failed: 25 Inappropriate ioctl for device’, this is normal and will not prevent gps from working. Fire up xgps, and it should automatically connect to gpsd. Now, while you were doing all that, it’s possible that the GPS lost connection and needs to be restarted. Just do the ‘AT!GPSEND=0’ and ‘AT!GPSTRACK=…’ as seen in the script above. As soon as your GPS gets a fix, you should see all of the text boxes at the bottom of xgps start to fill with data, including position and velocity data.
I’m using the card on a ThinkPad x300. Laptops, especially ThinkPads, can get pretty finicky over wireless cards and the radio switch. To avoid problems, make sure you’re putting the card in the right slot (the WWAN slot). Having more than one of the same type of card (e.g. 2 Wi-Fi, 2 WWAN) can cause problems in ThinkPads. Check ‘rfkill list’ to make sure the card isn’t soft-disabled (use ‘rfkill unblock’ if it is).
Occasionally, if the card is disabled and re-enabled (through rfkill or other means), then ttyUSB0/1/2 will become ttyUSB3/4/5 (or whatever your next available numbers are). Generally, if you disable and re-enable the card again, it will go back to the original device names.