Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'mqtt'
  4. require 'json'
  5.  
  6. org_id = "*****"
  7. mqtt_host = "#{org_id}.messaging.internetofthings.ibmcloud.com"
  8. mqtt_port = 1883
  9.  
  10. device_type = "raspi"
  11. device_id = "12345"
  12. client_id = "d:#{org_id}:#{device_type}:#{device_id}"
  13.  
  14. device_user = "use-token-auth"
  15. device_token = "*****"
  16.  
  17. client = MQTT::Client.connect(
  18. :host => mqtt_host,
  19. :port => mqtt_port,
  20. :username => device_user,
  21. :password => device_token,
  22. :client_id => client_id
  23. )
  24.  
  25. msg = JSON.generate({
  26. "d" => {
  27. "test_data" => 10
  28. }
  29. })
  30.  
  31. event_id = "type01"
  32. format = "json"
  33.  
  34. #EVENT TOPIC
  35. topic = "iot-2/evt/#{event_id}/fmt/#{format}"
  36.  
  37. #COMMAND TOPIC
  38. #topic = "iot-2/cmd/#{command_id}/fmt/#{format}"
  39.  
  40. client.publish(topic, msg)
  41. client.disconnect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement