Skip to content

Instantly share code, notes, and snippets.

@yukirii
Created August 14, 2016 07:59
Show Gist options
  • Select an option

  • Save yukirii/e7201cbc980138e254e515e6e89fd7b3 to your computer and use it in GitHub Desktop.

Select an option

Save yukirii/e7201cbc980138e254e515e6e89fd7b3 to your computer and use it in GitHub Desktop.

Revisions

  1. Yuki KIRII created this gist Aug 14, 2016.
    12 changes: 12 additions & 0 deletions mqtt_subscriber_example.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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