Project

gpsd2json

0.0
No commit activity in last 3 years
No release in over 3 years
This gem can be used to talk to the gps daemon
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
>= 2.4.0, ~> 2.4
~> 12.0
>= 0
 Project Readme

gpsd2json

ruby client to receive JSON formatted info of the gps daemon

Setup

Make sure you have gpsd installed and you have of course a gps connected to your device

# Install
sudo apt-get install gpsd
# Check if your gps is available
cgps
# Install the gps2json gem
gem install gps2json

Usage

Start an irb session

irb
require 'gpsd2json'
gps = GPSD2JSON.new()

Set the callbacks on the position and satellite change events

gps.on_position_change { |pos| STDERR.puts "New position: #{pos.inpect}" }
gps.on_satellites_change { |sats| STDERR.puts "#{sats.count} found, #{sats.count{|sat| sat['used']} are used" }

Then, your start watching

gps.start

If you have the gps connected you should get the satelites callback first. It has to connect te the deamon and the deamon has to tell te gps to start dumping the data if it did not do so already, but this should be all done withing a second or so.

To get position change callbacks, the gps should have enough sattelites with a fix and the speed should be higher then the minimum speed, which defaults to 0.

You can stop watching with

gps.stop

There is also a on_raw_data callback you can use to see all data that is dumped by the deamon

gps.on_raw_data { |json| STDERR.puts json.inspect}

You can change the minimum speed requered to return a position change, with

gps.change_min_speed(speed: <whatever speed>)

Development

# Install
git clone git@github.com:mmolhoek/gpsd2json.git
cd gpsd2json
bundle
# irb
bundle exec irb -r ./lib/gpsd2json.rb
# test (with coverage to ./coverage/index.html)
bundle exec rspec --color -fd spec/gpsd_client_test.rb

Send me PR if you want changes, but only dare to do so when you added the proper tests and the overall coverage stays above 95%