MQTTBadResponse with coreMQTT v1.1

Trying to set up a toy example with AWS IoT Core/MQTT on an STM32L475 board, but getting this error in the coreMQTT log:

63 15408 [iot_thread] [ERROR] Incoming packet invalid: Packet type=1.
64 15416 [iot_thread] [ERROR] CONNACK recv failed with status = MQTTBadResponse.

I noticed this project is using coreMQTT v1.1 which seems a bit old compared to v2.1 now available on Github. Is that the reason, or something else?

The TLS handshake seems to work:
51 14069 [iot_thread] [INFO] Creating a TLS connection to xxxxxxxx-ats.iot.eu-west-1.amazonaws.com:8883.
52 15320 [iot_thread] [DEBUG] Encoded size for length 28 is 1 bytes.

(no error message until MQTTBadResponse)

So it seems to be a problem at the MQTT level, right?
Any ideas?

Are you receiving a response or just timing out while waiting for response? You can check that in your transport interface implementation. Have you correctly attached a policy to your certificate?

Yes, we have set a policy for the certificate.

There seem to be some messages exchanged. The error code MQTTBadResponse means that an invalid packet was received. This comes from coreMQTT, so the mbedTLS connection seem to have been established correctly.

Here is the full log from the device

51 14069 [iot_thread] [INFO] Creating a TLS connection to xxxxxxxxxx-ats.iot.eu-west-1.amazonaws.com:8883.
52 15320 [iot_thread] [DEBUG] Encoded size for length 28 is 1 bytes.
53 15326 [iot_thread] [DEBUG] CONNECT packet remaining length=28 and packet size=30.
54 15334 [iot_thread] [DEBUG] CONNECT packet size is 30 and remaining length is 28.
55 15342 [iot_thread] [DEBUG] Encoded size for length 28 is 1 bytes.
56 15349 [iot_thread] [DEBUG] Length of serialized CONNECT packet is 30.
57 15359 [iot_thread] [DEBUG] BytesSent=30, BytesRemaining=0
58 15364 [iot_thread] [DEBUG] Successfully sent packet at time 4654.
59 15372 [iot_thread] [DEBUG] Sent 30 bytes of CONNECT packet.
60 15381 [iot_thread] [DEBUG] No data was received from the transport.
61 15392 [iot_thread] [DEBUG] No data was received from the transport.
62 15402 [iot_thread] [WARN] Incoming packet invalid: Packet type=1.
63 15408 [iot_thread] [ERROR] Incoming packet invalid: Packet type=1.
64 15416 [iot_thread] [ERROR] CONNACK recv failed with status = MQTTBadResponse.
65 15423 [iot_thread] [ERROR] MQTT connection failed with status = MQTTBadResponse.

PacketType 1 is CONNECT which you cannot get. Can you dump the received packet after TLS decoding? You should be able to do that in your transport receive implementation.

The log message says PacketType=1, but that’s the value of the entire byte. The high nibble is the packet type, which is 0, which is invalid.

Also there’s no real packet on the MCU. It requests 1 byte from the modem and receives it. I modified the code to request 16 bytes, in that case the modem returns two bytes: 0x01 0x00. SSL/TLS handling is offloaded, there is no TLS decoding on the MCU.

We resolved the issue over call and it was a mis-configured policy document.

Thanks for your support!