Using android phone as gps sensor for linux gpsd (with ShareGPS android app).
Udev rules file.
Simple way to install - Install Script.
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.
Run some software sharing gps data on phone.
Read data with corresponding software.
Run ShareGPS and check in Settings “Create NMEA” option and “Use USB/Bluetooth” depending on Your preferred way to connect devices.
That's simpler way.
Requirements for bluetooth tethering
Android phone with installed ShareGPS.
Linux computer with working bt sensor onboard.
blueman – most comfortable tool to manage bt connections
gpsd – linux gps daemon
some mapping/navigation program
Configuration for bluetooth
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
For gpsd You need set proper device in configuration.
Just /dev/rfcomm0 and start service.
Or start daemon manually:
# gpsd /dev/rfcomm0
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
Android phone with installed ShareGPS.
Linux computer (with USB port).
udev daemon working (that's standard for recent linux desktops)
adb from android sdk
gpsd - linux gps daemon
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.
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.
Udev - Identify phone/create udev rules
First unplug Your phone.
1) Check how udev identify Your phone.
#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:
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).
Content of /etc/udev/rules.d/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.
Content of /usr/local/bin/adb_gps.helper:
Content of /usr/local/bin/adb_gps_usb.sh:
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.
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:
# sudo ./install.sh
Then unpack it and execute in terminal:# cd <Where You put it>/adb_gps_usb
Follow the Rabbit (may be white).
USER SOFTWARE AND UTILITIES WORKING WITH GPSD
There are some testing apps (cgps, xgps) shipped with gpsd.
For others Check gpsd home page