MQTT over TCP - packet error - ARM processor, Quectel Modem, Losant broker

gsm

#1

Hey Ravi,
So I went through your video for the MQTT using the sim800 module.I have been trying to send MQTT subscribe packets to the Losant broker using the GSM Quectel M66 modem. But I have been unable to do so.
The TCP connection is not giving any trouble, but when I try to create and send the connect packet, I get SEND OK and then no response from the server. To prepare the Hex format I am using DockLight
Similarly tried a connect packet to cloudmqtt and that doesn’t work either.

This is the packet I constructed
10 8C 00 04 4D 51 54 54 03 C2 00 2C 00 18 35 61 37 61 30 66 66 65 63 38 34 37 36 39 30 30 30 36 32 64 61 63 30 63 00 24 32 34 37 65 64 30 63 61 2D 35 39 62 38 2D 34 30 36 65 2D 38 30 63 34 2D 34 33 66 62 38 66 34 39 63 64 31 66 00 40 37 38 32 36 32 38 37 65 32 34 66 63 33 37 36 65 38 39 30 63 30 33 63 61 34 31 65 37 66 63 63 64 33 66 32 37 39 36 65 36 62 64 30 61 64 65 31 64 62 64 63 63 65 66 37 31 30 30 61 62 37 64 66 65 1A 0D 0A

In bold is the client id length (00 18), client id, user id length (00 24), user id, and password length (00 40), password

Can You help me out here .
Thanks
Craig


#2

How did you calculate the remaining length field?


#3

After the first two characters the length of the remaining message is 140 bytes, so that is 8C in Hex.
The last three characters 1A 0D 0A I’m not counting in the remaining packet length, because that’s basically CR, NL.


#4

Are you taking care of the length for > 127 bytes. In the video there is a algorithm shown in the MQTT spec. It should be used to generate the Remaining length parameter. It can stretch to more than 1 byte.


#5

Ravi,
thanks for that reply, so I did try changing it.
Changed the remaining length from 8C to 80 0C as per the algorithm (for the remaining length of 140 bytes, 10 bytes variable header +130 bytes packet) but it still isn’t working
have I correctly calculated the remaining length?


#6

Did you check this code?
Its written for SIM800L
But packet formations are correct and it works.
Try it and see.
Is your TCP working for any other servers other than MQTT?
Like loading a website or connecting to any sockets?


#7

if your message greatter than 127 byte, you must create 2 byte, for exmple the message 140 byte,
remove 8c and add 8c 01.

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349205