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

Aditi_B
Moderator
Moderator
Moderator
500 replies posted 5 questions asked 250 replies posted

Overview

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.
Notes:
  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.
Requirements

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

https://www.infineon.com/cms/en/product/promopages/connectedsensorkit/

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.

AditiB_81_0-1654680958609.png

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:

https://github.com/Infineon/mtb-example-sensors-pasco2-anycloud-mqtt-client

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

https://docs.aws.amazon.com/iot/latest/developerguide/iot-gs.html

After login, the AWS Management Console Board will appear as follows-

AditiB_81_1-1654681257615.png

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-

AditiB_81_2-1654681334995.png

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-

AditiB_81_3-1654681443384.png

Go to “Create things”

AditiB_81_4-1654681476473.png

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.

AditiB_81_5-1654681531805.png

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.

AditiB_81_6-1654681593893.png

Step-3 Attach Policies to Certificate

AditiB_81_7-1654681629485.png

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.

AditiB_81_8-1654681667507.png

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”.

AditiB_81_9-1654681694530.png

The page on the Step-3 automatically updates the newly created policy.

AditiB_81_10-1654681722220.png

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.

Note-

AditiB_81_11-1654681752245.png

You’ve now successfully created the thing. You’ll see logs as below-

AditiB_81_12-1654681780213.png

You’ll be able to see the thing name under the Things.

Operation

Follow the steps under the “Operation” section from the following link to do the required configurations in the code example and program-

https://github.com/Infineon/mtb-example-sensors-pasco2-anycloud-mqtt-client

Conclusion

The code example used in this KBA is from the following link-

https://github.com/Infineon/mtb-example-sensors-pasco2-anycloud-mqtt-client

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.

 

 

 

0 Likes
1314 Views
Authors