FreeRTOS MQTT fails to connect to MQTT Mosquitto(v1.6.7) broker on Windows

wonderfuljames wrote on Friday, October 04, 2019:

I am running a FreeRTOS MQTT client on Microchip PIC32MZ eval board and able to connect to AWS MQTT server over wired Ethernet.
But When I try to connect to a MQTT Mosquitto broker running on my Windows, I get a connection error as follows:

C:\Program Files\mosquitto>mosquitto -v
1570213770: mosquitto version 1.6.7 starting
1570213770: Using default config.
1570213770: Opening ipv6 listen socket on port 1883.
1570213770: Opening ipv4 listen socket on port 1883.
1570213804: New connection from 192.168.9.169 on port 1883.
1570213804: Client disconnected due to protocol error.

The fact that the broker is getting a connection request from my PIC32MZ eval board, the IP and port # are correctly set up.
Does anyone have experience with trying to connect FreeRTOS MQTT client to a broker other than default AWS MQTT broker?

rtel wrote on Friday, October 04, 2019:

Yes. Is this the demo you tried? I used it with the public mosquitto broker and with mosquitto running locally: https://www.freertos.org/mqtt/preconfiguredexamples.html

wonderfuljames wrote on Friday, October 04, 2019:

Thanks Richard for getting back.
Yes the Windows version of FreeRTOS MQTT client works fine with my local mosquitto.
But FreeRTOS MQTT client running on my PIC32MZ fails to connect to the same local mosquitto.
As I mentioned, FreeRTOS MQTT client running on my PIC32MZ works fine with AWS MQTT broker.
In theory, the following is all I have to change?
//static const char clientcredentialMQTT_BROKER_ENDPOINT[] = “atmaz5u2t2hej-ats.iot.us-east-2.amazonaws.com”;
static const char clientcredentialMQTT_BROKER_ENDPOINT[] = “192.168.9.70”;

// #define clientcredentialMQTT_BROKER_PORT 8883
#define clientcredentialMQTT_BROKER_PORT 1883

wonderfuljames wrote on Friday, October 04, 2019:

I have a bit more specific information as to the failure:

33 5802 [iot_thread] ERROR: Handshake failed with error code -128
34 5802 [iot_thread] [ERROR][NET][5802] Failed to establish new connection.
35 5802 [IP-task] FreeRTOS_closesocket[42094 to c0a80946ip:1883]: buffers 60 socks 0
36 5803 [iot_thread] [ERROR][MQTT][5803] Failed to establish new MQTT connection, error NETWORK ERROR.

“Handshake failed”…

Any ideas?

wanggord wrote on Friday, October 04, 2019:

Hi James,

From those logs, it looks like the demo application is still trying to perform a TLS handshake. If your broker is an unsecured Mosquitto server, this will cause the connection to fail.

To successfully connect to Mosquitto, you will need to change 2 lines of code in your demo. Assuming you are running this file as your demo:

Disable TLS by not passing any credentials.

networkInfo.u.setup.pNetworkCredentialInfo = NULL; // Line 411

Disable AWS IoT MQTT mode.

connectInfo.awsIotMqttMode = false; // Line 419

wonderfuljames wrote on Friday, October 04, 2019:

Dear Gordon,
That fixed my issue.
Thanks for the info about TLS handshake in FreeRTOS.

wonderfuljames wrote on Friday, October 04, 2019:

Dear Gordon,
That fixed my issue.
Thanks for the info about TLS handshake in FreeRTOS.

wonderfuljames wrote on Friday, October 04, 2019:

Thanks for pointing me to this link. Quite helpful