Working on subscribing part

This commit is contained in:
Salman Zafar 2019-06-11 18:59:06 +05:00
parent 5e3a90ca14
commit d0a6435139
1 changed files with 20 additions and 0 deletions

View File

@ -69,5 +69,25 @@ class Mqtt
}
public function ConnectAndSubscribe($topic, $proc)
{
$client = new MqttService($this->host,$this->port, rand(0,100), $this->cert_file, $this->debug);
if ($client->connect(true, null, $this->username, $this->password))
{
$topics[$topic] = array("qos" => 0, "function" => $proc);
$client->subscribe($topics, 0);
while($client->proc())
{
}
$client->close();
}
return false;
}
}