Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Surilli
Published © GPL3+

Integration of Surilli WiFi with MQ135 Webserver

Air quality monitoring with MQ135 sensor and Surilli WiFi and displaying the value on the webserver.

BeginnerFull instructions provided15 minutes916
Integration of Surilli WiFi with MQ135 Webserver

Things used in this project

Hardware components

Surilli WiFi
Surilli WiFi
×1
MQ135 Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Surilli WiFi with MQ135 Sensor Webserver

Code

WiFi_Webserver_MQ135

C/C++
// Including the ESP8266 WiFi library

#include <ESP8266WiFi.h>

// Replace with your network details

const char* ssid = "YOUR_NETWORK_NAME";
const char* password = "YOUR_NETWORK_PASSWORD";

// Web Server on port 80

WiFiServer server(80);

int sensorValue;
int sensor_pin = A0;

void setup()
{
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(10);
  sensorValue = analogRead(sensor_pin);

  // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}

// runs over and over again

void loop()
{
  // Listening for new clients
  WiFiClient client = server.available();
  if (client)
  {
    Serial.println("New client");
    // Boolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();

               Serial.print(" AirQuality = ");
               Serial.print(sensorValue, DEC);
               Serial.println(" PPM");
        
           client.println("HTTP/1.1 200 OK");
           client.println("Content-Type: text/html");
           client.println("Connection: close");
           client.println();
           // your actual web page that displays Air Quality
           client.println("<!DOCTYPE HTML>");
           client.println("<html>");
           client.println("<head></head><body><h1>ESP8266 - Air Quality</h1><h3>Air Quality in PPM: ");
           client.println(sensorValue);
           client.println("</h3><h3>");
           client.println("</body></html>");     
           break;
        
        if (c == '\n')
        {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r')
        {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
}

Credits

Surilli
196 projects • 65 followers
Surilli is a premiere Internet of Things centric Technology Company aimed at providing cutting edge innovative solutions.
Contact

Comments

Please log in or sign up to comment.