diff --git a/src/MqttClass/MqttService.php b/src/MqttClass/MqttService.php index 687b65e..5fc39dd 100644 --- a/src/MqttClass/MqttService.php +++ b/src/MqttClass/MqttService.php @@ -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); } }