The NixCore X1 supports the Amazon Web Services (AWS) Embedded C SDK. Here are the steps required to get AWS compiled and linked to a project for the NixCore X1.
Pre-requirements
- Build environment with binutils, make, etc
- OpenWRT/LEDE Build or NixCore X1 SDK with gcc
Instructions
These instructions are provided to show how to compile the AWS SDK and a simple test program. Paths will need to be adjusted to match the location of your NixCore SDK and the project path
Setup
- Create a project directory: mkdir ~/awstest/;cd ~/awstest/
- Download the AWS Embedded C SDK: git clone https://github.com/aws/aws-iot-device-sdk-embedded-C.git aws_sdk
- Download the mbedTLS library archive: https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.1.1.tar.gz
- Download the NixCore X1 AWS SDK Makefile from GitHub
Build mbedTLS
The AWS SDK uses the mbedTLS library, the library must be built using the NixCore X1 compiler before compiling the AWS SDK.
- tar zxfv mbedtls-2.1.1.tar.gz
- cp -rf mbedtls-mbedtls-2.1.1/* aws_sdk/external_libs/mbedTLS/
- pushd ln_aws/external_libs/mbedTLS/
- make clean
- export CC=<PATH_TO_NIXCORE_GCC>
- make lib
- popd
Build AWS SDK
We provide a Makefile which is based on the Makefiles provided in the samples of the SDK. This Makefile will create a static ‘.a’ library to be linked into your application. The AWS SDK requires aws_iot_config.h in the local project, in this example we use the aws_iot_config.h from the sample project. Changes to this file require an SDK re-compile.
- Edit Makefile.aws
- change CC=<PATH_TO_NIXCORE_GCC>
- change IOT_CLIENT_DIR=<PATH_TO_AWS_SDK> (In this example it is aws_sdk)
- Copy the aws_iot_config.h from the sample: cp aws_sdk/samples/linux/subscribe_publish_library_sample/aws_iot_config.h .
- make clean -f Makefile.aws
- make -f Makefile.aws
After these commands you should have the file libAwsIotSdk.a in the project directory.
Linking AWS SDK
After the mbedTLS and AWS SDK libraries are compiled they must be linked into your application. Here are the libraries required to be linked:
- libAwsIotSdk.a
- libmbedtls.a
- libmbedcrypto.a
- libmbedx509.a
- pthread
- dl
Makefile definitions
Here are some Makefile entries to ensure that the correct Include and Library paths are passed to the compiler.
AWS_PATH = aws_sdk TLS_DIR = $(AWS_PATH)/external_libs/mbedTLS PLATFORM_DIR = $(AWS_PATH)/platform/linux/mbedtls PLATFORM_COMMON_DIR = $(AWS_PATH)/platform/linux/common IOT_INCLUDE_DIRS += -I $(AWS_PATH)/include IOT_INCLUDE_DIRS += -I $(AWS_PATH)/external_libs/jsmn IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) IOT_INCLUDE_DIRS += -I $(TLS_DIR)/include AWS_LDFLAGS = -l:libAwsIotSdk.a #TLS - mbedtls MBEDTLS_DIR = $(AWS_PATH)/external_libs/mbedTLS TLS_LIB_DIR = $(MBEDTLS_DIR)/library TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include EXTERNAL_LIBS += -L $(TLS_LIB_DIR) TLS_LDFLAG = -Wl,-rpath,$(TLS_LIB_DIR) TLS_LDFLAG += -ldl -l:libmbedtls.a -l:libmbedcrypto.a -l:libmbedx509.a -lpthread ###### Example usage INCLUDE = -I . $(IOT_INCLUDE_DIRS) $(TLS_INCLUDE_DIR) LIBS = -L . $(EXTERNAL_LIBS) LDFLAGS = $(AWS_LDFLAGS) $(TLS_LDFLAG) gcc $(INCLUDE) main.c -o main.o gcc -s -o aws.bin main.o $(LIBS) $(LDFLAGS)