# How to port MQTT of AWS IoT Device SDK for Embedded C to mangOH platform

**URL:** <https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926>\
**Category:** Cloud & Connectivity\
**Created:** [April 18, 2022, 2:01am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926 "2022-04-18T02:01:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![babangparhusip](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@babangparhusip](https://mangoh.discourse.group/u/babangparhusip)\
**Post date:** [April 18, 2022, 2:01am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/1 "2022-04-18T02:01:55Z")

</div>

I am trying to integrate MQTT stack of AWS IoT Device SDK into my mangOH red board.

I downloaded latest SDK here:

> **[Release 202108.00 · aws/aws-iot-device-sdk-embedded-C](https://github.com/aws/aws-iot-device-sdk-embedded-C/releases/tag/202108.00)**
>
> Release version 202108.00 of the AWS IoT Device SDK for Embedded C.

and manage to make it work on local PC (Ubuntu 18.04 ) i.e. it can do mutual TLS authentication and simple MQTT publish to AWS IoT core cloud.

However when I tried to port over to mangOH platform, I made some progress but was stuck at compilation error which seemed from openssl library integration, it could not find function which was defined in this inclusion:

#include \<openssl/ssl.h\>

This mean, this library was recognized locally by my local PC OS but not by legato (release 16 ver 19.11.2). This is the snippet of compilation error:

\<project\_base\>/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c:247:17: error: implicit declaration of function ‘SSL\_set1\_host’; did you mean ‘SSL\_set\_trust’? [-Werror=implicit-function-declaration]  
sslStatus = SSL\_set1\_host( pOpensslParams-\>pSsl, pServerInfo-\>pHostName );  
^ ~~~~~~~~~~~~  
SSL\_set\_trust  
\<project\_base\>/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c: In function ‘setOptionalConfigurations’:  
/home/iotlab0035x1804/repo/gatewayx/src/gateway/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c:533:13: error: implicit declaration of function ‘SSL\_set\_default\_read\_buffer\_len’; did you mean ‘SSL\_CTX\_set\_default\_read\_ahead’? [-Werror=implicit-function-declaration]  
SSL\_set\_default\_read\_buffer\_len( pSsl, ( size\_t ) readBufferLength );  
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
SSL\_CTX\_set\_default\_read\_ahead  
\<project\_base\>/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c: In function ‘Openssl\_Connect’:  
\<project\_base\>/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c:625:36: error: implicit declaration of function ‘TLS\_client\_method’; did you mean ‘DTLS\_client\_method’? [-Werror=implicit-function-declaration]  
pSslContext = SSL\_CTX\_new( TLS\_client\_method() );  
^ ~~~~~~~~~~~~~~~~  
DTLS\_client\_method  
\<project\_base\>/src/gateway/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c:625:36: error: passing argument 1 of ‘SSL\_CTX\_new’ makes pointer from integer without a cast [-Werror=int-conversion]  
In file included from \<project\_base\>/src/gateway/cloud/aws/sdk/platform/posix/transport/include/openssl\_posix.h:59:0,  
from \<project\_base\>/gatewayx/src/gateway/cloud/aws/sdk/platform/posix/transport/src/openssl\_posix.c:35:  
\<project\_base\>/gatewayx/leaf-data/r16/wp76-toolchain/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/openssl/ssl.h:2131:10: note: expected ‘const SSL\_METHOD \* {aka const struct ssl\_method\_st \*}’ but argument is of type ‘int’  
SSL\_CTX \*SSL\_CTX\_new(const SSL\_METHOD \*meth);  
^ ~~~~~~~~~~

This is snippet of my .cdef  
cxxflags: {  
-std=c++1z  
-DMQTT\_DO\_NOT\_USE\_CUSTOM\_CONFIG  
-DDISABLE\_LOGGING  
-DLIBRARY\_LOG\_LEVEL=LOG\_NONE  
-I$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/include  
-I$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/  
-I$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/interface  
-I$CURDIR/cloud/aws/sdk/platform/posix/transport/include  
-I$CURDIR/cloud/aws/logging-stack  
-I$CURDIR/cloud/aws/sdk/platform/include  
-I$CURDIR/cloud/aws/sdk/platform/posix/transport/include  
}

cflags: {  
-std=c99  
-DMQTT\_DO\_NOT\_USE\_CUSTOM\_CONFIG  
-DDISABLE\_LOGGING  
-DLIBRARY\_LOG\_LEVEL=LOG\_NONE  
-I$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/include  
-I$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/  
-I$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/interface  
-I$CURDIR/cloud/aws/sdk/platform/posix/transport/include  
-I$CURDIR/cloud/aws/logging-stack  
-I$CURDIR/cloud/aws/sdk/platform/include  
-I$CURDIR/cloud/aws/sdk/platform/posix/transport/include  
}

provides: {  
api: {  
ipcGateway = $CURDIR/…/leipc/ipcGateway.api  
}  
}

sources: {  
…

```
// AWS MQTT library
$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/core_mqtt.c
$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/core_mqtt_state.c
$CURDIR/cloud/aws/sdk/libraries/standard/coreMQTT/source/core_mqtt_serializer.c

$CURDIR/cloud/aws/sdk/platform/posix/transport/src/openssl_posix.c

```

}

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 18, 2022, 2:31am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/2 "2022-04-18T02:31:51Z")

</div>

Is it same issue as this one?

> **[Running Azure IoT sdk-c](https://forum.legato.io/t/running-azure-iot-sdk-c/5635/12)**
>
> You can see here

---

<div class="post-metadata">

**Author:** ![babangparhusip](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@babangparhusip](https://mangoh.discourse.group/u/babangparhusip)\
**Post date:** [April 18, 2022, 3:32am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/3 "2022-04-18T03:32:06Z")

</div>

Thanks but It’s not.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 18, 2022, 3:46am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/4 "2022-04-18T03:46:48Z")

</div>

[https://www.openssl.org/docs/manmaster/man3/SSL\_set\_default\_read\_buffer\_len.html](https://www.openssl.org/docs/manmaster/man3/SSL_set_default_read_buffer_len.html)

what is your “openssl version” on module?

You might also see here:

> **[Integrating AWS IoT (Alexa) with WP76 | Upgrading OpenSSL](https://forum.legato.io/t/integrating-aws-iot-alexa-with-wp76-upgrading-openssl/5902)**
>
> Hello, We are working with WP76xx and Legato 19.11.2 (the stable version from release 16). We would like to integrate it with AWS (Registration | AVS for AWS IoT) which requires Curve25519. Currently, the Linux Kernel prebuilt has OpenSSL version...

---

<div class="post-metadata">

**Author:** ![babangparhusip](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@babangparhusip](https://mangoh.discourse.group/u/babangparhusip)\
**Post date:** [April 21, 2022, 1:59am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/5 "2022-04-21T01:59:37Z")

</div>

Why would ssl version matter? This is compile error.

Thanks for the link, but not that relevant.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 21, 2022, 2:39am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/6 "2022-04-21T02:39:16Z")

</div>

Maybe only new version of ssl lib have that function

---

<div class="post-metadata">

**Author:** ![babangparhusip](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@babangparhusip](https://mangoh.discourse.group/u/babangparhusip)\
**Post date:** [April 21, 2022, 3:21am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/7 "2022-04-21T03:21:03Z")

</div>

I see, the version is ssl 1.0.2 , the one associated with release 16:

root@swi-mdm9x28-wp:~# openssl version  
OpenSSL 1.0.2p 14 Aug 2018

---

<div class="post-metadata">

**Author:** ![babangparhusip](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@babangparhusip](https://mangoh.discourse.group/u/babangparhusip)\
**Post date:** [April 21, 2022, 3:29am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/8 "2022-04-21T03:29:13Z")

</div>

Ok, I read again AWS SDK, it needs openssl 1.1.0 or later.  
This explains why the AWS SDK MQTT can’t be integrated to Legato release 16.

How should I go about this? Any legato release includes updated openssl?

If I were to add manually, how should I do it? How can I write the component def (i.e. cdef)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jyijyi/32/997_2.png) [@jyijyi](https://mangoh.discourse.group/u/jyijyi)\
**Post date:** [April 21, 2022, 4:41am UTC](https://mangoh.discourse.group/t/how-to-port-mqtt-of-aws-iot-device-sdk-for-embedded-c-to-mangoh-platform/9926/9 "2022-04-21T04:41:20Z")

</div>

Probably you need to wait for next release r17

Or you can see here

> **[Integrating AWS IoT (Alexa) with WP76 | Upgrading OpenSSL](https://forum.legato.io/t/integrating-aws-iot-alexa-with-wp76-upgrading-openssl/5902)**
>
> Hello, We are working with WP76xx and Legato 19.11.2 (the stable version from release 16). We would like to integrate it with AWS (Registration | AVS for AWS IoT) which requires Curve25519. Currently, the Linux Kernel prebuilt has OpenSSL...

To include in .cdef file:

> [@Using Openssl to implement cryptography](https://mangoh.discourse.group/t/using-openssl-to-implement-cryptography/9107):
>
> Hi, I’m writing a program to transmit SMS message on WP7702, I would like to encrypt the message before it is transmitted over the network. I wonder how can I use openssl lib on Legato? sample code would be very helpful!! Thanks
