class Reader
Public Class Methods
new()
click to toggle source
# File lib/file.rb, line 8 def initialize() end
Public Instance Methods
connect()
click to toggle source
# File lib/file.rb, line 30 def connect require "mqtt" temperature_topic = 'softwareengineering/temperature/mbed' MQTT::Client.connect('mqtt.labict.be') do |client| while true client.get(temperature_topic) do |topic,message| json = JSON.parse(message) $temperature = (json["temperature"]).to_f @on_change_block.call($temperature) unless @on_change_block.nil? #puts $temperature end end end end
get_temp(link)
click to toggle source
# File lib/file.rb, line 12 def get_temp(link) file = open(link) $temperature = file.read $temperature = $temperature.to_f end
on_change(&block)
click to toggle source
# File lib/file.rb, line 18 def on_change &block @on_change_block = block end
send(color)
click to toggle source
# File lib/file.rb, line 22 def send(color) require "mqtt" client2 = MQTT::Client.connect('mqtt.labict.be') data = {"color" => color} payload = JSON.generate(data) client2.publish('softwareengineering/thermostat/Nigga/led', payload, retain=false) end