class HumbleRPiPluginLd3W

Public Class Methods

new(settings: {}, variables: {}, debug: false) click to toggle source
# File lib/humble_rpi-plugin-ld3w.rb, line 13
def initialize(settings: {}, variables: {}, debug: false)

  h = {rfdevice: 'rfcomm0', bdaddress: '', channel: '1', 
       refresh_rate: 120}.merge settings
  @device_id = variables[:device_id] || 'pi'
  @debug, @h, @notifier = debug, h, variables[:notifier]

  @ld3w = Ld3w.new device: h[:rfdevice], bdaddress: h[:bdaddress], 
      channel: h[:channel], verbose: false, affirmations: 5
  
end

Public Instance Methods

on_start()
Alias for: start
start() click to toggle source
# File lib/humble_rpi-plugin-ld3w.rb, line 25
def start()          
      
  begin
    
    loc = @ld3w.locate        
    puts ('loc: ' + loc.inspect).debug if @debug
    located = loc.is_a?(Array) ? loc.last : loc
    @notifier.notice "%s/gps: lat: %s lon: %s" % 
                          [@device_id,  located.latitude, located.longitude]
    sleep(@h[:refresh_rate])                                    
  rescue
    
    @notifier.notice "%s/gps/warning: %s" % [@device_id, 
                                              'unable to connect']
    `service bluetooth restart`
    sleep 6
    
  end 
  

  start()

end
Also aliased as: on_start