6

Is there any tool to check my generated packets for being a valid MQTT (3.1.1) packet? Background: I'm using Paho embedded (MQTTPacket) on my microcontroller to generate packets to be send over my ethernet driver. But something seems to be wrong with my packets as they aren't displayed in mqtt-spy.

i.e. this packet:

0x10 0x1D 0x04 0x00 0x4D 0x51 0x54 0x54 0x04 0x02 0x00 0x14 0x00 0x11 
0x65 0x76 0x6F 0x6C 0x61 0x6E 0x5F 0x31 0x32 0x33 0x34 0x35 0x36 0x37
0x38 0x39 0x30 0x30 0x15 0x00 0x06 0x65 0x76 0x6F 0x6C 0x61 0x6E 0x48 
0x65 0x6C 0x6C 0x6F 0x20 0x65 0x65 0x76 0x6F 0x4C 0x41 0x4E 0x21 0xE0 
0x00 0x29 0x90 0x20

is it valid?

Bence Kaulics
  • 7,843
  • 8
  • 42
  • 90
elasticman
  • 221
  • 1
  • 5

1 Answers1

6

The message above decoded:

MQIsdp{03}{02}{00}{14}{00}{11}evolan_12345678900!{00}{06}evolanHello eevoLAN!à{00}

It is mixed Ascii/Hex (topic, clientID and payload are plain ascii, special chars are {hex}.

It turns out, that this packet always contains the connect / disconnect option (refer to this table http://docs.solace.com/MQTT-311-Prtl-Conformance-Spec/MQTT%20Control%20Packet%20format.htm#_Table_2.1_-)

So I rewrote my method for publishing and split it into separate Connect/Disconnect and Publish methods. (The examples for Paho embedded are very bad documented, so I didn't know that I have always sent a connect/disconnect request within my published message)..

Programming details:

Connect method

MQTTPacket_connectData data = MQTTPacket_connectData_initializer;

char m_buf[200];
uint32_t m_len = sizeof(m_buf);

data.clientID.cstring = "<your client id string>";
data.keepAliveInterval = 20;
data.cleansession = 1;
data.MQTTVersion = 4;
uint32_t len = MQTTSerialize_connect(m_buf, m_len, &data);

your_ethernet_driver_send_method(m_buf, len);

Send method

char m_buf[200];
uint32_t m_len = sizeof(m_buf);

MQTTString topicString = MQTTString_initializer;

uint32_t payloadlen = strlen(m_payload);
topicString.cstring = m_topic;

uint32_t len = 0;
len += MQTTSerialize_publish(m_buf + len, m_len - len, 0, 0, 0, 0, topicString, m_payload, payloadlen);

your_ethernet_driver_send_method(m_buf, len);

This works now, I can confirm getting packets on mqtt-spy!

So, unfortunately I couldn't find a tool for validating my packet, but what I did is outputting it to a text editor and highlight the special chars as hex values. Then I compared the header bytes to the definition posted above.

elasticman
  • 221
  • 1
  • 5