Exemplo n.º 1
0
 protected function payload()
 {
     if (empty($this->topics)) {
         /*
         The Topic Filters in an UNSUBSCRIBE packet MUST be UTF-8 encoded strings as
         defined in Section 1.5.3, packed contiguously [MQTT-3.10.3-1].
         */
         throw new Exception('Missing topics!');
     }
     $buffer = "";
     # Payload
     foreach ($this->topics as $topic) {
         $buffer .= Utility::PackStringWithLength($topic);
     }
     return $buffer;
 }
Exemplo n.º 2
0
 protected function payload()
 {
     if (empty($this->topics)) {
         /*
         The payload of a SUBSCRIBE packet MUST contain at least one Topic Filter / QoS pair.
         A SUBSCRIBE packet with no payload is a protocol violation [MQTT-3.8.3-3]
         */
         throw new Exception('Missing topics!');
     }
     $buffer = "";
     # Payload
     foreach ($this->topics as $topic => $qos_max) {
         $buffer .= Utility::PackStringWithLength($topic);
         $buffer .= chr($qos_max);
     }
     return $buffer;
 }
Exemplo n.º 3
0
 /**
  * PUBLISH Variable Header
  *
  * Topic Name, Packet Identifier
  *
  * @return string
  * @throws Exception
  */
 protected function buildVariableHeader()
 {
     $header = '';
     $topic = $this->message->getTopic();
     # Topic
     $header .= Utility::PackStringWithLength($topic);
     Debug::Log(Debug::DEBUG, 'Message PUBLISH: topic=' . $topic);
     Debug::Log(Debug::DEBUG, 'Message PUBLISH: QoS=' . $this->getQos());
     Debug::Log(Debug::DEBUG, 'Message PUBLISH: DUP=' . $this->getDup());
     Debug::Log(Debug::DEBUG, 'Message PUBLISH: RETAIN=' . $this->getRetain());
     # Message ID if QoS > 0
     if ($this->getQos()) {
         if (!$this->msgid) {
             throw new Exception('MsgID MUST be set if QoS is not 0.');
         }
         $header .= $this->packPacketIdentifer();
     }
     return $header;
 }
Exemplo n.º 4
0
 /**
  * Build Variable Header
  *
  * @return string
  */
 protected function buildVariableHeader()
 {
     $buffer = "";
     # Protocol Name
     if ($this->message->mqtt->version() == MQTT::VERSION_3_1_1) {
         $buffer .= Utility::PackStringWithLength('MQTT');
     } else {
         $buffer .= Utility::PackStringWithLength('MQIsdp');
     }
     # End of Protocol Name
     # Protocol Level
     $buffer .= chr($this->message->mqtt->version());
     # Connect Flags
     # Set to 0 by default
     $var = 0;
     # clean session
     if ($this->clean) {
         $var |= 0x2;
     }
     # Will flags
     if ($this->message->will) {
         $var |= $this->message->will->get();
     }
     # User name flag
     if ($this->message->username != NULL) {
         $var |= 0x80;
     }
     # Password flag
     if ($this->message->password != NULL) {
         $var |= 0x40;
     }
     $buffer .= chr($var);
     # End of Connect Flags
     # Keep alive: unsigned short 16bits big endian
     $buffer .= pack('n', $this->keepalive);
     return $buffer;
 }
Exemplo n.º 5
0
 protected function payload()
 {
     $payload = '';
     $payload .= Utility::PackStringWithLength($this->mqtt->clientid);
     # Adding Connect Will
     if ($this->will && $this->will->get()) {
         /*
         If the Will Flag is set to 0 the Will QoS and Will Retain fields in the Connect Flags
         MUST be set to zero and the Will Topic and Will Message fields MUST NOT be present in
         the payload [MQTT-3.1.2-11].
         */
         $payload .= Utility::PackStringWithLength($this->will->getTopic());
         $payload .= Utility::PackStringWithLength($this->will->getMessage());
     }
     # Append Username
     if ($this->username != NULL) {
         $payload .= Utility::PackStringWithLength($this->username);
     }
     # Append Password
     if ($this->password != NULL) {
         $payload .= Utility::PackStringWithLength($this->password);
     }
     return $payload;
 }