How to connect your device to AWS IoT Platform using TapNLink NFC-WIFI Primer
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.
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 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.
Choose Create 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 our TapNLink certificate. From the AWS IoT main page, select Secure then certificates. Select the certificate created for your TapNLink and Actions Attach Policy.
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).
The Data sent to AWS IoT Platform is the datalog variables' values. To include a Variable in the datalog, select its Bundle container and set the Datalog Period. To remove a Bundle from the datalog list set its Datalog Period to 0.
We are going to add a third bundle to the list of selected bundles for Cloud connectivity to enable interaction with the device from AWS IoT Platform.
Select the Count_Control bundle and change DataLog Period to 61 seconds. tech profile can change this bundles' variables, so if we associate this profile to AWS IoT Platform we can change these variables directly from AWS IoT Platform. Refer to Security and access control to learn more about profiles and users.
Now we have to set the IoT Platform settings and the configuration: - Select AWS IoT Platform - Provide the previously created Thing information, to let TapNLink connect to your AWS IoT Platform. - Setup the frequency (in seconds) of the Twin Status Update sent to the platform.
We are going to use the tech profile which can modify sensor demo values. You could select a specific Cloud Profile to control the access privileges of the connected 'IoT Platform'.
Provide the required information to let TapNLink connect and publish to AWS IoT Platform.
- Organization custom endpoint
- Thing Name Provide the path of the certificates we previously generated and saved:
- Private Key
- AWS IoT root certificate
Step4: Setup the WiFi Settings and Configure TapNLink
Make sure that TapNLink is configured to 'Store variable information' and that Wireless Communication is set to 'Network(Station)' to let TapNLink connect to the Internet.
Click on the "Configure" button to re-configure TapNLink, then use Test|Reboot Tap to retart 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: View MQTT messages with the AWS IoT MQTT client
TapNLink is now configured and running. Every 60 seconds, it sends the values of the selected variables to update the device shadow sensor_demo. You can watch the MQTT messages received by AWS IoT in the AWS IoT MQTT client's console.
TapNLink publishes MQTT messages on topics to communicate their state to AWS IoT, and AWS IoT publishes MQTT messages to inform the devices and apps of changes and events.
You can use the MQTT client to subscribe to these topics and watch these messages as they occur. You can also use the MQTT client to publish MQTT messages to other devices and services in your AWS account.
Select Test and Subscribe to $aws/things/sensor_demo/shadow/update topic.
- As TapNLink is continuously sending an update message to the platform, you will see the message payload.
- You can also check the shadow status of your device under Manage, Things, sensor_demo then Shadows .
The shadow feature is an easy way to interact with your device and update the state of the device. Use the Edit button to change the Json document of the Thing Shadow as following, then save:
Et Voilà! TapNLink reports that the value has been successfully changed! You have a fully functional Shadow for the sensor demo target app.
Refer to AWS IoT Platform documentation to learn amore about AWS Iot Platform features and services.
To go further
- To learn more about IoTize TapNLink products, refer to IoTize documentation center.