Skip to content

Instantly share code, notes, and snippets.

@km4ack
Forked from psfleming/setgrid2.rb
Created April 20, 2019 13:30
Show Gist options
  • Save km4ack/1de2d977b02c75c32b20d6d592f5c877 to your computer and use it in GitHub Desktop.
Save km4ack/1de2d977b02c75c32b20d6d592f5c877 to your computer and use it in GitHub Desktop.
Set FT8Call gps grid using gpsd and api
require 'gpsd_client'
require 'maidenhead'
require 'socket'
require 'json'
ft8call_port = 2237
gpsd = GpsdClient::Gpsd.new()
gpsd.start()
apicmd = {}
# get maidenhead if gps is ready
if gpsd.started?
pos = gpsd.get_position
maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5)
puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}"
apicmd = {:type => "STATION.SET_GRID", :value => maid}
end
# send if we have data
Socket.udp_server_loop(ft8call_port) { |msg, msg_src|
if apicmd.length > 0 then
puts "Sending #{apicmd}"
msg_src.reply apicmd.to_json
break
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment