PyMaemo/Python-GPSbt

[edit] Introduction

Python-GPSbt is a binding, based on libgpsbt, that provides access to GPS data through osso-gpsd. It only depends on a Bluetooth GPS device already paired. How it works

Libgpsbt allows to connect with Bluetooth GPS devices and uses osso-gpsd daemon to provide a socket where you can send/receive information.

After a gps.start() its possible to send commands (trhough query) and receive data from GPS. Almost all information acquired from socket is stored inside a structure called 'fix'. To fill it just call the get_fix(). It does a query to get all necessary information from GPS device.

To finish the Bluetooth connection just call the gps.stop() method, providing the context (returned by gps.start()). API

  • gpsbt.start - establishes a new GPS connection and returns a context. This one is is used to inform stop method what connection to be ended.
context = gps.start()
  • gpsbt.stop - ends an active connection, passed through the context. gps.stop(context)
  • gpsbt.gps() - the class that gets information from GPS. Through it its possible to query, get_fix, get_position, etc.
  • gpsbt.gps.get_fix() - fills in the 'fix' structure with GPS data. The fields are: mode, time, ept, latitude, longitude, eph, altitude (meters), epv, track (degrees from true north), speed (knots), climb (meters per second), epd, eps and epc.
  • gpsbt.gps.get_position() - its a shortcut to return (latitude, longitude) info.
  • gpsbt.gps.query() - allows user to send one letter commands to the GPS device. Its possible to group a sequence of commands to send, e.g.:
    • gpsbt.gps.query('a') fills in the altitude field of 'fix' structure
    • gpsbt.gps.query('as') fills in the altitude and speed fields
  • gpsbt.gps.satellites - contains a list of detected satellites, including information about usage and quality.

[edit] Example

The code below shows how to connect with a GPS device, get data and close this connection:

import gpsbt
import time
 
def main():
    context = gpsbt.start()
 
    if context == None:
        print 'Problem while connecting!'
        return
 
    # ensure that GPS device is ready to connect and to receive commands
    time.sleep(2)
    gpsdevice = gpsbt.gps()
 
    # read 3 times and show information
    for a in range(4):
        gpsdevice.get_fix()
        time.sleep(2)
 
        # print information stored under 'fix' variable
        print 'Altitude: %.3f'%gpsdevice.fix.altitude
        # dump all information available
        print gpsdevice
 
    # ends Bluetooth connection
    gpsbt.stop(context)
 
main()

Download source code here.