class TemperatureReader

Attributes

temp[R]

Public Class Methods

new() click to toggle source
# File lib/temperature_reader.rb, line 13
def initialize
        @temp = 0
end

Public Instance Methods

cmdline_temperature(temp) click to toggle source
# File lib/temperature_reader.rb, line 17
def cmdline_temperature temp
        TemperaturePrinter.print(temp.to_f)
end
file_temperature(path) click to toggle source
# File lib/temperature_reader.rb, line 21
def file_temperature path
        @path = path
        temp = File.read(path).to_f
        TemperaturePrinter.print(temp)
end
open_url(url) click to toggle source
# File lib/temperature_reader.rb, line 32
def open_url(url)
        Net::HTTP.get(URI.parse(url))
end
ttn_reader(ttn_host, port, username, password, sensor_id) click to toggle source
# File lib/temperature_reader.rb, line 36
def ttn_reader (ttn_host, port, username, password, sensor_id)
        # Subscribe example
        MQTT::Client.connect(
        :host => ttn_host,
        :port => port,
        :username => username,
        :password => password) do |c|
          # If you pass a block to the get method, then it will loop
          c.get(sensor_id) do |topic,message|
                                        obj = JSON.parse("#{message}")
                                        temp = obj['fields']['temperature'].to_f
                                        TemperaturePrinter.print(temp)
                                        puts '.....................................................................'
          end
        end
end
url_temperature(url) click to toggle source
# File lib/temperature_reader.rb, line 27
def url_temperature url
        temp = Net::HTTP.get(URI.parse(url)).to_f
        TemperaturePrinter.print(temp)
end