# Free rtos + mqtt

**URL:** <https://forums.freertos.org/t/free-rtos-mqtt/10219>\
**Category:** AWS\
**Created:** [July 9, 2020, 12:34am UTC](https://forums.freertos.org/t/free-rtos-mqtt/10219 "2020-07-09T00:34:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgb17](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mgb17](https://forums.freertos.org/u/mgb17)\
**Post date:** [July 9, 2020, 12:34am UTC](https://forums.freertos.org/t/free-rtos-mqtt/10219/1 "2020-07-09T00:34:24Z")

</div>

Hello,  
I am trying to run the FREE RTOS + MQTT Basic TLS Demo, However, after running the solution after following the steps given at [https://www.freertos.org/mqtt/preconfiguredexamplesTLS.html..with](https://www.freertos.org/mqtt/preconfiguredexamplesTLS.html..with) the default certificate definition in “mqtt\_demo\_profile.h” . I get the following errors…

12 1877 [MQTTDemo] [ERROR][NET][1877] Failed to perform TLS handshake, error -9984.  
13 1878 [MQTTDemo] [ERROR][MQTT][1878] Failed to create network connection: 1  
14 1878 [MQTTDemo] [ERROR][MQTT][1878] Failed to establish new MQTT connection, error NETWORK ERROR

When I tried to download the certificate via the link given at test.mosquitto .org, and copy pasted it in a similar format, I got the errors…

12 1663 [MQTTDemo] [ERROR][NET][1663] Failed to parse server root CA certificate, error -4396.  
13 1664 [MQTTDemo] [ERROR][MQTT][1664] Failed to create network connection: 4  
14 1664 [MQTTDemo] [ERROR][MQTT][1664] Failed to establish new MQTT connection, error NETWORK ERROR.

I get the same error as above when I try out some other mqtt rocker such as maqiatto or flespi and using their certificates.  
I have already turned off my anti virus firewall, as well as added inbound rules in the advanced windows firewall. In both cases I also get the following log:

Connected to [test.mosquitto.org:8883](http://test.mosquitto.org:8883)

I am running the demo on the Microsoft Visual Studio 2020 RTOS Simulator Port.

Am I missing something?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 10, 2020, 4:51am UTC](https://forums.freertos.org/t/free-rtos-mqtt/10219/2 "2020-07-10T04:51:06Z")

</div>

Would you please share the content of `mqtt_demo_profile.h` to ensure that the certificate formatting is correct.

Thanks.

---

<div class="post-metadata">

**Author:** ![mgb17](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mgb17](https://forums.freertos.org/u/mgb17)\
**Post date:** [July 10, 2020, 7:57pm UTC](https://forums.freertos.org/t/free-rtos-mqtt/10219/3 "2020-07-10T19:57:03Z")

</div>

I am sorry since I am a new user on this forum, I am not allowed to upload files…here is how the format of the certificate…

```auto
#define mqttdemoprofileCLIENT_IDENTIFIER "mqttexampleclient"

/**
 * @brief The server certificate for test.mosquitto. org:8883.
 *
 * This certificate is obtained from https://test.mosquitto.org/ and is used
 * to authenticate the Mosquitto MQTT broker. This demo only authenticates
 * the server and does not authenticate the client. This is a RSA SHA-1
 * certificate which is not considered secure for production use cases as
 * per the industry standards.
 *
 * If you want to connect to any other MQTT broker other than
 * test.mosquitto.org, replace it with the certificate of the MQTT broker.
 */
#define mqttdemoprofileBROKER_CERTIFICATE_PEM \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL\n" \
"BQAwgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwG\n" \
"A1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAU\n" \
"BgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hv\n" \
"by5vcmcwHhcNMjAwNjA5MTEwNjM5WhcNMzAwNjA3MTEwNjM5WjCBkDELMAkGA1UE\n" \
"BhMCR0IxFzAVBgNVBAgMDlVuaXRlZ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lb+1IKJE\n" \
"m/XriWr /Cq4h/JfB7NTsezVslgkBaoU=\n" \
"-----END CERTIFICATE-----\n"

```

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 10, 2020, 9:09pm UTC](https://forums.freertos.org/t/free-rtos-mqtt/10219/4 "2020-07-10T21:09:08Z")

</div>

I noticed one extra space. I downloaded the certificate and formatted. Would you please copy-paste the following in your config file:

```auto
#define mqttdemoprofileBROKER_CERTIFICATE_PEM \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL\n" \
"BQAwgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwG\n" \
"A1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAU\n" \
"BgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hv\n" \
"by5vcmcwHhcNMjAwNjA5MTEwNjM5WhcNMzAwNjA3MTEwNjM5WjCBkDELMAkGA1UE\n" \
"BhMCR0IxFzAVBgNVBAgMDlVuaXRlZCBLaW5nZG9tMQ4wDAYDVQQHDAVEZXJieTES\n" \
"MBAGA1UECgwJTW9zcXVpdHRvMQswCQYDVQQLDAJDQTEWMBQGA1UEAwwNbW9zcXVp\n" \
"dHRvLm9yZzEfMB0GCSqGSIb3DQEJARYQcm9nZXJAYXRjaG9vLm9yZzCCASIwDQYJ\n" \
"KoZIhvcNAQEBBQADggEPADCCAQoCggEBAME0HKmIzfTOwkKLT3THHe+ObdizamPg\n" \
"UZmD64Tf3zJdNeYGYn4CEXbyP6fy3tWc8S2boW6dzrH8SdFf9uo320GJA9B7U1FW\n" \
"Te3xda/Lm3JFfaHjkWw7jBwcauQZjpGINHapHRlpiCZsquAthOgxW9SgDgYlGzEA\n" \
"s06pkEFiMw+qDfLo/sxFKB6vQlFekMeCymjLCbNwPJyqyhFmPWwio/PDMruBTzPH\n" \
"3cioBnrJWKXc3OjXdLGFJOfj7pP0j/dr2LH72eSvv3PQQFl90CZPFhrCUcRHSSxo\n" \
"E6yjGOdnz7f6PveLIB574kQORwt8ePn0yidrTC1ictikED3nHYhMUOUCAwEAAaNT\n" \
"MFEwHQYDVR0OBBYEFPVV6xBUFPiGKDyo5V3+Hbh4N9YSMB8GA1UdIwQYMBaAFPVV\n" \
"6xBUFPiGKDyo5V3+Hbh4N9YSMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL\n" \
"BQADggEBAGa9kS21N70ThM6/Hj9D7mbVxKLBjVWe2TPsGfbl3rEDfZ+OKRZ2j6AC\n" \
"6r7jb4TZO3dzF2p6dgbrlU71Y/4K0TdzIjRj3cQ3KSm41JvUQ0hZ/c04iGDg/xWf\n" \
"+pp58nfPAYwuerruPNWmlStWAXf0UTqRtg4hQDWBuUFDJTuWuuBvEXudz74eh/wK\n" \
"sMwfu1HFvjy5Z0iMDU8PUDepjVolOCue9ashlS4EB5IECdSR2TItnAIiIwimx839\n" \
"LdUdRudafMu5T5Xma182OC0/u/xRlEm+tvKGGmfFcN0piqVl8OrSPBgIlb+1IKJE\n" \
"m/XriWr/Cq4h/JfB7NTsezVslgkBaoU=\n" \
"-----END CERTIFICATE-----\n"

```

If you still get the same error, would you please enable mbed\_tls logs. I have explained here how to do it: [https://github.com/aws/aws-iot-device-sdk-embedded-C/issues/976#issuecomment-647176211](https://github.com/aws/aws-iot-device-sdk-embedded-C/issues/976#issuecomment-647176211)

Thanks.

---

<div class="post-metadata">

**Author:** ![mgb17](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mgb17](https://forums.freertos.org/u/mgb17)\
**Post date:** [July 12, 2020, 5:40pm UTC](https://forums.freertos.org/t/free-rtos-mqtt/10219/5 "2020-07-12T17:40:44Z")

</div>

This worked for me… Thanks a lot Gaurav !! 🙂
