Using android phone as gps sensor for linux gpsd (with ShareGPS android app).



Contents:

What for?

Phone configuration.

Bluetooth tethering.

Requirements

Configuration

USB tethering.

Requirements

Configuration

Udev configuration.

Udev rules file.

Scripts.

Simple way to install - Install Script.

User software.



Goal.

Most android phones (may be all) are equipped with gps sensor. There are many reasons to use rather notebook than phone as gps software host. Examples? Biger display. Flexibility. Configuration possibilities. And for satisfaction that's possible to use android device as gps sensor. Why not? To reach that we must do three things.

  1. Run some software sharing gps data on phone.

  2. Connect devices.

  3. Read data with corresponding software.


Phone configuration.

Run ShareGPS and check in Settings “Create NMEA” option and “Use USB/Bluetooth” depending on Your preferred way to connect devices.

TOP


BLUETOOTH TETHERING

That's simpler way.


 

Requirements for bluetooth tethering

Hardware

Android phone with installed ShareGPS.

Linux computer with working bt sensor onboard.

Software

blueman – most comfortable tool to manage bt connections

gpsd – linux gps daemon

some mapping/navigation program

TOP

 

Configuration for bluetooth

Blueman

As blueman works on most linux desktops out of the box, You do not need to configure it.

a) Simply pair Your phone with linux.

b) Run ShareGPS with bluetooth sharing enabled.

c) Then choose in blueman interface Device → Settings.

If ShareGPS works with “USE Bluetooth” enabled You should find “Serial Port” over there.

Choose it and finish dialog.

You shoud receive message such “Serial Port Connected”. There should be also serial device name.

If You use only one bt sensor usually it is /dev/rfcomm0

TOP


Gpsd

For gpsd You need set proper device in configuration.

Just /dev/rfcomm0 and start service.

Or start daemon manually:

# gpsd /dev/rfcomm0

That's all.

TOP



USB TETHERING

Although USB connection is more stable and less phone battery consuming, configuring USB tethering is more sophisticated.

There is no special drivers for phones to create regular tty device.

Therefore programmers uses adb from android sdk for most USB shared services.


 

Requirements for USB tethering

Hardware

Android phone with installed ShareGPS.

Linux computer (with USB port).

Software

udev daemon working (that's standard for recent linux desktops)

adb from android sdk

gpsd - linux gps daemon

ncat

netstat

TOP

How does it work?

It simply redirects tcp data shared with adb to fifo (with ncat).

Gpsd uses fifo instead tty.


 

Configuration for USB

There are three files needed to use usb connection:

1) 65-adb_gps_usb.rules - udev rules to launch others when You connect phone

2) adb_gps.helper - udev helper script executed directly by udev daemon

3) adb_gps_usb.sh - main script rerouting gps data into gpsd

There colud be only one script but any proccess called by udev must be unattached from daemon as quickly as it is possible, therefore I used two scripts. First of them (adb_gps.helper) only launches the second and exits.

I put all configuration in adb_gps_usb.sh. Simply put files in corresponding places and set required values inside.

TOP


Udev - Identify phone/create udev rules

First unplug Your phone.

1) Check how udev identify Your phone.

Execute:

#sudo udevadm monitor --property | grep ID_MODEL=

Then plug and wait until You see lines beggining with ID_MODEL=.

Ignore these containing “Card” string.

2) Remember value of ID_MODEL of Your phone:

For my Samsung I5700 Spica I found:

#ID_MODEL=GT-I5700

3) Create file /etc/udev/rules.d/65-adb_gps_usb.rules (You can name it as You wish only number 65 and extension are important).

TOP

Content of /etc/udev/rules.d/65-adb_gps_usb.rules:

65-adb_gps_usb.rules


4) Replace GT-I5700 with Your phone ID_MODEL:

# sudo sed -ie 's/GT-I5700/<Your phone ID_MODEL>/g' /etc/udev/rules.d/65-adb_gps_usb.rules

To refresh udev configuration execute:

# sudo udevadm trigger


Do not configure other stuff.

Simply put below scripts in /usr/local/bin.

adb_gps.helper - is udev helper to start the second and unbind from udev.

adb_gps_usb.sh - is te main script.

TOP

Content of /usr/local/bin/adb_gps.helper:

adb_gps.helper

Content of /usr/local/bin/adb_gps_usb.sh:

adb_gps_usb.sh

TOP


Then change it ownership to root and permissions to executable:

# sudo chown root /usr/local/bin/adb_gps*

# sudo chmod 755 /usr/local/bin/adb_gps*

Should work always when You connect devices with USB.

TOP


Simple way.

I wrote simple install script to make above with one command.

First download that archive: adb_gps_usb.tar.gz

Then unpack it and execute in terminal:

# cd <Where You put it>/adb_gps_usb
# sudo ./install.sh

Follow the Rabbit (may be white).

TOP


USER SOFTWARE AND UTILITIES WORKING WITH GPSD

There are some testing apps (cgps, xgps) shipped with gpsd.

For others Check gpsd home page

TOP