Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require("phpMQTT.php");
- $host = "trin";
- $port = "1883";
- $username = "js_client";
- $password = "AQXH9TobPmr479z";
- $topic = "ring";
- $file = '/tmp/ifttt.txt';
- $arr = get_defined_vars();
- $data = json_encode($arr,JSON_PRETTY_PRINT);
- $thing = $_GET['thing'];
- $time = $_GET['time'];
- $kind = $_GET['kind'];
- # Write it out all the vars to a log file just
- # for debugging and checking what is going on.
- $current = file_get_contents($file);
- $current .= $data . "\n";
- file_put_contents($file, $current);
- # If its the doorbell (only ting supported right now) then
- # publish a simple JSON message to MQTT
- if ( $thing == "doorbell" ){
- $message = [
- "kind" => $kind,
- "time" => $time
- ];
- $mqtt = new phpMQTT($host, $port, "iftt.php".rand());
- if ($mqtt->connect(true, NULL, $username, $password)) {
- $mqtt->publish($topic, json_encode($message), 0, true);
- $mqtt->close();
- }
- }
- ?>
- <html>
- <body>
- <pre>
- <?php
- # print out all returned data for debugging
- print $data;
- ?>
- </pre>
- </pre>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement