diff --git a/src/Client/MQTTClient.php b/src/Client/MQTTClient.php index f7a5850..caa4ace 100644 --- a/src/Client/MQTTClient.php +++ b/src/Client/MQTTClient.php @@ -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, @@ -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, ]; @@ -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, ]; @@ -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, @@ -138,7 +138,7 @@ public function recv() $this->reConnect(); return true; } - return Mqtt::decode($response); + return MQTT::decode($response); } /** @@ -148,7 +148,7 @@ public function recv() */ public function ping() { - return $this->sendBuffer(['cmd' => 12]); + return $this->sendBuffer(['cmd' => MQTT::PINGREQ]); // 12 } /** @@ -158,7 +158,7 @@ public function ping() */ public function close() { - return $this->sendBuffer(['cmd' => 14]); + return $this->sendBuffer(['cmd' => MQTT::DISCONNECT]); // 14 } /** @@ -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; }