code cleanup

This commit is contained in:
Salman Zafar 2019-06-28 12:46:41 +05:00
parent 487c533750
commit d80df23ff9
1 changed files with 7 additions and 7 deletions

View File

@ -9,7 +9,7 @@
namespace Salman\Mqtt\MqttClass; namespace Salman\Mqtt\MqttClass;
/* /*
A simple php class to connect/publish to an MQTT broker A simple php class to connect/publish/Subscribe to an MQTT broker
*/ */
/* phpMQTT */ /* phpMQTT */
@ -18,13 +18,13 @@ class MqttService
{ {
private $socket; /* holds the socket */ private $socket; /* holds the socket */
private $msgid = 1; /* counter for message id */ private $msgid = 1; /* counter for message id */
public $keepalive = 10; /* default keepalive timmer */ public $keepalive = 10; /* default keepalive timer */
public $timesinceping; /* host unix time, used to detect disconects */ public $timesinceping; /* host unix time, used to detect disconnects */
public $topics = array(); /* used to store currently subscribed topics */ public $topics = array(); /* used to store currently subscribed topics */
public $debug = false; /* should output debug messages */ public $debug = false; /* should output debug messages */
public $address; /* broker address */ public $address; /* broker address */
public $port; /* broker port */ public $port; /* broker port */
public $clientid; /* client id sent to brocker */ public $clientid; /* client id sent to broker */
public $will; /* stores the will of the client */ public $will; /* stores the will of the client */
private $username; /* stores username */ private $username; /* stores username */
private $password; /* stores password */ private $password; /* stores password */
@ -181,7 +181,7 @@ class MqttService
if($this->debug) echo "ping sent\n"; if($this->debug) echo "ping sent\n";
} }
/* disconnect: sends a proper disconect cmd */ /* disconnect: sends a proper disconnect cmd */
function disconnect(){ function disconnect(){
$head = " "; $head = " ";
$head{0} = chr(0xe0); $head{0} = chr(0xe0);
@ -218,7 +218,7 @@ class MqttService
fwrite($this->socket, $buffer, $i); fwrite($this->socket, $buffer, $i);
} }
/* message: processes a recieved topic */ /* message: processes a received topic */
function message($msg){ function message($msg){
$tlen = (ord($msg{0})<<8) + ord($msg{1}); $tlen = (ord($msg{0})<<8) + ord($msg{1});
$topic = substr($msg,2,$tlen); $topic = substr($msg,2,$tlen);
@ -239,7 +239,7 @@ class MqttService
if($this->debug && !$found) echo "msg recieved but no match in subscriptions\n"; if($this->debug && !$found) echo "msg recieved but no match in subscriptions\n";
} }
/* proc: the processing loop for an "allways on" client /* proc: the processing loop for an "always on" client
set true when you are doing other stuff in the loop good for watching something else at the same time */ set true when you are doing other stuff in the loop good for watching something else at the same time */
function proc( $loop = true){ function proc( $loop = true){
if(1){ if(1){