Skip to content

Commit

Permalink
update mqtt client
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Apr 14, 2020
1 parent 050543a commit ff7a4bc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Client/MQTTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(array $config)
public function connect(bool $clean = true, array $will = [])
{
$data = [
'cmd' => 1,
'cmd' => MQTT::CONNECT, // 1
'protocol_name' => 'MQTT',
'protocol_level' => 4,
'clean_session' => $clean ? 0 : 1,
Expand Down Expand Up @@ -76,7 +76,7 @@ public function connect(bool $clean = true, array $will = [])
public function subscribe(array $topics)
{
$data = [
'cmd' => 8,
'cmd' => MQTT::SUBSCRIBE, // 8
'message_id' => $this->getMsgId(),
'topics' => $topics,
];
Expand All @@ -92,7 +92,7 @@ public function subscribe(array $topics)
public function unSubscribe(array $topics)
{
$data = [
'cmd' => 10,
'cmd' => MQTT::UNSUBSCRIBE, // 10
'message_id' => $this->getMsgId(),
'topics' => $topics,
];
Expand All @@ -113,7 +113,7 @@ public function publish($topic, $content, $qos = 0, $dup = 0, $retain = 0)
{
$response = ($qos > 0) ? true : false;
return $this->sendBuffer([
'cmd' => 3,
'cmd' => MQTT::PUBLISH, // 3
'message_id' => $this->getMsgId(),
'topic' => $topic,
'content' => $content,
Expand All @@ -138,7 +138,7 @@ public function recv()
$this->reConnect();
return true;
}
return Mqtt::decode($response);
return MQTT::decode($response);
}

/**
Expand All @@ -148,7 +148,7 @@ public function recv()
*/
public function ping()
{
return $this->sendBuffer(['cmd' => 12]);
return $this->sendBuffer(['cmd' => MQTT::PINGREQ]); // 12
}

/**
Expand All @@ -158,7 +158,7 @@ public function ping()
*/
public function close()
{
return $this->sendBuffer(['cmd' => 14]);
return $this->sendBuffer(['cmd' => MQTT::DISCONNECT]); // 14
}

/**
Expand All @@ -180,11 +180,11 @@ public function getMsgId()
*/
private function sendBuffer($data, $response = true)
{
$buffer = Mqtt::encode($data);
$buffer = MQTT::encode($data);
$this->client->send($buffer);
if ($response) {
$response = $this->client->recv();
return Mqtt::decode($response);
return MQTT::decode($response);
}
return true;
}
Expand Down

0 comments on commit ff7a4bc

Please sign in to comment.