How to connect your device to AWS IoT Platform using TapNLink NFC-WIFI Primer
Introduction
AWS IoT is a managed cloud platform that lets connected devices interact easily and securely with cloud applications and other devices.
We will show how TapNLink NFC-WIFI can connect to AWS IoT to use features like Device Shadows, JSON documents (used to store and retrieve devices' current state information), and the Rules Engine (which provides message processing and integration with other AWS services), to build a really connected product that receives commands from the cloud using MQTT protocol.
Prerequisites
-
TapNLink Primer WiFi Evaluation Kit: this kit allows IoT designers to evaluate all the advantages of IoTize TapNLink products for building a connected electronic system. You can purchase a TapNLink Primer Evaluation Kit from Digikey.
-
IoTize Studio: the PC-based configuration software that can configure TapNLink Primer to communicate with AWS IoT Platform. You can download and install the software from IoTize website.
Step1: Setup your AWS IoT account
The first step is to create an AWS IoT account: https://aws.amazon.com/.
Follow the online instructions, sign in to the AWS Management Console and open the AWS IoT console.
Step2: Register your device and IoTize Studio on your AWS IoT Platform
In this step we create a device Things' Shadow in your AWS IoT Platform service that represents your physical device. Devices connected to AWS IoT are represented as Things in the AWS IoT registry.
-
On the Welcome to the AWS IoT Console page, in the navigation pane, choose Manage | Things.
-
Choose Register and Create a single thing.
Communication between the TapNLink and AWS IoT Core is protected through the use of X.509 certificates. AWS IoT Core can generate a certificate for you, or you can use your own X.509 certificate.
Register your device to enable it to connect to the IoT Platform:
- Choose Create certificate.
- On the Certificate created page, choose the Download links to download the certificate, private key, and root CA for AWS IoT Core. Save them on your computer as you will need them to configure TapNLink. Choose Done to return to AWS IoT main page.
-
X.509 certificates authenticate your device with AWS IoT Core. AWS IoT Core policies authorize devices to perform AWS IoT Core operations, such as subscribing to or publishing MQTT topics. TapNLink must present its certificate when sending messages to AWS IoT Core. To allow TapNLink to perform AWS IoT Core operations, you must create an AWS IoT Core Policy and attach it to your device certificate. To do so select Secure, Policies and Create button.
-
Select a name for your newly created Policy, Add two new statemants iot:* as Actions. Provide the ARN of your device and the ARN of the topic to which your device will publish. For reasons of simplicity in this tutorial we are using *. Choose Create to terminate.
- The policy we just created must now be attached to your TapNLink certificate. From the AWS IoT main page, select Secure then certificates. Select the certificate created for your TapNLink and Actions Attach Policy.
Repeat these steps to register IoTize Studio as a device. These new credentials will allow IoTize Studio to also connect to your AWS MQTT broker.
Step3: Configure TapNLink to handle AWS IoT Connectivity
The STM32 Blue Pill board that is included in the TapNLink Primer Evaluation Kit is pre-programmed with the STM32_Sensor application which demonstrates a few simple features like blinking the LED, measuring the internal temperature and voltage etc. In this guide, we will configure TapNLink to send some information to AWS IoT Platform.
Launch IoTize Studio and open the sensor_demo.iotz config file (in the Sensors_STM32_Demo subdirectory of the installed examples).
Select IoT Platform (MQTT) and setup the configuration:
- Set Enable Relay to Yes.This allows the tap to use MQTT to receive LWM2M commands
- Select AWS IoT in IoT Platform
- AWS information: Provide the information you previously genrated for your Tap and saved:
- Organization Custom Endpoint
- Thing Name
- Certificate
- Private Key
- AWS IoT root CA certificate
Step4: Setup the WiFi Settings and Configure TapNLink
Set Incoming communication (Wireless) | WiFi:
- Network mode to 'Network(Station)'
- SSID to your WiFi network
- WEP key to your WiFi network's security key,
Click on the "Configure" button to re-configure TapNLink, then use Test|Reboot Tap to restart TapNLink. Now TapNLink will dynamically connect to your AWS IoT Platform and update your registered device twin with the datalog information you set during this configuration.
Step5: Connect IoTize Studio to AWS IoT Hub
Here, we will use the credentials you created on Step2 to connect IoTize Studio. Go to Studio | Connection to Tap:
- Set Protocol to MQTT Relay
- Set Adapt broker information from Tap MQTT settings to Yes.
- Set Broker Certificate, Certificate and Private Key to the one you created for IoTize Studio on your AWS IoT Hub.
Click on Monitor. IoTize Studio will connect to the MQTT Broker, and communicate with the Tap. You are now able to communicate with your Tap through your AWS MQTT broker.
To go further
- To learn more about IoTize TapNLink products, refer to IoTize documentation center.