Skip to content

Commit

Permalink
PHP 8+ compatibility updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sktaylortrash committed Jan 28, 2023
1 parent d0e4e2a commit 3f56a1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
MQTT Services - Broker connections settings for subscribing and publishing
*/
$ENABLE_MQTT = 1; // Enable MQTT State Publishing (1 = true, 0 = false)
$MQTTserver = "172.16.33.8"; // Change as necessary
$MQTTserver = "192.168.1.MQTT"; // Change as necessary
$MQTTport = 1883; // Change as necessary
$MQTTusername = "admin"; // Set your username
$MQTTusername = "username"; // Set your username
$MQTTpassword = "password"; // set your password
$MQTTsub_id = "tcp-subscriber"; // Make sure this is unique for connecting to server - you could use uniqid()
$MQTTpub_id = "tcp-publisher"; // Make sure this is unique for connecting to server - you could use uniqid()
Expand Down
3 changes: 2 additions & 1 deletion include.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function getCurlReturn($postDataString){
}

//This may be required if you encounter an error that your openssl dh key is too small error
// curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT:!DH');
//Also appears to be required for PHP 8+
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT:!DH');



Expand Down
2 changes: 1 addition & 1 deletion mqttdiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
$unplugged = 0;
$roomBrightness = 0;
$roomDevices = 0;
if ($mqtt->connect(true, retain, $MQTTusername, $MQTTpassword)) {
if ($mqtt->connect(true, NULL, $MQTTusername, $MQTTpassword)) {
foreach($DEVICES as $device){
$DeviceName = str_replace(' ', '', $device['name']);
$DeviceCommand = $RoomName."/".$DeviceName."/".$device['did'];
Expand Down
2 changes: 1 addition & 1 deletion mqttstate.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$unplugged = 0;
$roomBrightness = 0;
$roomDevices = 0;
if ($mqtt->connect(true, retain, $MQTTusername, $MQTTpassword)) {
if ($mqtt->connect(true, NULL, $MQTTusername, $MQTTpassword)) {
foreach($DEVICES as $device){
$DeviceName = str_replace(' ', '', $device['name']);
if( isset($device['offline']) && $device['offline'] == 1){ $LWT = "offline"; } else {$LWT = "online";}
Expand Down
24 changes: 12 additions & 12 deletions phpMQTT/phpMQTT.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ function connect($clean = true, $will = NULL, $username = NULL, $password = NULL
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[0])));
return false;
}

Expand Down Expand Up @@ -230,8 +230,8 @@ function ping(){
/* disconnect: sends a proper disconect 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);
}

Expand Down Expand Up @@ -266,7 +266,7 @@ function publish($topic, $content, $qos = 0, $retain = 1){
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));
Expand Down Expand Up @@ -299,7 +299,7 @@ function publishnoretain($topic, $content, $qos = 0, $retain = 0){
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));
Expand All @@ -311,7 +311,7 @@ function publishnoretain($topic, $content, $qos = 0, $retain = 0){

/* message: processes a recieved 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;
Expand Down Expand Up @@ -409,7 +409,7 @@ function getmsglength(&$msg, &$i){
$multiplier = 1;
$value = 0 ;
do{
$digit = ord($msg{$i});
$digit = ord($msg[$i]);
$value += ($digit & 127) * $multiplier;
$multiplier *= 128;
$i++;
Expand Down Expand Up @@ -449,9 +449,9 @@ function strwritestring($str, &$i){
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);
}
}
Expand Down

0 comments on commit 3f56a1b

Please sign in to comment.