Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. if( getenv("VCAP_SERVICES") ) {
  2.  
  3. echo "hello";
  4.  
  5. $services = getenv("VCAP_SERVICES");
  6. $services_json = json_decode($services, true);
  7. echo json_encode($services_json);
  8.  
  9. $mysql_config = $services_json["iotf-service"][0]["credentials"];
  10.  
  11. $org_id = $mysql_config["org"];
  12.  
  13.  
  14. $port = $mysql_config["mqtt_u_port"];
  15.  
  16.  
  17. $username = $mysql_config["apiKey"];
  18.  
  19.  
  20. $password = $mysql_config["apiToken"];
  21.  
  22. }
  23.  
  24. // set configuration values
  25. $config = array(
  26. 'org_id' => $org_id,
  27. 'port' => $port,
  28. 'app_id' => 'mymqttfinalservice',
  29. 'iotf_api_key' => $username,
  30. 'iotf_api_secret' => $password,
  31. 'device_id' => 'abcdef',
  32. 'qos' => 1
  33. );
  34.  
  35. $config['server'] = $config['org_id'] . '.messaging.internetofthings.ibmcloud.com';
  36.  
  37.  
  38. $config['client_id'] = 'a:' . $config['org_id'] . ':' . $config['app_id'];
  39. $location = array();
  40.  
  41.  
  42. // initialize client
  43. $mqtt = new phpMQTT($config['server'], $config['port'], $config['client_id']);
  44. $mqtt->debug = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement