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?

  • 1
    Some pointers what sort of packet it should be would be helpful (including the topic and payload if applicable), also have you tried to compare it to the spec yourself? – hardillb Jun 14 '17 at 12:02
  • See my answer below. – elasticman Jun 14 '17 at 12:21
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.

  • 1
    Also, use data.MQTTVersion = 4 to get the newest header definition, so MQTT instead of MQIsdp. – elasticman Jun 14 '17 at 12:22
  • Please accept this as an answer (even though you posted it), as that will help others who read this in future. Btw are you aware of WireShark? It has an MQTT filter which will decode such messages for you. – Mawg says reinstate Monica Jun 15 '17 at 7:31
  • 1
    I will accept as, as soon as the system allows me :) I know WireShark, but I can't use it as the MQTT transaction is between my microcontroller and the mosquitto.org testserver. So I can't directly capture anything on my computer. (I know that there is still a way, but I can't do that on my company's PC.) – elasticman Jun 15 '17 at 9:11
  • Just use your PC as a gateway? I am sure that there is a solution, involving routing, but can't give you details. Googling shows some interesting possibilities, such as Raspberry Pi as a Network Monitoring Node – Mawg says reinstate Monica Jun 15 '17 at 9:27
  • 1
    I know such solutions exist, but as described above, I can't change my company's network settings on the PC-side. – elasticman Jun 16 '17 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.