class Transport

Public Instance Methods

get_connection() click to toggle source

this method will automatically subscribe through MQTT from an mbed

# File lib/transport.rb, line 6
def get_connection
    puts "MQTT:"
    temperature_topic = 'softwareengineering/thermostat/cfbnik/temperature'
    MQTT::Client.connect('mqtt.labict.be') do |client|
        while(true)
            client.get(temperature_topic) do |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
end
on_change(&block) click to toggle source
# File lib/transport.rb, line 21
def on_change &block
    @on_change_block = block
end
send_color(color) click to toggle source

this method will publish its value through MQTT to an mbed

# File lib/transport.rb, line 26
def send_color(color)
    connection = MQTT::Client.connect('mqtt.labict.be')
    my_hash = {"color" => color}
    payload = JSON.generate(my_hash) # convert my_hash to JSON
    connection.publish('softwareengineering/thermostat/cfbnik/led', payload, retain = false)
end