Class: MQTTP
- Inherits:
-
Object
- Object
- MQTTP
- Defined in:
- lib/mqttp.rb
Instance Method Summary collapse
Instance Method Details
#get ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mqttp.rb', line 2 def get puts "MQTT:" temperature_topic = 'softwareengineering/thermostat/repsaj/temperature' MQTT::Client.connect('mqtt.labict.be') do |client| while true client.get(temperature_topic) do |topic,| cJson = cHash = JSON.parse(cJson) cTemp = (cHash["temperature"]).to_f @on_change_block.call(cTemp) unless @on_change_block.nil? end end end end |
#on_change(&block) ⇒ Object
17 18 19 |
# File 'lib/mqttp.rb', line 17 def on_change &block @on_change_block = block end |
#send(color) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/mqttp.rb', line 21 def send(color) client2 = MQTT::Client.connect('mqtt.labict.be') my_hash = {"color" => color} payload = JSON.generate(my_hash) client2.publish('softwareengineering/thermostat/repsaj/led', payload, retain=false) end |