Its my first post here. Correct me if im wrong
I'm using free scale controller with G620 module for connecting to server. I started to implement MQTT client.
The communication with G620 GPRS module through UART. Through AT commands i connected to the MQTTbroker. As soon as i sent the connect packet, broker closing the connection. Need help or suggestion.
The connect packet is: { 0x10,0x12,0x00,0x04,M,Q,T,T,0x04,0x00,0x3C,0x00,0x00,0x06,Z,1,2,1,2,3
}
There are two scenarios the server is disconnecting you as per MQTT Protocol.
1. If you are violating protocol format
2. If the timeout of the connection is exceeded
Reasons for Protocol Violation termination:
- You might have wrongly framed out some protocol bytes. Cross verify with the protocol document.
- You might be already connected and trying to connect again. Check for server side logs if you have access.
- As you are sending the frame through UART, you might have used a for loop to send the bytes. If the for loop counter is based from "strlen(Connectpacket)", you will not get the exact count as "strlen" will terminate after 0x00. So the server will receive half packet and disconnects you for violation.
Your protocol seems to be invalid,
0x10 - MQTT Control Packet type
0x12 - Remaining Length
0x00 - Length MSB
0x04 - Length LSB
M
Q
T
T - Protocol Name
0x04 - Protocol Level
0x00 - Connect Flags
0x3C - Keep Alive MSB
0x00 - Keep Alive LSB
0x00,0x06,Z,1,2,1,2,3 - What are there bytes used for? Cross verify with protocol document.
Set clean session bit as 1. Set keep alive for 0x00 MSB 0x3C LSB.