Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created May 19, 2014 09:34
Show Gist options
  • Save yoggy/05946f48ba483096a739 to your computer and use it in GitHub Desktop.
Save yoggy/05946f48ba483096a739 to your computer and use it in GitHub Desktop.
#!/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
#!/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