This code example demonstrates implementing an MQTT client on the CSK kit using the MQTT client library for XENSIV™ sensor. The MQTT client establishes the connection with the AWS broker and publishes CO2 level (in ppm) onto the cloud. The library uses the following:
Note: This code example version requires ModusToolbox software version 2.2 or later and is not backward compatible with v2.1 or older versions.
Note: This example requires a PSoC™ 6 MCU device with at least 2 MB flash and 1 MB SRAM, and therefore does not support other PSoC™ 6 MCU kits.
This code example requires the XENSIV™ PAS CO2 wing board as part of the connected sensor kit.
Install a terminal emulator if you don't have one. Instructions in this document use Tera Term.
This example requires no additional software or tools.
Create the project and open it using one of the following ways mentioned in the following link:
Sign in to the AWS console via this link - https://aws.amazon.com/console/
Sign in if an account is already created, else sign up for account creation. The following link provides more insights on getting started with AWS
After login, the AWS Management Console Board will appear as follows-
Search for the service “IoT Core” where you’ll get option to create, manage and test things.
Once you’ve visited this service page, it’ll come under “Recently visited services”.
The “IoT Core” page will appear as follows-
Go to Manage->Things to create a new thing.
An IoT thing is a representation and record of your physical device in the cloud. A physical device needs a thing record in order to work with AWS IoT.
The “Things” page will appear as follows-
Go to “Create things”
You can either create a single thing or multiple things for multiple devices.
Step-1 Specify Thing Properties
Provide the “Thing name” for your device. You can also add other features in the thing resource such as additional configurations provided in this page or adding a Device Shadow for the same.
Step-2 Configure Device Certificate
You can either auto generate a new certificate using AWS IoT’s certificate authority/can use your own certificates/upload certificate signing request/can skip creating certificates at this step.
In this example, we’re auto generating certificates using AWS.
Note - Your device won't be able to connect to AWS IoT until it has an active certificate with an appropriate policy.
You can skip creating certificates at this step but it’s required by your device for establishing connection with AWS.
Step-3 Attach Policies to Certificate
Policies are required to grant/deny access to the AWS IoT resources. A policy is required to be attached to the device certificate created in the previous step.
To do this, click on “Create policy”.
You will be redirected to the AWS Create Policy page.
Provide a “Policy name”. Under the “Policy document”, select “Allow” under the “Policy effect” and “*” under “Policy action” and “Policy Resource”. The “*” signifies that the device is allowed to do any operations such as connect, disconnect, publish, subscribe etc.
Click on “Create”. The policy is now listed under “AWS IoT Policies”.
The page on the Step-3 automatically updates the newly created policy.
Click on “Create thing”.
A pop will appear showcasing the rootCA, private/public keys and the client certificates. As these certificates and keys are required in the code example, download all the required components.
You’ve now successfully created the thing. You’ll see logs as below-
You’ll be able to see the thing name under the Things.
Follow the steps under the “Operation” section from the following link to do the required configurations in the code example and program-
The code example used in this KBA is from the following link-
The MQTT broker used here is AWS which can be set by following the steps above. The publish topic used is pasco2_status to send the CO2 level (in ppm) to the cloud. The CSK kit is subscribed to the topic pasco2_config which can be used to configure the device remotely via the AWS cloud.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By technically required cookies we mean cookies without those the technical provision of the online service cannot be ensured. These include e.g. cookies supporting essential services like a smooth reproduction of video or audio footage. So called ?functional cookies? are also assigned belonging to this category. Functional cookies store information in order to provide you comfortable use of our online services (e.g. language selection). The legal basis for the processing of personal data by means of cookies of this category is Infineon?s legitimate interest. This includes, among other things, the interest in having a professional external presentation as well as an optimal balancing of the loads on the server due to technical reasons.
By performance and marketing cookies we mean cookies which are technically not required. We use performance and marketing cookies only if you have given us your prior consent. With such cookies, we collect information about how users interact with our website and which pages have been visited. This helps us to understand user activity on our website on an aggregated as well as on a personal level to provide you relevant content and services.