|
3 | 3 | * Implementation of MQTT 3.1.1 for PHP with SSL support
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -namespace karpy47/php-mqtt-client; |
| 6 | +namespace pascalwacker\PHPMqttClient; |
7 | 7 |
|
8 | 8 | class MQTTClient {
|
9 | 9 |
|
@@ -79,9 +79,7 @@ class MQTTClient {
|
79 | 79 | * @param string $protocol Which protocol to use
|
80 | 80 | */
|
81 | 81 | function __construct($address, $port=null, $protocol='tcp'){
|
82 |
| - if ($this->setConnection($address, $port, $protocol)) { |
83 |
| - ; |
84 |
| - } |
| 82 | + $this->setConnection($address, $port, $protocol); |
85 | 83 | $this->packetId = rand(1,100)*100; // Reduce risk of creating duplicate ids in sequential sessions
|
86 | 84 | }
|
87 | 85 |
|
@@ -225,11 +223,11 @@ public function sendConnect($clientId, $cleanSession=false, $keepAlive=10, $time
|
225 | 223 | // Basic validation of clientid
|
226 | 224 | if(preg_match("/[^0-9a-zA-Z]/",$clientId)) {
|
227 | 225 | $this->debugMessage('ClientId can only contain characters 0-9,a-z,A-Z');
|
228 |
| - return; |
| 226 | + return false; |
229 | 227 | }
|
230 | 228 | if(strlen($clientId) > 23) {
|
231 | 229 | $this->debugMessage('ClientId max length is 23 characters/numbers');
|
232 |
| - return; |
| 230 | + return false; |
233 | 231 | }
|
234 | 232 | $this->clientId = $clientId;
|
235 | 233 |
|
@@ -331,7 +329,7 @@ public function sendConnect($clientId, $cleanSession=false, $keepAlive=10, $time
|
331 | 329 | $connectFlags = 0;
|
332 | 330 | if ($this->connectCleanSession) $connectFlags += 0x02;
|
333 | 331 | if ($this->connectWill) {
|
334 |
| - $connectflags += 0x04; |
| 332 | + $connectFlags += 0x04; |
335 | 333 | if ($this->connectWillQos) $connectFlags += ($this->connectWill << 3);
|
336 | 334 | if ($this->connectWillRetain) $connectFlags += 0x20;
|
337 | 335 | }
|
@@ -392,7 +390,7 @@ public function sendConnect($clientId, $cleanSession=false, $keepAlive=10, $time
|
392 | 390 | public function sendPublish($topic, $message, $qos = self::MQTT_QOS1) {
|
393 | 391 | if(!$this->isConnected()) return false;
|
394 | 392 |
|
395 |
| - if($qos!=self::MQTT_QOS0 && $qos!=self::MQTT_QOS1) return false; |
| 393 | + if(!in_array($qos, array(self::MQTT_QOS0, self::MQTT_QOS1, self::MQTT_QOS2))) return false; |
396 | 394 |
|
397 | 395 | $packetId = $this->getNextPacketId();
|
398 | 396 | $payload = $this->createPayload($topic);
|
@@ -424,7 +422,8 @@ public function sendPublish($topic, $message, $qos = self::MQTT_QOS1) {
|
424 | 422 | }
|
425 | 423 |
|
426 | 424 | // Send PUBREL
|
427 |
| - $this->sendPubRel($receivedPacketId); |
| 425 | + // TODO: find $receivedPacketId |
| 426 | + //$this->sendPubRel($receivedPacketId); |
428 | 427 |
|
429 | 428 | // A PUBCOMP packet is expected
|
430 | 429 | $response = $this->waitForPacket(self::MQTT_PUBCOMP, $packetId);
|
@@ -598,11 +597,12 @@ public function sendPing() {
|
598 | 597 | $this->pingReqTime = time();
|
599 | 598 |
|
600 | 599 | // A PINGRESP packet is expected
|
601 |
| - $response = waitForPacket(self::MQTT_PINGRESP); |
602 |
| - if($responseHeader === false) { |
| 600 | + $response = $this->waitForPacket(self::MQTT_PINGRESP); |
| 601 | + // TODO: get $responseHeader out of response |
| 602 | + /*if($responseHeader === false) { |
603 | 603 | $this->debugMessage('Invalid packet received, expecting PINGRESP');
|
604 | 604 | return false;
|
605 |
| - } |
| 605 | + }*/ |
606 | 606 |
|
607 | 607 | return true;
|
608 | 608 | }
|
|
0 commit comments