Compare commits
4 Commits
developmen
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
9addc4bf7f | |
|
|
e267d30f75 | |
|
|
794934bc62 | |
|
|
5ec057142d |
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "salmanzafar/laravel-mqtt",
|
||||
"description": "A simple Laravel 5 and 8 Library to connect/publish/subscribe to MQTT broker",
|
||||
"name": "salmanzafar-chenc/laravel-mqtt",
|
||||
"description": "A simple Laravel 5 and 6 Library to connect/publish/subscribe to MQTT broker",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
|
|
|
|||
|
|
@ -107,16 +107,16 @@ class MqttService
|
|||
if($this->username) $buffer .= $this->strwritestring($this->username,$i);
|
||||
if($this->password) $buffer .= $this->strwritestring($this->password,$i);
|
||||
$head = " ";
|
||||
$head{0} = chr(0x10);
|
||||
$head{1} = chr($i);
|
||||
$head[0] = chr(0x10);
|
||||
$head[1] = chr($i);
|
||||
fwrite($this->socket, $head, 2);
|
||||
fwrite($this->socket, $buffer);
|
||||
$string = $this->read(4);
|
||||
if(ord($string{0})>>4 == 2 && $string{3} == chr(0)){
|
||||
if(ord($string[0])>>4 == 2 && $string[3] == chr(0)){
|
||||
if($this->debug) echo "Connected to Broker\n";
|
||||
}else{
|
||||
error_log(sprintf("Connection failed! (Error: 0x%02x 0x%02x)\n",
|
||||
ord($string{0}),ord($string{3})));
|
||||
ord($string[0]),ord($string[3])));
|
||||
return false;
|
||||
}
|
||||
$this->timesinceping = time();
|
||||
|
|
@ -184,8 +184,8 @@ class MqttService
|
|||
/* disconnect: sends a proper disconnect cmd */
|
||||
function disconnect(){
|
||||
$head = " ";
|
||||
$head{0} = chr(0xe0);
|
||||
$head{1} = chr(0x00);
|
||||
$head[0] = chr(0xe0);
|
||||
$head[1] = chr(0x00);
|
||||
fwrite($this->socket, $head, 2);
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ class MqttService
|
|||
$cmd = 0x30;
|
||||
if($qos) $cmd += $qos << 1;
|
||||
if($retain) $cmd += 1;
|
||||
$head{0} = chr($cmd);
|
||||
$head[0] = chr($cmd);
|
||||
$head .= $this->setmsglength($i);
|
||||
fwrite($this->socket, $head, strlen($head));
|
||||
fwrite($this->socket, $buffer, $i);
|
||||
|
|
@ -220,7 +220,7 @@ class MqttService
|
|||
|
||||
/* message: processes a received topic */
|
||||
function message($msg){
|
||||
$tlen = (ord($msg{0})<<8) + ord($msg{1});
|
||||
$tlen = (ord($msg[0])<<8) + ord($msg[1]);
|
||||
$topic = substr($msg,2,$tlen);
|
||||
$msg = substr($msg,($tlen+2));
|
||||
$found = 0;
|
||||
|
|
@ -309,7 +309,7 @@ class MqttService
|
|||
$multiplier = 1;
|
||||
$value = 0 ;
|
||||
do{
|
||||
$digit = ord($msg{$i});
|
||||
$digit = ord($msg[$i]);
|
||||
$value += ($digit & 127) * $multiplier;
|
||||
$multiplier *= 128;
|
||||
$i++;
|
||||
|
|
@ -347,9 +347,9 @@ class MqttService
|
|||
function printstr($string){
|
||||
$strlen = strlen($string);
|
||||
for($j=0;$j<$strlen;$j++){
|
||||
$num = ord($string{$j});
|
||||
$num = ord($string[$j]);
|
||||
if($num > 31)
|
||||
$chr = $string{$j}; else $chr = " ";
|
||||
$chr = $string[$j]; else $chr = " ";
|
||||
printf("%4d: %08b : 0x%02x : %s \n",$j,$num,$num,$chr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue