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
- device_type = "raspi"
- device_id = "12345"
- client_id = "d:#{org_id}:#{device_type}:#{device_id}"
- device_user = "use-token-auth"
- device_token = "*****"
- client = MQTT::Client.connect(
- :host => mqtt_host,
- :port => mqtt_port,
- :username => device_user,
- :password => device_token,
- :client_id => client_id
- )
- msg = JSON.generate({
- "d" => {
- "test_data" => 10
- }
- })
- event_id = "type01"
- format = "json"
- #EVENT TOPIC
- topic = "iot-2/evt/#{event_id}/fmt/#{format}"
- #COMMAND TOPIC
- #topic = "iot-2/cmd/#{command_id}/fmt/#{format}"
- client.publish(topic, msg)
- client.disconnect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement