GPSd with Ruby


GPSd is a Linux daemon that can read and parse data from various GPS recievers, and it provides a standard interface for obtaining said data. GPSd provides JSON data over a socket connection in an easy to consume stream. In this example, I'm going to read the data with and parse it with Ruby bindings to yajl. brings events like Node.js to Ruby with the simplicity of Sinatra. Yajl, on the other hand, is a streaming JSON parser that's fast and reliable.

First, install the required gems:

$ (sudo) gem install yajl-ruby
$ (sudo) gem install


require 'rubygems'
require ''
require 'yajl'

ADDR = ''
PORT = 2947

print = lambda { |data| puts data.inspect }
parser =
parser.on_parse_complete = print ADDR, PORT do
    on_connect do
        puts "Connected"
        write "?WATCH={\"enable\":true,\"json\":true}"

    on_read do |data|
        parser << data

puts "Running"

blog comments powered by Disqus