You've already forked Adafruit_MQTT_Library
							
							
				mirror of
				https://github.com/adafruit/Adafruit_MQTT_Library.git
				synced 2025-11-03 11:53:11 +03:00 
			
		
		
		
	Fixing reversal of topic/packet identifier (topic should come first)
This commit is contained in:
		@@ -490,6 +490,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
 | 
				
			|||||||
  return len;
 | 
					  return len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// as per http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040
 | 
				
			||||||
uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, 
 | 
					uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, 
 | 
				
			||||||
                                     const char *data, uint8_t qos) {
 | 
					                                     const char *data, uint8_t qos) {
 | 
				
			||||||
  uint8_t *p = packet;
 | 
					  uint8_t *p = packet;
 | 
				
			||||||
@@ -499,6 +500,9 @@ uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
 | 
				
			|||||||
  // fill in packet[1] last
 | 
					  // fill in packet[1] last
 | 
				
			||||||
  p+=2;
 | 
					  p+=2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // topic comes before packet identifier
 | 
				
			||||||
 | 
					  p = stringprint_P(p, topic);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // add packet identifier. used for checking PUBACK in QOS > 0
 | 
					  // add packet identifier. used for checking PUBACK in QOS > 0
 | 
				
			||||||
  if(qos > 0) {
 | 
					  if(qos > 0) {
 | 
				
			||||||
    p[0] = (packet_id_counter >> 8) & 0xFF;
 | 
					    p[0] = (packet_id_counter >> 8) & 0xFF;
 | 
				
			||||||
@@ -509,8 +513,6 @@ uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
 | 
				
			|||||||
    packet_id_counter++;
 | 
					    packet_id_counter++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  p = stringprint_P(p, topic);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  memcpy(p, data, strlen(data));
 | 
					  memcpy(p, data, strlen(data));
 | 
				
			||||||
  p+=strlen(data);
 | 
					  p+=strlen(data);
 | 
				
			||||||
  len = p - packet;
 | 
					  len = p - packet;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user