class MqttReader
Public Instance Methods
get_temp()
click to toggle source
# File lib/mqtt.rb, line 5 def get_temp client = MQTT::Client.new client.host = 'mqtt.labict.be' client.connect() temperature_topic ='softwareengineering/thermostat/enzo/temperature' while true client.get(temperature_topic) do |topic,message| puts "#{topic}: #{message}" json = message hash = JSON.parse(json) temp = (hash["temperature"]).to_f @on_change_block.call(temp) unless @on_change_block.nil? end end end
on_change(&block)
click to toggle source
# File lib/mqtt.rb, line 22 def on_change &block @on_change_block = block end
send(color)
click to toggle source
# File lib/mqtt.rb, line 26 def send(color) client = MQTT::Client.connect('mqtt.labict.be') hash2 = {"color" => color} payload = JSON.generate(hash2) client.publish('softwareengineering/thermostat/enzo/led', payload, retain = false) end