sexta-feira, 16 de outubro de 2009

How to connect a GPS phone to a Computer via bluetooth

A very quick post to show how these things work togheter. I connected a Nokia E71 GPS to my ThinkPad T61 running Ubuntu 9.04 Janty Jackalope using bluetooth connection. The initial idea was to use Google Earth as my main GPS screen while driving, but unfortunately I couldn't make it work *yet*.

Step 1) Going right to the point: First you need to be sure that you mobile phone exports the GPS service via bluetooth. And that's simple to get. First you must edit yout /etc/bluetooth/hcid.conf to look like this:

root@phoenix:/etc/bluetooth# cat hcid.conf
#
# HCI daemon configuration file.
#

# HCId options
options {
# Automatically initialize new devices
autoinit yes;

# Security Manager mode
# none - Security manager disabled
# auto - Use local PIN for incoming connections
# user - Always ask user for a PIN
#
security none;

# Pairing mode
# none - Pairing disabled
# multi - Allow pairing with already paired devices
# once - Pair once and deny successive attempts
pairing multi;

# PIN helper
#pin_helper /usr/bin/bluepin;

# D-Bus PIN helper
#dbus_pin_helper;
}

# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "otubotp";

# Local device class
class 0x3e0100;

# Default packet type
#pkt_type DH1,DM1,HV1;

# Inquiry and Page scan
iscan enable; pscan enable;

# Default link mode
# none - no specific policy
# accept - always accept incoming connections
# master - become master on incoming connections,
# deny role switch on outgoing connections
lm accept;

# Default link policy
# none - no specific policy
# rswitch - allow role switch
# hold - allow hold mode
# sniff - allow sniff mode
# park - allow park mode
lp rswitch,hold,sniff,park;

# Authentication and Encryption (Security Mode 3)
#auth enable;
#encrypt enable;
}


Step 2)
Restart you bluetooth daemon:

root@phoenix:~# /etc/init.d/bluetooth restart
* Stopping bluetooth [ OK ]
* Starting bluetooth [ OK ]


Step 3) Turn on the bluetooth on your phone and get ready to scan devices:

root@phoenix:~# hcitool scan
Scanning ...
00:21:FE:xx:xx:xx mycellphone


Step 4) Then, check if your phone exports GPS data via bluetooth running sdptool. In this step you need to pay attention to the Service Names and to the channel they use. We're gonna use these informations later on.

root@phoenix:~# sdptool browse 00:21:FE:F8:2F:E2
Browsing 00:21:FE:F8:2F:E2 ...
Service Name: AVRCP Target
Service Description: Audio Video Remote Control
Service Provider: Symbian Software Ltd.
Service RecHandle: 0x10000
Service Class ID List:
"AV Remote Target" (0x110c)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 23
"AVCTP" (0x0017)
uint16: 0x100
Profile Descriptor List:
"AV Remote" (0x110e)
Version: 0x0100

Service Name: Hands-Free Audio Gateway
Service RecHandle: 0x10004
Service Class ID List:
"Handsfree Audio Gateway" (0x111f)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Handsfree" (0x111e)
Version: 0x0105

Service Name: Headset Audio Gateway
Service RecHandle: 0x10005
Service Class ID List:
"Headset Audio Gateway" (0x1112)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 2
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Headset" (0x1108)
Version: 0x0100

Service Name: Audio Source
Service RecHandle: 0x10027
Service Class ID List:
"Audio Source" (0x110a)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 25
"AVDTP" (0x0019)
uint16: 0x100
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Advanced Audio" (0x110d)
Version: 0x0100

Service Name: AVRCP Controller
Service Description: Audio Video Remote Control
Service Provider: Symbian Software Ltd.
Service RecHandle: 0x10028
Service Class ID List:
"AV Remote" (0x110e)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 23
"AVCTP" (0x0017)
uint16: 0x100
Profile Descriptor List:
"AV Remote" (0x110e)
Version: 0x0100

Service Name: SyncMLClient
Service RecHandle: 0x10029
Service Class ID List:
UUID 128: 00000002-0000-1000-8000-0002ee000002
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 10
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"" (0x00000002-0000-1000-8000-0002ee000002)
Version: 0x0100

Service Name: OBEX File Transfer
Service RecHandle: 0x1002a
Service Class ID List:
"OBEX File Transfer" (0x1106)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 11
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX File Transfer" (0x1106)
Version: 0x0100

Service Name: Nokia OBEX PC Suite Services
Service RecHandle: 0x1002b
Service Class ID List:
UUID 128: 00005005-0000-1000-8000-0002ee000001
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 12
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"" (0x00005005-0000-1000-8000-0002ee000001)
Version: 0x0100

Service Name: SyncML DM Client
Service RecHandle: 0x1002c
Service Class ID List:
UUID 128: 00000004-0000-1000-8000-0002ee000002
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 13
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"" (0x00000004-0000-1000-8000-0002ee000002)
Version: 0x0100

Service Name: Nokia SyncML Server
Service RecHandle: 0x1002e
Service Class ID List:
UUID 128: 00005601-0000-1000-8000-0002ee000001
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 14
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"" (0x00005601-0000-1000-8000-0002ee000001)
Version: 0x0100

Service RecHandle: 0x1002f
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 3

Service Name: Dial-Up Networking
Service RecHandle: 0x10030
Service Class ID List:
"Dialup Networking" (0x1103)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 4
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Dialup Networking" (0x1103)
Version: 0x0100

Service Name: OBEX Object Push
Service RecHandle: 0x10031
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 9
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100

Service Name: Imaging
Service RecHandle: 0x10032
Service Class ID List:
"Imaging Responder" (0x111b)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 15
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Imaging" (0x111a)
Version: 0x0100

Service Name: SIM Access
Service RecHandle: 0x10033
Service Class ID List:
"SIM Access" (0x112d)
"Generic Telephony" (0x1204)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 8
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"SIM Access" (0x112d)
Version: 0x0101

All you need to check on this huge amount of data is something telling that you phone exports the GPS information. In the above example there is no such thing. If your phone DOES support this information go to step 5. Otherwise, install this strategic application for Symbian: ExtGSP. This little tricky app will do all the messy thing for you exporting all the GPS data over the bluetooth connection. Then re-run the sdptool command again to check. In the end you will find additional information about ExtGPS:

Service Name: Symarctic ExtGPS
Service Description: Share phone's built-in GPS module via Bluetooth
Service Provider: Symarctic Solutions
Service RecHandle: 0x10034
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 5
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100


Step 5) Then, edit your /etc/bluetooth/rfcomm.conf and make it look like this:

root@phoenix:~# cat /etc/bluetooth/rfcomm.conf
rfcomm4 {
bind yes;
device 00:21:FE:F8:2F:E2;
channel 5;
comment "Serial Port";
}


Step 6) Once configured (and ExtGPS running on your phone) you will now open a communication channel and bind it to a local device like this:

root@phoenix:~# rfcomm connect 4
Connected /dev/rfcomm4 to 00:21:FE:F8:2F:E2 on channel 5
Press CTRL-C for hangup


Step 7) Now there's a bunch of GPS information being written on /dev/rfcomm4. In order to make a good use of it, we should grad all these information, and parse it with gpsd:

root@phoenix:~# gpsd -N /dev/rfcomm4
(-N means not to daemonize it, to see all the debug info.)



What's next? Now we have all the setup ready: Cellphone with GPS up and running, exporting information via bluetooth (using ExtGPS), connected and writing information on a local device, and a daemon grabing and parsing all the information. Good! We just need a client program to enjoy the show:

Step 8) You can use a bunch of client programs, I've tested two of them: Xgps and GpsDrive.
Xpgs is a very simple program just to make sure things are working fine. It shows the position of satelites, the current position and so on. Here is a print screen:


GPSDrive is more Google-Earth-like, you may track you path during a travel, check the map and so on:


Well, that's it. Hope you enjoy :)

Um comentário:

Unknown disse...

Thanks for this tutorial! It's very useful for me!