Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

XENSIV™ PAS CO2 Anycloud MQTT Client using CSK

XENSIV™ PAS CO2 Anycloud MQTT Client using CSK

500 replies posted 5 questions asked 250 replies posted


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:

  • AWS IoT device SDK MQTT client library that includes an MQTT 3.1.1 client
  • sensor-xensiv-pasco2 library that is configured to detect the CO2 presence
Sequence of Operation
  1. A new CO2 value is read from the module.
  2. The pasco2_task notifies the publisher task with the new CO2 value.
  3. The publisher task publishes this new CO2 data to AWS on a topic defined (default is pasco2_status). You can verify this data from the AWS side.
  4. AWS sends the configuration as a JSON string to this client to configure the 'sensor-xensiv-pasco2' library. This allows the example to perform remote configuration.
  1. pasco2_task is suspended if the PAS CO2 wing board is not connected.
  2. Check the sensor-xensiv-pasco2 library documentation for information on configuration JSON objects.

Note: This code example version requires ModusToolbox software version 2.2 or later and is not backward compatible with v2.1 or older versions.

  • Board support package (BSP) minimum required version: 2.0.0
  • Programming language: C
  • Associated parts: All PSoC™ 6 MCU parts with SDIO, AIROC™ CYW43012 Wi-Fi & Bluetooth® combo chip, AIROC™ CYW4343W Wi-Fi & Bluetooth® combo chip
Supported toolchains (make variable 'TOOLCHAIN')
  • GNU Arm® embedded compiler v9.3.1 (GCC_ARM) - Default value of TOOLCHAIN
Supported kits (make variable 'TARGET')
  • PSoC™ 6 rapid IoT connect platform RP01 feather kit (CYSBSYSKIT-DEV-01) - Default value of TARGET


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.

Hardware Setup

This code example requires the XENSIV™ PAS CO2 wing board as part of the connected sensor kit.

  1. Connect the PAS CO2 wing board to the CYSBSYSKIT-DEV-01 kit with the pin headers.
  2. Connect the CYSBSYSKIT-DEV-01 kit to the PC with a USB cable.
  3. Place the CYSBSYSKIT-DEV-01 kit at a location in a room which is not very high.


Software Setup

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.

Using the Code Example

Create the project and open it using one of the following ways mentioned in the following link:


Setting Up the MQTT Broker

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-


Create Things

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.