Rishabh BangaPriyanka Jain
Published © CC BY-NC-ND

Air Quality System Using LinkIt ONE and MCS

Monitor the temperature, humidity, pressure, air quality, dust particle concentration online & even detect fire using LinkIt ONE & sensors.

AdvancedShowcase (no instructions)3,885
Air Quality System Using LinkIt ONE and MCS

Things used in this project

Hardware components

Grove Starter Kit for LinkIt ONE
Seeed Studio Grove Starter Kit for LinkIt ONE
Barometer Sensor, Dust Sensor, and Temperature and Humidity Sensor Pro. Air Quality Sensor I had lying around and is not a part of this kit.
×1

Software apps and online services

Arduino IDE
Arduino IDE
LinkIT ONE SDK for Arduino

Story

Read more

Schematics

Final Setup

Shows the final setup of sensors and WiFi Antenna

Final Setup

Shows complete setup of sensors and WiFi Antenna

Code

WiFi Connection

Arduino
Skeleton code for connecting to WiFi. Replace WiFi SSD & Key, Device ID & Key with your own.
#include <LTask.h>
#include <LWifi.h>
#include <LWiFiClient.h>
#include <HttpClient.h>
#include <LDateTime.h>

#define WIFI_AP "" //WiFi SSID
#define WIFI_PASSWORD "" //WiFi Key
#define WIFI_AUTH LWIFI_WPA2 //Authentication Mode
#define per 50
#define per1 3
#define DEVICEID "" // Device ID given by cloud sandbox
#define DEVICEKEY "" //Device key given by cloud sandbox
#define SITE_URL "api.mediatek.com" //the site of the API


LWiFiClient c; //wifi client
LWiFiClient c2;
HttpClient http(c2); //http client
unsigned int rtc; //real-time clock
unsigned int lrtc;
unsigned int rtc1;
unsigned int lrtc1;
char port[4]="   ";
char connection_info[21]="                    ";
char ip[21]="              ";             
int portnum;
int val = 0;
String tcpdata = String(DEVICEID) + "," + String(DEVICEKEY) + ",0";

String TCPCMD_LED_ON = "LED_controller,1"; //tcp command to controll LED ON/OFF
String TCPCMD_LED_OFF = "LED_controller,0";

void setup() {
  //initialize
  Serial.begin(115200);
  LTask.begin();
  LWiFi.begin();
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
    delay(1000);
  Serial.println("WiFi succeed");
  
  Serial.println("calling connection");
  while (!c2.connect(SITE_URL, 80))
    delay(1000);
  Serial.println("Connection to site succeed");
  
  getconnectInfo();
  Serial.println("getConnectionInfo succeed"); 
  
  connectTCP();
  Serial.println("connectTCP() succeed");
  
}

Grove Kit - Barometer and RGB LCD

Arduino
Code for connecting and pushing sensor data to cloud. Since the process is more or less the same for each sensor, I'd be explaining only two in this instance.
#include <Wire.h> //include wire library to enable Grove
#include <Barometer.h> //include library of Barometer sensor
#include <rgb_lcd.h>

Barometer myBarometer;


float humidity;
float temperature;
float pressure;
float atm;
float altitude;

Int colorR = 255;
Int colorG = 255;
Int colorB = 0;

void setup()
{
  myBarometer.init();
  pinMode(13, OUTPUT);
  lcd.begin(16, 2);
  lcd.setRGB(colorR, color G, colorB)
}

void loop() 
{
  
 
  int val = analogRead(pinTemp);
  float r = (float) (1023-val)*10000/val;
  humidity = 1/ (log(r/10000)/b+1/298.15);
  pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP());
  altitude = myBarometer.calcAltitude(pressure);  //calculate the ideal altitude
  //  atm = pressure / 101325;
  //print some information on serial monitor
  temperature = myBarometer.bmp085GetTemperature(myBarometer.bmp085ReadUT());
  
  if (temperature < 25)
  {
    colorR=0;
    colorG=0;
    colorB=255;
    lcd.setRGB(colorR, colorG, colorB);
    lcd.print("It's cool at: ");
    lcd.print(temperature);
  }
  
  else
  {
    colorR=255;
    colorG=0;
    colorB=0;
    lcd.setRGB(colorR, colorG, colorB);
    lcd.print("It's hot at: ");
    lcd.print(temperature);
  }
}

void uploadstatus(){
  //Uploading datapoint to MCS(Meditek Cloud Sandbox)
  Serial.println("calling connection");
  LWiFiClient c2;  
 
  char bufferH[5];
  char bufferT[5];
  char bufferA[7];
  char bufferP[7];
  
  sprintf(bufferH, "%.2f", humidity);
  sprintf(bufferT, "%.2f", temperature);
  sprintf(bufferA, "%.2f", altitude);
  sprintf(bufferP, "%.0f", pressure);
  
  String uploadHumidity = "humidity_display,," + String(bufferH);
  String uploadTemperature = "temperature_display,," + String(bufferT);
  String uploadAltitude = "altitude_display,," + String(bufferA);
  String uploadPressure = "pressure_display,," + String(bufferP);
  
  
  while (!c2.connect(SITE_URL, 80))
  {
    Serial.println("Re-Connecting to WebSite");
    delay(1000);
  }
  delay(100);
  if(digitalRead(13)==1)
    uploadLED = "LED_display,,1";
  else
    uploadLED = "LED_display,,0";
  
  String uploadData = uploadHumidity + "\n" +
                      uploadTemperature + "\n" + 
                      uploadAltitude + "\n" +
                      uploadPressure;
  
  HttpClient http(c2);
  c2.print("POST /mcs/v2/devices/");
  c2.print(DEVICEID);
  c2.println("/datapoints.csv HTTP/1.1");
  c2.print("Host: ");
  c2.println(SITE_URL);
  c2.print("deviceKey: ");
  c2.println(DEVICEKEY);
  c2.println("Content-Type: text/csv");
  c2.println("Connection: close");
  c2.println();
  c2.println(uploadData);
  //upload the data
  
  delay(500);

  int errorcount = 0;
  while (!c2.available())
  {
    Serial.print("waiting HTTP response: ");
    Serial.println(errorcount);
    errorcount += 1;
    if (errorcount > 10) 
    {
      c2.stop();
      Serial.println("uploadStatus failed");
      return;
    }
    delay(100);
  }

Credits

Rishabh Banga

Rishabh Banga

12 projects • 135 followers
Intel Software Innovator | Microsoft Certified Professional | IoT Evangelist
Priyanka Jain

Priyanka Jain

2 projects • 6 followers

Comments