Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <?php
  2.  
  3. require("phpMQTT.php");
  4.  
  5. $host = "trin";
  6. $port = "1883";
  7. $username = "js_client";
  8. $password = "AQXH9TobPmr479z";
  9. $topic = "ring";
  10.  
  11. $file = '/tmp/ifttt.txt';
  12. $arr = get_defined_vars();
  13.  
  14. $data = json_encode($arr,JSON_PRETTY_PRINT);
  15.  
  16. $thing = $_GET['thing'];
  17. $time = $_GET['time'];
  18. $kind = $_GET['kind'];
  19.  
  20. # Write it out all the vars to a log file just
  21. # for debugging and checking what is going on.
  22. $current = file_get_contents($file);
  23. $current .= $data . "\n";
  24. file_put_contents($file, $current);
  25.  
  26.  
  27. # If its the doorbell (only ting supported right now) then
  28. # publish a simple JSON message to MQTT
  29. if ( $thing == "doorbell" ){
  30.  
  31. $message = [
  32. "kind" => $kind,
  33. "time" => $time
  34. ];
  35.  
  36. $mqtt = new phpMQTT($host, $port, "iftt.php".rand());
  37.  
  38. if ($mqtt->connect(true, NULL, $username, $password)) {
  39. $mqtt->publish($topic, json_encode($message), 0, true);
  40. $mqtt->close();
  41. }
  42. }
  43.  
  44. ?>
  45. <html>
  46. <body>
  47. <pre>
  48. <?php
  49. # print out all returned data for debugging
  50. print $data;
  51. ?>
  52. </pre>
  53.  
  54. </pre>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement