MQTT_Basic_TLS Seems Fails after TLS connection

I am working up to IOT on AWS and trying to implement things in stages on my target processor. I am simply trying to establish TLS MQTT communication with test.mosquitto.org.

I am running the MQTT_Basic_TLS demo in Microsoft Visual Studio and it appears that the Ethernet/TCP and TLS interfaces are connecting but then I get errors when it tries to establish MQTT communication. (see below)

I am not sure what I can change to make things work.

Any guidance would be much appreciated.

13 6726 [IP-Task] TCP: active 29527 => 91.121.93.94:8883 set ESTAB (scaling 1)
Socket 29527 -> 91.121.93.94:8883 State eCONNECT_SYN->eESTABLISHED
14 6726 [DemoTask] [INFO] [SocketsWrapper] [TCP_Sockets_Connect:180] Established TCP connection with test.mosquitto.org.15 7006 [DemoTask] [INFO] [MbedtlsTransport] [tlsHandshake:568] (Network connection 021AFC58) TLS handshake successful.
16 7006 [DemoTask] [INFO] [MbedtlsTransport] [TLS_FreeRTOS_Connect:726] (Network connection 021AFC58) Connection to test.mosquitto.org established.
17 7006 [DemoTask] [INFO] [MQTTDemo] [prvMQTTDemoTask:520] Creating an MQTT connection to test.mosquitto.org.

18 7126 [IP-Task] Socket 29527 -> 91.121.93.94:8883 State eESTABLISHED->eLAST_ACK
[ERROR] [MQTT] [logConnackResponse:1083] 19 7126 [DemoTask] Connection refused: not authorized.
20 7126 [DemoTask] [ERROR] [MQTT] [receiveConnack:2365] CONNACK recv failed with status = MQTTServerRefused.
21 7126 [DemoTask] [ERROR] [MQTT] [MQTT_Connect:2690] MQTT connection failed with status = MQTTServerRefused.
vAssertCalled( C:\proj\FreeRTOSv202212.00\FreeRTOS-Plus\Demo\coreMQTT_Windows_Simulator\MQTT_Basic_TLS\DemoTasks\BasicTLSMQTTExample.c, 707

It seems that the broker is refusing your MQTT connection request. It is hard to guess why the broker is doing so. Is it possible to capture network traffic? Another option is to host the broker yourself.

The issue was in the function prvCreateMQTTConnectionWithBroker(). The pUserName and pPassword elements of the xConnectInfo struct were set to “username” and “password”. Not sure when this happened. I might have done this months ago when I was first looking into this code and got pulled off to another project. I set these to NULL and the corresponding lengths to 0 and the demo started working. I had thought that the TLS portion was working correctly. Apparently, the server did not like trying just the MQTT Login. Just wanted to close this thread. Thank you.

Thank you for reporting back!