Created
May 19, 2014 09:34
-
-
Save yoggy/05946f48ba483096a739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
# -*- encoding: utf-8 -*- | |
# | |
# $ gem install mqtt | |
# | |
require 'rubygems' | |
require 'mqtt' | |
require 'uri' | |
uri = URI.parse 'mqtt://localhost:1883' | |
conn_opts = { | |
remote_host: uri.host, | |
remote_port: uri.port, | |
username: uri.user, | |
password: uri.password, | |
} | |
MQTT::Client.connect(conn_opts) do |c| | |
c.publish('topic/message', 'こんにちは') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
# -*- encoding: utf-8 -*- | |
# | |
# $ gem install mqtt | |
# | |
require 'rubygems' | |
require 'mqtt' | |
require 'uri' | |
uri = URI.parse 'mqtt://localhost:1883' | |
conn_opts = { | |
remote_host: uri.host, | |
remote_port: uri.port, | |
username: uri.user, | |
password: uri.password, | |
} | |
MQTT::Client.connect(conn_opts) do |c| | |
puts "connect..." | |
c.get('#') do |topic, message| | |
puts "#{topic}: #{message}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment