-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea33371
commit 7a9d6b2
Showing
5 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
<?php | ||
|
||
require("../phpMQTT.php"); | ||
require('../phpMQTT.php'); | ||
|
||
|
||
$server = "localhost"; // change if necessary | ||
$server = 'localhost'; // change if necessary | ||
$port = 1883; // change if necessary | ||
$username = ""; // set your username | ||
$password = ""; // set your password | ||
$client_id = "phpMQTT-subscriber"; // make sure this is unique for connecting to sever - you could use uniqid() | ||
$username = ''; // set your username | ||
$password = ''; // set your password | ||
$client_id = 'phpMQTT-subscriber'; // make sure this is unique for connecting to sever - you could use uniqid() | ||
|
||
$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id); | ||
if(!$mqtt->connect(true, NULL, $username, $password)) { | ||
exit(1); | ||
} | ||
|
||
$topics['bluerhinos/phpMQTT/examples/publishtest'] = array("qos" => 0, "function" => "procmsg"); | ||
$mqtt->debug = true; | ||
|
||
$topics['bluerhinos/phpMQTT/examples/publishtest'] = array('qos' => 0, 'function' => 'procMsg'); | ||
$mqtt->subscribe($topics, 0); | ||
|
||
while($mqtt->proc()){ | ||
|
||
} | ||
while($mqtt->proc()) { | ||
|
||
} | ||
|
||
$mqtt->close(); | ||
|
||
function procmsg($topic, $msg){ | ||
echo "Msg Recieved: " . date("r") . "\n"; | ||
function procMsg($topic, $msg){ | ||
echo 'Msg Recieved: ' . date('r') . "\n"; | ||
echo "Topic: {$topic}\n\n"; | ||
echo "\t$msg\n\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require('../phpMQTT.php'); | ||
|
||
$server = 'localhost'; // change if necessary | ||
$port = 1883; // change if necessary | ||
$username = ''; // set your username | ||
$password = ''; // set your password | ||
$client_id = 'phpMQTT-subscribe-msg'; // make sure this is unique for connecting to sever - you could use uniqid() | ||
|
||
$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id); | ||
if(!$mqtt->connect(true, NULL, $username, $password)) { | ||
exit(1); | ||
} | ||
|
||
echo $mqtt->subscribeAndWaitForMessage('bluerhinos/phpMQTT/examples/publishtest', 0); | ||
|
||
$mqtt->close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters