getting started with the fp-cld-aws1 software package for ... · 2 fp-cld-aws1 software description...

26
March 2017 DocID030431 Rev 1 1/26 www.st.com UM2186 User manual Getting started with the FP-CLD-AWS1 software package for IoT node with Wi-Fi and sensors, connected to Amazon AWS IoT cloud Introduction FP-CLD-AWS1 is an STM32 ODE function pack. Thanks to this package you can directly connect your IoT node to the Amazon AWS IoT platform, transmit and receive sensor data and commands to and from AWS services. This package can jump-start any end-to-end IoT development, saving you time in the integration of the different basic functions needed for a sensor-to-cloud development environment. This software package implements application level functions based on the MQTT protocol and enables communication with the Amazon AWS IoT platform. Developers can use it to prototype end-to-end IoT applications together with Amazon AWS cloud services, to easily transmit and receive real time sensor data. The software runs on the STM32 microcontroller and includes drivers for the Wi-Fi module (SPWF01SA), and sensor devices (HTS221, LPS25HB, LSM6DS0, LIS3MDL, LSM6DSL and LSM303AGR).

Upload: ngokhanh

Post on 04-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

March 2017 DocID030431 Rev 1 1/26

www.st.com

UM2186 User manual

Getting started with the FP-CLD-AWS1 software package for IoT node with Wi-Fi and sensors, connected to Amazon AWS IoT cloud

Introduction FP-CLD-AWS1 is an STM32 ODE function pack. Thanks to this package you can directly connect your IoT node to the Amazon AWS IoT platform, transmit and receive sensor data and commands to and from AWS services. This package can jump-start any end-to-end IoT development, saving you time in the integration of the different basic functions needed for a sensor-to-cloud development environment.

This software package implements application level functions based on the MQTT protocol and enables communication with the Amazon AWS IoT platform. Developers can use it to prototype end-to-end IoT applications together with Amazon AWS cloud services, to easily transmit and receive real time sensor data.

The software runs on the STM32 microcontroller and includes drivers for the Wi-Fi module (SPWF01SA), and sensor devices (HTS221, LPS25HB, LSM6DS0, LIS3MDL, LSM6DSL and LSM303AGR).

Contents UM2186

2/26 DocID030431 Rev 1

Contents

1 Acronyms and abbreviations ......................................................... 5

2 FP-CLD-AWS1 software description .............................................. 6

2.1 Overview ........................................................................................... 6

2.2 Architecture ....................................................................................... 6

2.3 Folder structure ................................................................................. 7

2.4 APIs .................................................................................................. 8

3 Amazon AWS IoT service setup ..................................................... 9

3.1 Overview ........................................................................................... 9

3.2 AWS management console configuration steps ................................ 9

3.2.1 Device certificate ................................................................................ 9

3.2.2 Create a CSR using OpenSSL and upload it to AWS IoT console .. 10

4 FP-CLD-AWS1 sample application description ........................... 12

4.1 Source code update with AWS IoT configuration ............................ 12

4.1.1 Changes in aws_iot_config.h ........................................................... 12

4.1.2 Changes in aws_nucleo_certificates.c ............................................. 13

4.2 Configure Wi-Fi access point parameters and connect the STM32 Nucleo board to the AWS IoT console ......................................................... 15

5 System setup guide ....................................................................... 18

5.1 Hardware description ...................................................................... 18

5.1.1 STM32 Nucleo platform .................................................................... 18

5.1.2 X-NUCLEO-IDW01M1 expansion board .......................................... 19

5.1.3 X-NUCLEO-IKS01A1 expansion board ............................................ 20

5.1.4 X-NUCLEO-IKS01A2 expansion board ............................................ 21

5.2 Hardware setup ............................................................................... 21

5.2.1 STM32 Nucleo and expansion board setup ..................................... 21

5.3 Software requirements .................................................................... 23

5.4 Sofware setup ................................................................................. 23

5.4.1 Development tool-chains and compilers .......................................... 24

6 Revision history ............................................................................ 25

UM2186 List of tables

DocID030431 Rev 1 3/26

List of tables

Table 1: List of acronyms ............................................................................................................................ 5 Table 2: Document revision history .......................................................................................................... 25

List of figures UM2186

4/26 DocID030431 Rev 1

List of figures

Figure 1: FP-CLD-AWS1 software architecture .......................................................................................... 7 Figure 2: FP- CLD-AWS1 package folder structure ................................................................................... 7 Figure 3: Certificate creation through CSR file in the AWS console ........................................................ 10 Figure 4: CSR file upload to AWS console ............................................................................................... 11 Figure 5: Successful certificate creation ................................................................................................... 11 Figure 6: AWS IoT dashboard: Thing details ............................................................................................ 13 Figure 7: Certificate download .................................................................................................................. 13 Figure 8: SSID and password setup via serial interface ........................................................................... 16 Figure 9: Terminal sensor data view ......................................................................................................... 17 Figure 10: STM32 Nucleo board ............................................................................................................... 18 Figure 11: X-NUCLEO-IDW01M1 Wi-Fi expansion board ........................................................................ 19 Figure 12: X-NUCLEO-IKS01A1 expansion board ................................................................................... 20 Figure 13: X-NUCLEO-IKS01A2 MEMS and environmental sensor expansion board ............................ 21 Figure 14: X-NUCLEO-IDW01M1 Wi-Fi expansion board connected to an STM32 Nucleo via morpho connectors ................................................................................................................................................ 22 Figure 15: X-NUCLEO-IKS01A2 sensor expansion board connected to an STM32 Nucleo on top of X-NUCLEO-IDW01M1 expansion board ...................................................................................................... 23

UM2186 Acronyms and abbreviations

DocID030431 Rev 1 5/26

1 Acronyms and abbreviations Table 1: List of acronyms

Acronym Description

AP Access point

BSP Base support package

FOTA Firmware update over-the-air

GPIO General purpose input/output

HAL Hardware abstraction layer

HTML Hypertext markup language

HTTP Hypertext transfer protocol

IDE Integrated development environment

IoT Internet of things

I2C Inter-integrated circuit

MCU Microcontroller unit

MEMS Micro electro-mechanical systems

ODE Open development environment

REST API Representational state transfer API

SDK Software sevelopment kit

SMD Surface mount device

SSID Service set identifier

UART Universal asynchronous receiver/transmitter

URL Uniform resource locator

WLAN Wireless local area network

FP-CLD-AWS1 software description UM2186

6/26 DocID030431 Rev 1

2 FP-CLD-AWS1 software description

2.1 Overview

The package features:

Complete middleware to build applications based on Wi-Fi connectivity, inertial and environmental sensors and to connect STM32 Nucleo boards to the Amazon AWS IoT cloud platform

Software interface to access temperature and humidity sensor (HTS221), pressure sensor (LPS25HB), and motion sensors (LIS3MDL, LSM6DS0, LSM6DSL and LSM303AGR)

Integrated Amazon AWS IoT C-SDK Software Development Kit for easy access to Cloud services provided by Amazon AWS

Sample application for X-NUCLEO-IKS01A2, X-NUCLEO-IKS01A1 and X-NUCLEO-IDW01M1 boards connected to a NUCLEO-F401RE board

Free, user-friendly license terms

How does this STM32 ODE Function Pack complement STM32Cube?

The proposed software is based on the STM32CubeHAL hardware abstraction layer for the STM32 microcontroller. The package extends STM32Cube by providing a board support package (BSP) for the Wi-Fi and the sensor expansion boards. The drivers abstract low-level details of the hardware and allow the middleware components and applications to access and control sensor data and Wi-Fi communication interface in a hardware-independent manner.

The package includes middleware implementing the Application Program Interfaces for easy interaction of an STM32 Nucleo based development kit with Amazon web services (AWS). Developers can use it to prototype end-to-end IoT applications by registering the STM32 Nucleo based development kit with the AWS IoT cloud platform and easily start to transmit and receive sensor data and commands in real time.

2.2 Architecture

The software layers used by the application software to access and use the STM32 microcontroller, the Wi-Fi and the sensor expansion boards are:

STM32Cube HAL layer: consists of a simple, generic and multi-instance set of APIs (application programming interfaces) to interact with the upper application, library and stack layers. These generic and extension APIs are directly built around a generic architecture and allows layers like the middleware layer built on top of them to implement their functions without requiring specific hardware configuration information for given microcontroller units (MCU). This structure improves library code reusability and guarantees easy portability across other devices.

Board support package (BSP) layer: supports the peripherals on the STM32 Nucleo board, except the MCU. This limited set of APIs provides a programming interface for certain board specific peripherals like the LED and user button. This interface also helps in identifying the specific board version.

Middleware layers:

AWS IoT Embedded C SDK (https://github.com/aws/aws-iot-device-sdk-embedded-C): used to connect the STM32 Nucleo microsystem to the AWS IoT Platform; it is integrated in the STM32Cube package;

an RTOS environment (FreeRTOS): required by Amazon AWS IoT device SDK to run;

UM2186 FP-CLD-AWS1 software description

DocID030431 Rev 1 7/26

a network interface (TCP/IP) for the SPWF01SA Wi-Fi module: AWS IoT device SDK requires TLS protocol for secure communication. TLS interface is provided by the the SPWF01SA Wi-Fi module.

Figure 1: FP-CLD-AWS1 software architecture

2.3 Folder structure

Figure 2: FP- CLD-AWS1 package folder structure

The folders in the software package are:

Documentation: contains a compiled HTML file generated from the source code, which details the software components and APIs.

Drivers: contains the HAL drivers, the board-specific drivers for each supported board or hardware platform (including those for the onboard components) and the CMSIS vendor-independent hardware abstraction layer for the Cortex-M processor series.

Middlewares: contains the middleware interface for Wi-Fi, FreeRTOS real time operating system and the porting of Amazon AWS IoT device SDK.

Projects: contains sample applications which can be used to connect STM32 Nucleo and sensors to Amazon AWS IoT via Wi-Fi. Projects are provided for the NUCLEO-F401RE platform with three development environments: IAR Embedded Workbench

FP-CLD-AWS1 software description UM2186

8/26 DocID030431 Rev 1

for ARM, RealView Microcontroller Development Kit (MDK-ARM) and System Workbench for STM32.

2.4 APIs

Detailed user API function and parameter descriptions are available in a compiled HTML file in the package Documentation folder.

The AWS IoT MQTT client sample application runs on FreeRTOS within a single task

named void AwsIotTask (void * pvParameters).

The main APIs used in this sample application are:

IoT_Error_t aws_iot_mqtt_init (AWS_IoT_Client *pClient,

IoT_Client_Init_Params *pInitParams): this function is called to initialize the

MQTT client and requires "reference to the IoT client" and "pointer to MQTT initialization" as parameters.

IoT_Error_t aws_iot_mqtt_connect (AWS_IoT_Client *pClient,

IoT_Client_Connect_Params *pConnectParams): this function is called to

establish an MQTT connection with the AWS IoT service and requires "reference to the IoT client" and "pointer to MQTT connection" as parameters.

IoT_Error_t aws_iot_mqtt_subscribe (AWS_IoT_Client *pClient,

const char *pTopicName, uint16_t topicNameLen, QoS qos,

pApplicationHandler_t pApplicationHandler, void

*pApplicationHandlerData): this function is called to send a subscription

request to an MQTT topic and requires the following parameters: "reference to the IoT client", "topic name" to publish, "topic name length", "reference to the handler function" for the subscription in subject and "data" to be transmitted as argument to the application handler callback.

IoT_Error_t aws_iot_mqtt_yield (AWS_IoT_Client *pClient,

uint32_t timeout_ms): this function is called to yield the current thread to the

underlying MQTT client. This time is used by the MQTT client to manage PING requests to monitor the stability of the TCP connection and periodically check the socket receive buffer for subscription messages. Yield () must be called at a rate faster than this interval and the incoming message rate: this is the only way the client can receive processing time to manage incoming messages. This function requires as parameters: "reference to the IoT client" and "maximum number of milliseconds" to pass thread execution to the client.

IoT_Error_t aws_iot_mqtt_publish (AWS_IoT_Client *pClient,

const char *pTopicName, uint16_t topicNameLen,

IoT_Publish_Message_Params *pParams): this function is called to publish an

MQTT message in a topic and requires as parameters: "reference to the IoT client", "topic name" to publish, "topic name length", "pointer to publish message".

UM2186 Amazon AWS IoT service setup

DocID030431 Rev 1 9/26

3 Amazon AWS IoT service setup

3.1 Overview

Before running the test application included in the FP-CLD-AWS1 package, it is necessary to set up the proper development environment in Amazon AWS IoT as follows:

1. create a free account in Amazon AWS (https://aws.amazon.com) 2. log in, select AWS IoT services and register your device

3.2 AWS management console configuration steps

Once you have created an account in Amazon AWS and signed in with your credentials, select AWS IoT services to enter the AWS IoT console: a web-based interface to access and manage your AWS IoT resources.

In the console management:

1 Create a device in the Thing Registry (http://docs.aws.amazon.com/iot/latest/developerguide/create-device.html).

2 Create and activate a device certificate (http://docs.aws.amazon.com/iot/latest/developerguide/create-device-certificate.html).

You have to create your Private Key file and certificate signing request (CSR) file offline, upload CSR to AWS IoT console instead of going through the 1-Click certificate creation process described in AWS documentation (see Section 3.2.2:

"Create a CSR using OpenSSL and upload it to AWS IoT console").

3 Create an AWS IoT policy (http://docs.aws.amazon.com/iot/latest/developerguide/create-

iot-policy.html)

When requested, add the following policy parameters: Action : iot:* and

Resource : *

4 Attach an AWS IoT policy to device certificate (http://docs.aws.amazon.com/iot/latest/developerguide/attach-policy-to-certificate.html)

5 Attach a Thing to certificate (http://docs.aws.amazon.com/iot/latest/developerguide/attach-cert-thing.html)

Your STM32 Nucleo device is now ready for communication with AWS IoT.

3.2.1 Device certificate

The communication between an STM32 Nucleo development board and AWS IoT is protected through the use of an X.509 device digital certificate which uses public key infrastructure (PKI) standard.

Through Amazon IoT, you can generate an X.509 certificate:

1. by following the standard procedure documented in http://docs.aws.amazon.com/iot/latest/developerguide/create-device-certificate.html which consists of using AWS console and generating the private and public keys for the certificate;

2. by using AWS console, creating the private and public keys for the certificate offline together with the certificate signing request (CSR) file, and then uploading to AWS IoT console

Amazon AWS IoT service setup UM2186

10/26 DocID030431 Rev 1

To use FP-CLD-AWS1, follow the second procedure (see Section 3.2.2: "Create a CSR using OpenSSL and upload it to AWS IoT console").

3.2.2 Create a CSR using OpenSSL and upload it to AWS IoT console

OpenSSL is an open source project that consists of a cryptographic library and an SSL/TLS toolkit (for documentation and installation instructions, refer to OpenSSL website, www.openssl.org).

After installation, OpenSSL commands can be used to generate Private Key and CSR file.

To create Private Key, launch the command OpenSSL ecparam -out my_ec_key.pem

-name prime256v1 -genkey: an EC Private Key will be created in “my_ec_key.pem”

file.

To create a CSR, launch the command OpenSSL req -new -config my_config.cnf

-key my_ec_key.pem -out my_ec_key.csr: the CSR will be created in

“my_ec_key.csr” file.

This command requires a configuration file (cnf) to be run which must be modified with custom details (for information on how to create a .cnf file, refer to OpenSSL documentation).

The following is a sample configuration file:

[req]

prompt = no

distinguished_name = dn

req_extensions = ext

[dn]

CN = www.xxx.com

emailAddress = [email protected]

O = XXX

L = XXX

C = XX

[ext]

Once created, the CSR file has to be uploaded in the AWS IoT console: click on “Create with CSR” button to create the certificate for your device using the .csr file previously generated with OpenSSL.

Figure 3: Certificate creation through CSR file in the AWS console

UM2186 Amazon AWS IoT service setup

DocID030431 Rev 1 11/26

Figure 4: CSR file upload to AWS console

Your certificate will be created:

Figure 5: Successful certificate creation

FP-CLD-AWS1 sample application description UM2186

12/26 DocID030431 Rev 1

4 FP-CLD-AWS1 sample application description

A sample application using the X-NUCLEO-IKS01A2 or X-NUCLEO-IKS01A1 and X-NUCLEO-IDW01M1 expansion boards with the NUCLEO-F401RE board is provided in the "Projects" directory.

Ready-to-build projects are available for multiple IDEs.

This application reads the data values from the temperature, humidity, pressure, accelerometer, magnetometer and gyroscope sensors and transmits them to the Amazon AWS IoT via Wi-Fi.

In order to run the application, set up Amazon AWS services as described in Section 3: "Amazon AWS IoT service setup". Next, several details need to be updated in the package source code before recompiling the projects (see Section 4.1: "Source code update with AWS IoT configuration"). When the binary code is ready and flashed to the Nucleo board, the application can be launched as described in Section 4.2: "Configure Wi-Fi access point parameters and connect the STM32 Nucleo board to the AWS IoT console".

4.1 Source code update with AWS IoT configuration

This section describes the FP-CLD-AWS1 source file to be updated with Amazon credentials and device certificates.

4.1.1 Changes in aws_iot_config.h

The following "defines" have to be updated in Middlewares/Third_Parties/aws-sdk /samples/nucleo/sub_pub/aws_iot_config.h:

AWS_IOT_MY_THING_NAME: it is the name of the Thing associated to the Nucleo

device and created in AWS IoT Console, as described in Section 3: "Amazon AWS

IoT service setup". For example: #define AWS_IOT_MY_THING_NAME "stnoidatp1"

AWS_IOT_MQTT_CLIENT_ID: MQTT client ID should be unique for every device; it

can be the same as Thing name. For example: #define AWS_IOT_MQTT_CLIENT_ID "stnoidatp1"

AWS_IOT_MQTT_HOST: it can be retrieved from the AWS IoT dashboard by selecting

details tab of the Thing (see the figure below). For example: #define

AWS_IOT_MQTT_HOST "AG6ASB6KLJ2M.iot.us-east-1.amazonaws.com". It

can be retrieved from the AWS IoT dashboard by selecting Registry => Things => stnoidatp1 => Interact.

UM2186 FP-CLD-AWS1 sample application description

DocID030431 Rev 1 13/26

Figure 6: AWS IoT dashboard: Thing details

4.1.2 Changes in aws_nucleo_certificates.c

The file Middlewares/Third_Parties/aws-sdk/platform/nucleo/aws_nucleo_certificates.c contains two variables to be updated: uint8_t clientCRT [], Device Identity Certificate and uint8_t clientKey[], Device Private Key.

uint8_t clientCRT [], Device Identity Certificate

This variable contains the X.509 device certificate which can be downloaded from AWS IoT console, by selecting the certificate icon, as shown below:

Figure 7: Certificate download

FP-CLD-AWS1 sample application description UM2186

14/26 DocID030431 Rev 1

Once downloaded, the file received from AWS contains data in the following format:

-----BEGIN CERTIFICATE-----

MIIC2DCCAcCgAwIBAgIVAKX1mBt63N3G39cAnz7U7JX1Hd6DMA0GCSqGSIb3DQEB

CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t

IEluYy4gTD1TZWF0dGxlIFNUPVdhc2hpbmd0b24gQz1VUzAeFw0xNjAzMDgwODQ3

MTNaFw00OTEyMzEyMzU5NTlaMGcxEzARBgNVBAMMCnd3dy5zdC5jb20xJDAiBgkq

hkiG9w0BCQEWFWFudXAta3VtYXIuZGFzQHN0LmNvbTEMMAoGA1UECgwDU1RNMQ8w

DQYDVQQHDAZHTm9pZGExCzAJBgNVBAYTAklOMFkwEwYHKoZIzj0CAQYIKoZIzj0D

AQcDQgAEBtVHX1Clq0KezbzauSpNSvFFy4Dj+pcfKyNVtquy1zrVkUoQJjNHQjY0

smphQv/y7xvlXMZF96BaCb6E4K8VXaNgMF4wHwYDVR0jBBgwFoAU6XIqHcA8mtSX

JyqxwPGn6hS9DWIwHQYDVR0OBBYEFAO3NTsRZhOto7YJUCHKUJ62fuAHMAwGA1Ud

EwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUAA4IBAQAF2oVC

dyo+V/+lDZh+A9hxSWI85hIGL4o6GWHbqgCtZGIPtU5kKwATfl0QjSmxTXbYSSFD

18c1OJNCvG0EA8t9ScHPSzOY6hJ+mW0uxd8em1n2oWjCpLmvHPUWwnnnijXPNZ9t

x73jNVxJCGLuk0lI22hzHetV2cFxYBhKh9nPSagxKIwJye9qL7I6yLqgfbKvr5Ob

7Z7lDoeIHyXsQ5jjTCFqjR7hJ47v8WKJOOs87VV2stGUQW5CAHnk+oZyaXqnSiYB

USsyEx2MA7asEs237BpiNOx0RhBhVuP/CtafigBTBqubH8yHV4NclCLnigW+UzTA

BseHclKIGJJK3bnM

-----END CERTIFICATE-----

This X.509 certificate is a string of bytes stored in a TXT format file. At the end of each byte string line in the TXT file, there is a new line character, ‘\n’.

The FP-CLD-AWS1 package does not use the TXT format certificate file directly in the code. It uses the data from the file as an unsigned char array (c programming structure). To store the data in the array we need to add extra characters to satisfy the X.509 certificate structure and also C programming requirements.

Changes required by X.509 certificate format are:

Add \n after -----BEGIN CERTIFICATE----- string line

Add \n before -----END CERTIFICATE----- string line

Add \n after -----END CERTIFICATE----- string line

The only change required by C programming requirements is to add backward slash character (\) at the end of each line of character string.

Copy the data in the array in the following format:

uint8_t clientCRT[] = "\

-----BEGIN CERTIFICATE-----\n\

MIIC2DCCAcCgAwIBAgIVAKX1mBt63N3G39cAnz7U7JX1Hd6DMA0GCSqGSIb3DQEB\

CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t\

IEluYy4gTD1TZWF0dGxlIFNUPVdhc2hpbmd0b24gQz1VUzAeFw0xNjAzMDgwODQ3\

MTNaFw00OTEyMzEyMzU5NTlaMGcxEzARBgNVBAMMCnd3dy5zdC5jb20xJDAiBgkq\

hkiG9w0BCQEWFWFudXAta3VtYXIuZGFzQHN0LmNvbTEMMAoGA1UECgwDU1RNMQ8w\

DQYDVQQHDAZHTm9pZGExCzAJBgNVBAYTAklOMFkwEwYHKoZIzj0CAQYIKoZIzj0D\

AQcDQgAEBtVHX1Clq0KezbzauSpNSvFFy4Dj+pcfKyNVtquy1zrVkUoQJjNHQjY0\

smphQv/y7xvlXMZF96BaCb6E4K8VXaNgMF4wHwYDVR0jBBgwFoAU6XIqHcA8mtSX\

JyqxwPGn6hS9DWIwHQYDVR0OBBYEFAO3NTsRZhOto7YJUCHKUJ62fuAHMAwGA1Ud\

EwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMA0GCSqGSIb3DQEBCwUAA4IBAQAF2oVC\

dyo+V/+lDZh+A9hxSWI85hIGL4o6GWHbqgCtZGIPtU5kKwATfl0QjSmxTXbYSSFD\

18c1OJNCvG0EA8t9ScHPSzOY6hJ+mW0uxd8em1n2oWjCpLmvHPUWwnnnijXPNZ9t\

x73jNVxJCGLuk0lI22hzHetV2cFxYBhKh9nPSagxKIwJye9qL7I6yLqgfbKvr5Ob\

7Z7lDoeIHyXsQ5jjTCFqjR7hJ47v8WKJOOs87VV2stGUQW5CAHnk+oZyaXqnSiYB\

USsyEx2MA7asEs237BpiNOx0RhBhVuP/CtafigBTBqubH8yHV4NclCLnigW+UzTA\

BseHclKIGJJK3bnM\

\n-----END CERTIFICATE-----\n

uint8_t clientKey[], Device Private Key

This variable contains the Device Private Key generated with OpenSSL (.pem file as described in Section 3.2.2: "Create a CSR using OpenSSL and upload it to AWS IoT console").

-----BEGIN EC PARAMETERS-----

BggqhkjOPQMBBw==

-----END EC PARAMETERS-----

UM2186 FP-CLD-AWS1 sample application description

DocID030431 Rev 1 15/26

-----BEGIN EC PRIVATE KEY-----

MHcCAQEEICASgpjAQK+JTScxRh6f8fTZ5QlSYXDqiskyRPMpx2JpoAoGCCqGSM49

AwEHoUQDQgAEBtVHX1Clq0KezbzauSpNSvFFy4Dj+pcfKyNVtquy1zrVkUoQJjNH

QjY0smphQv/y7xvlXMZF96BaCb6E4K8VXQ==

-----END EC PRIVATE KEY-----

As described above in uint8_t clientCRT [], Device Identity Certificate, also this private key is generated in a TXT format file. Therefore, the changes to be done are similar to the ones listed above.

Changes required by X.509 certificate format are:

Add \n after -----BEGIN EC PARAMETERS-----string line

Add \n before -----END EC PARAMETERS----- string line

Add \n after -----END EC PARAMETERS----- string line

Add \n after -----BEGIN EC PRIVATE KEY-----string line

Add \n before -----END EC PRIVATE KEY----- string line

Add \n after -----END EC PRIVATE KEY----- string line

The only change required by C programming requirements is to add backward slash character (\) at the end of each line of character string.

Modify the variable uint8_t clientKey[]:

uint8_t clientKey[] ="\

-----BEGIN EC PARAMETERS-----\n\

BggqhkjOPQMBBw==\

\n-----END EC PARAMETERS-----\n\

-----BEGIN EC PRIVATE KEY-----\n\

MHcCAQEEICASgpjAQK+JTScxRh6f8fTZ5QlSYXDqiskyRPMpx2JpoAoGCCqGSM49\

AwEHoUQDQgAEBtVHX1Clq0KezbzauSpNSvFFy4Dj+pcfKyNVtquy1zrVkUoQJjNH\

QjY0smphQv/y7xvlXMZF96BaCb6E4K8VXQ==\

\n-----END EC PRIVATE KEY-----\n"

4.2 Configure Wi-Fi access point parameters and connect the STM32 Nucleo board to the AWS IoT console

Once AWS IoT cloud setup has been completed and the hardware setup is configured (see Section 5: "System setup guide"), use a serial line monitor to visualize messages from your STM32 Nucleo-based system.

The serial terminal must be configured with the following parameters:

BaudRate: 460800

Data: 8 bit

Parity: none

Stop: 1 bit

Flow control: none

Newline RX: CR+LF

Newline TX: CR

To connect your STM32 Nucleo-based system with a Wi-Fi access point (AP), you have to configure the corresponding SSID and password, by typing them in the serial interface.

FP-CLD-AWS1 sample application description UM2186

16/26 DocID030431 Rev 1

Access point parameter configuration via serial interface

reset the STM32 Nucleo board;

wait until you are asked to type SSID and password in the serial interface, as shown in the following picture:

Figure 8: SSID and password setup via serial interface

type SSID and password;

the application reads the parameters from the serial interface and use them to connect to the AP.

Once the STM32 Nucleo board is connected to a Wi-Fi access point, the MQTT client application automatically contacts the AWS IoT console. To publish and subscribe sensor data, press the User Button (Blue Button) on the STM32 Nucleo board.

Sensor data log can be viewed in the hyper terminal application.

UM2186 FP-CLD-AWS1 sample application description

DocID030431 Rev 1 17/26

Figure 9: Terminal sensor data view

Once received by the AWS IoT console, sensor data can be used to develop cloud applications relying on Amazon AWS IoT, and build end-to-end IoT systems.

System setup guide UM2186

18/26 DocID030431 Rev 1

5 System setup guide

5.1 Hardware description

This section summarizes the hardware components needed for connecting the STM32 Nucleo based platform to the Amazon AWS IoT console.

5.1.1 STM32 Nucleo platform

STM32 Nucleo development boards provide an affordable and flexible way for users to test solutions and build prototypes with any STM32 microcontroller line.

The Arduino™ connectivity support and ST morpho connectors make it easy to expand the functionality of the STM32 Nucleo open development platform with a wide range of specialized expansion boards to choose from.

The STM32 Nucleo board does not require separate probes as it integrates the ST-LINK/V2-1 debugger/programmer.

The STM32 Nucleo board comes with the comprehensive STM32 software HAL library together with various packaged software examples.

Figure 10: STM32 Nucleo board

Information regarding the STM32 Nucleo board is available at www.st.com/stm32nucleo

UM2186 System setup guide

DocID030431 Rev 1 19/26

5.1.2 X-NUCLEO-IDW01M1 expansion board

The X-NUCLEO-IDW01M1 is a Wi-Fi evaluation board based on the SPWF01SA module, which expands the STM32 Nucleo boards. The CE, IC and FCC certified SPWF01SA module has an embedded STM32 MCU, a low-power Wi-Fi b/g/n SoC with integrated power amplifier and power management and an SMD antenna. The SPWF01SA module is also equipped with 1 MByte of external FLASH for firmware update over-the-air (FOTA). The firmware features a complete software IP stack to open up to 8 TCP/UDP sockets, as well as dynamic web pages with SSI to interact with the module and a REST API (get & post) for conveniently transferring files to/from servers in the cloud. The module can simultaneously behave as a socket server and socket client. The firmware supports secure sockets with TLS/SSL encryption, ensuring secure end-to-end communications with the cloud, with or without authentication. The module operates as a client STA, IBSS, or miniAP (with up to 5 client STAs). The X-NUCLEO-IDW01M1 interfaces with the MCU on the STM32 Nucleo board via the UART serial port; the user can easily access the stack functions using the AT command. X-NUCLEO-IDW01M1 is compatible with both the ST morpho and Arduino UNO R3 connector layout.

Figure 11: X-NUCLEO-IDW01M1 Wi-Fi expansion board

Information regarding the expansion board is available on www.st.com at http://www.st.com/x-nucleo.

System setup guide UM2186

20/26 DocID030431 Rev 1

5.1.3 X-NUCLEO-IKS01A1 expansion board

The X-NUCLEO-IKS01A1 is a sensor expansion board for the STM32 Nucleo board. It is also compatible with Arduino UNO R3 connector layout and is designed around humidity (HTS221), pressure (LPS25HB) and motion (LIS3MDL and LSM6DS0) sensing devices. The X-NUCLEO-IKS01A1 interfaces with the STM32 MCU via the I²C pin, and the user can change the default I²C port and the device IRQ by changing a resistor on the evaluation board.

You can attach the LSM6DS3 DIL24 expansion component and use it instead of the one of the LSM6DS0 sensors.

Figure 12: X-NUCLEO-IKS01A1 expansion board

UM2186 System setup guide

DocID030431 Rev 1 21/26

5.1.4 X-NUCLEO-IKS01A2 expansion board

The X-NUCLEO-IKS01A2 is a motion MEMS and environmental sensor expansion board for the STM32 Nucleo.

It is equipped with Arduino UNO R3 connector layout, and is designed around the LSM6DSL 3D accelerometer and 3D gyroscope, the LSM303AGR 3D accelerometer and 3D magnetometer, the HTS221 humidity and temperature sensor and the LPS22HB pressure sensor.

The X-NUCLEO-IKS01A2 interfaces with the STM32 microcontroller via the I²C pin, and it is possible to change the default I²C port.

Figure 13: X-NUCLEO-IKS01A2 MEMS and environmental sensor expansion board

5.2 Hardware setup

The following hardware components are needed:

1. An STM32 Nucleo development platform (order code: NUCLEO-F401RE) 2. A Wi-Fi expansion board (order code: X-NUCLEO-IDW01M1) 3. A sensor expansion board (order code: X-NUCLEO-IKS01A2 or X-NUCLEO-IKS01A1) 4. A USB type A to Mini-B USB cable to connect the STM32 Nucleo to the PC

5.2.1 STM32 Nucleo and expansion board setup

The STM32 Nucleo board integrates the ST-LINK/V2-1 debugger/programmer

The developer can download the relevant version of the ST-LINK/V2-1 USB driver on www.st.com (for Windows OS).

The X-NUCLEO-IDW01M1 Wi-Fi expansion board can be connected to an STM32 Nucleo through the morpho extension connector, as shown below.

System setup guide UM2186

22/26 DocID030431 Rev 1

Figure 14: X-NUCLEO-IDW01M1 Wi-Fi expansion board connected to an STM32 Nucleo via morpho connectors

Finally, the X-NUCLEO-IKS01A2 or X-NUCLEO-IKS01A1 sensor expansion board can be easily connected to X-NUCLEO-IDW01M1 Wi-Fi expansion board through the Arduino UNO R3 extension connector, as shown below.

UM2186 System setup guide

DocID030431 Rev 1 23/26

Figure 15: X-NUCLEO-IKS01A2 sensor expansion board connected to an STM32 Nucleo on top of X-NUCLEO-IDW01M1 expansion board

5.3 Software requirements

The following software components are needed in order to set up a suitable development environment for compiling and running the FP-CLD-AWS1 package:

FP-CLD-AWS1 software, available on www.st.com/stm32ode

One of the following development tool-chain and compilers:

IAR Embedded Workbench for ARM® (EWARM) toolchain + ST-LINK

RealView Microcontroller Development Kit (MDK-ARM) toolchain + ST-LINK

System Workbench for STM32 (SW4STM32) + ST-LINK

a serial line monitor (e.g. Tera Term, http://www.compuphase.com/software_termite.htm)

5.4 Sofware setup

This section lists the minimum requirements for the developer to set up the FP-CLD-AWS1 SDK, run the sample testing scenario and customize applications.

System setup guide UM2186

24/26 DocID030431 Rev 1

5.4.1 Development tool-chains and compilers

Select one of the integrated development environments supported by the software package and listed in Section 5.3: "Software requirements", and refer to the system and setup information provided by the selected IDE provider. Project files for all three supported IDEs can be found in FP-CLD-AWS1 package Projects/Multi/Applications/MQTT_AWS/ folder.

UM2186 Revision history

DocID030431 Rev 1 25/26

6 Revision history Table 2: Document revision history

Date Version Changes

22-Mar-2017 1 Initial release

UM2186

26/26 DocID030431 Rev 1

IMPORTANT NOTICE – PLEASE READ CAREFULLY

STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications , and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.

Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of Purchasers’ products.

No license, express or implied, to any intellectual property right is granted by ST herein.

Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.

ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.

Information in this document supersedes and replaces information previously supplied in any prior versions of this document.

© 2017 STMicroelectronics – All rights reserved