Skip to content

Instantly share code, notes, and snippets.

@olvap
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save olvap/9959542 to your computer and use it in GitHub Desktop.

Select an option

Save olvap/9959542 to your computer and use it in GitHub Desktop.
require 'json'
require 'mqtt'
class Command
attr_accessor :options, :response, :thread
def initialize
self.response = ""
end
def devices
send_json({ "CommuniqueType" => "ReadRequest",
"Header" => { "Url" => "/device" } }.to_json)
end
def send_json json
publish(json)
end
private
def conn_opts
{ remote_host: 'v3mqtt.xively.com',
username: 'd_htwowxg8mdiy_10912800',
password: 'e076a2a09e072e75eaea74e1211951241f5cb7b8' }
end
def publish_channel
"/v3/service_instances/1lfaato4fd86l/domains/htwowxg8mdiy/devices/10912800/queues/messagesOUT"
end
def publish json
MQTT::Client.connect(conn_opts) do |c|
c.publish(publish_channel, json.to_s)
end
end
end
command = Command.new()
puts command.devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment