Skip to content

Instantly share code, notes, and snippets.

@yukirii
Created August 14, 2016 07:59
Show Gist options
  • Save yukirii/e7201cbc980138e254e515e6e89fd7b3 to your computer and use it in GitHub Desktop.
Save yukirii/e7201cbc980138e254e515e6e89fd7b3 to your computer and use it in GitHub Desktop.
mqtt_subscriber_example
require 'mqtt'
require 'json'
HOST = '192.168.x.x'
PORT = 1883
MQTT::Client.connect(remote_host: HOST, remote_port: PORT, username: 'test', password: 'test') do |client|
client.get('test') do |topic, message|
data = JSON.parse(message)
puts "#{topic}: #{data}.class = #{data.class}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment