Flip&Click: Air Quality Example

This page will guide you through the various parts of the Flip&Click Air Quality Example.


The Air Quality demo is designed to offer the simplest means of adding a sensor to the existing Flip 'n Click framework.

It does, for the time being, have a hard coded expectation of finding a sensor in Slot D of the Flip 'n Click.

It reads from the analog pin and uses the Libraries of 'Davide Gironi' to calculate the Co2 detected in the air.

It takes those values, wraps them in a JSON payload, and publishes them to the Thingstream Portal.

The Publish Topic

The example uses a Predefined Topic for the publish.  The path for this topic is 'airquality/co2' and the alias is 200

A different alias may be assigned to the topic provided the alias used to create the Predefined Topic in the Arduino code is amended accordingly.

To create the topic

1) Signin to the Thingstream Portal

2) Select Topics from the left hand menu bar

3) A list of existing topics is displayed with a button to 'Create Topic', this should be clicked

4) The Topic value to be input is 'airquality/co2'

5) Click the checkbox entitled 'Add alias'

5) Click Create to be taken to a dialog that enables the assignment of an Alias

6) In the 'Add Alias' dialog, set an alias value of 200 in order to match the number used in the example code.

Handling the 'Flow' of data

There is a flow that is available from the MQTT Anywhere KIT category of the Flow Library entitled 'Air Quality Flow' which should be subscribed to the aforementioned topic.

Select Copy to domain & edit - this will copy the Flow from the Library to your domain and open it for editing.

This flow contains a Co2 threshold value ( co2_ppm_limit ) within the Function 'Evaluate CO2 reading'. 

The reading supplied by the device is compared to the specified threshold value and an alarm boolean is set true/false based on the outcome of this comparison. ( msg.co2_alarm )

The value of msg.co2_alarm is then evaluated and two possible outcomes are triggered.

In the event msg.co2_alarm is true, the first path is taken.  This path results in an email being sent to a specified individual, in this case, the domain Owner.  

The message is passed to a funtion that prepares the email content and sets the intended recipient. This is then sent by the email node entitled ' Email domain Owner'

Once you are comfortable with the flow content, it is ready to be 'Deployed'

Ensure any edits have been saved and then click the 'Deploy' button on the top right of the Flow Editor.

This will open a dialog which will enable you to select a 'Subscription'. Here we will subscribe to the newly created Topic 'airquality/co2'.

Click Edit on the 'Subscription' section and select the newly created Topic

If you select Done and then Deploy you will note the text confirming your Flow has been deployed and is subscribed appears above the editor. 'Subscribed to airquality/co2'.

The flow will now respond to messages received from the Qir Quality example running on the Flip & Click.

In the event msg.co2_alarm is false, the message payload is simply displayed in the debugger.

Triggering the alarm

There are two ways to trigger the alarm,

Frequency of Publish

The Example will attempt to publish every 2 minutes with a warning of an impending read of the sensor, 5 seconds prior to the read.

The flow of execution is controlled within the Thingstream_basic_publish_air_quality.ino sketch and are labelled.


* Set the loop wait time in milliseconds


static int loopWaitPeriod = 120000;


* Set the loop commencement warning time in milliseconds


static int loopStartingIn = 5000;

In this section

Getting Started

Still need help?

If you need more help or have any questions, please send an email to support@thingstream.io.