class MqttData

Public Instance Methods

get_mqtt_temperature() click to toggle source
# File lib/mqtt_data.rb, line 10
def get_mqtt_temperature
    temperature_topic = 'softwareengineering/thermostat/s4nder/temperature'
    MQTT::Client.connect('mqtt.labict.be') do |client|
        while true
            client.get(temperature_topic) do |topic,message|
                parsed_temperature = JSON.parse(message)["temperature"]
                #client.publish('softwareengineering/thermostat/s4nder/led', '{"color": "FF0000"}', retain=false)
                @on_change_block.call(parsed_temperature.to_f) unless @on_change_block.nil?
            end
        end
    end
end
on_change(&block) click to toggle source
# File lib/mqtt_data.rb, line 6
def on_change &block
    @on_change_block = block
end
send_color_to_mqtt(color) click to toggle source
# File lib/mqtt_data.rb, line 23
def send_color_to_mqtt (color)
    temperature_topic = 'softwareengineering/thermostat/s4nder/temperature'
    client2 = MQTT::Client.connect('mqtt.labict.be')
    hash = {"color" => color}
    payload = JSON.generate(hash)
    client2.publish('softwareengineering/thermostat/s4nder/led', payload, retain=false)
end