Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'mqtt'
- require 'json'
- org_id = "*****"
- mqtt_host = "#{org_id}.messaging.internetofthings.ibmcloud.com"
- mqtt_port = 1883
- service_api_key = "*****"
- service_token = "*****"
- device_type = "raspi"
- device_id = "12345"
- app_id = "shinya"
- client_id = "a:#{org_id}:#{app_id}"
- client = MQTT::Client.connect(
- :host => mqtt_host,
- :port => mqtt_port,
- :username => service_api_key,
- :password => service_token,
- :client_id => client_id
- )
- event_id = "type01"
- format = "json"
- # EVENT TOPIC
- topic = "iot-2/type/#{device_type}/id/#{device_id}/evt/#{event_id}/fmt/#{format}"
- #topic = "iot-2/type/#{device_type}/id/+/evt/#{event_id}/fmt/#{format}"
- #COMMAND TOPIC
- #topic = "iot-2/type/#{device_type}/id/#{device_id}/cmd/#{command_id}/fmt/#{format}"
- client.subscribe(topic)
- client.get do |topic,message|
- # Block is executed for every message received
- p topic
- p message
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement