Class: Biscuit::Monitor::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/biscuit-monitor/poller.rb

Instance Method Summary collapse

Constructor Details

#initialize(device_ip, polling_frequency_in_seconds) ⇒ Poller

Returns a new instance of Poller.



6
7
8
9
# File 'lib/biscuit-monitor/poller.rb', line 6

def initialize(device_ip, polling_frequency_in_seconds)
  @device_ip = device_ip
  @polling_frequency_in_seconds = polling_frequency_in_seconds
end

Instance Method Details

#pollObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/biscuit-monitor/poller.rb', line 11

def poll
  until false
    begin

      ss = SignalStrength.new(@device_ip)
      @response = ss.exec

      message = ''
      message << ss.cinr
      message << ' '
      message << ss.rssi

      write message

      Thread.new do
        ap = AccessPointScanner.new
        ap.exec
        ap.found_access_points.each do |access_point|
          DB_CONN[:wi_fi_access_points].insert(access_point)
          LOGGER.debug(access_point)
        end
      end

      Thread.new(ss.response) do |sig_str|
        DB_CONN[:wi_max_statuses].insert(sig_str)
        LOGGER.debug(sig_str)
      end

    rescue Errno::EHOSTUNREACH => err

      write "Cannot find the biscuit. Check your connection. Tail #{LOG_FILE} for details."
      LOGGER.error(err.inspect)
      LOGGER.debug(@response.inspect)

    rescue StandardError => err

      write "There was an error talking to your biscuit. Tail #{LOG_FILE} for details."
      LOGGER.error(err.inspect)
      LOGGER.debug(@response.inspect)

    ensure

      sleep @polling_frequency_in_seconds # TODO when error increase length of time until next check to avoid spamming error log

    end
  end
end