#ifdef ESP8266 #include #include ESP8266WebServer server(80); #else #include #include WebServer server(80); #endif #include // candle for Adafruit NeoPixel // 1 pixel version // by Tim Bartlett, December 2013 // current settings for 5v Trinket #include #define PIN 33 // color variables: mix RGB (0-255) for desired yellow int redPx = 255; int grnHigh = 110; //110-120 for 5v, 135 for 3.3v int bluePx = 10; //10 for 5v, 15 for 3.3v // animation time variables, with recommendations int burnDepth = 10; //10 for 5v, 14 for 3.3v -- how much green dips below grnHigh for normal burn - int flutterDepth = 25; //25 for 5v, 30 for 3.3v -- maximum dip for flutter int cycleTime = 120; //120 -- duration of one dip in milliseconds // pay no attention to that man behind the curtain int fDelay; int fRep; int flickerDepth; int burnDelay; int burnLow; int flickDelay; int flickLow; int flutDelay; int flutLow; Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_GRB + NEO_KHZ800); /*************************************************************************** This is a library for the BME680 gas, humidity, temperature & pressure sensor Designed specifically to work with the Adafruit BME680 Breakout ----> http://www.adafruit.com/products/3660 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ #include #include #include #include "Adafruit_BME680.h" #define BME_SCK 13 #define BME_MISO 12 #define BME_MOSI 11 #define BME_CS 10 #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME680 bme; // I2C //Adafruit_BME680 bme(BME_CS); // hardware SPI //Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); int count; // global counter for diagnostics //Enter your Wi-Fi SSID and PASSWORD const char* ssid = "ssid_name"; const char* password = "wifi_password"; // This function returns an HTML formated page in the correct type for display // It uses the Raw string macro 'R' to place commands in PROGMEM const char Web_page[] PROGMEM = R"=====(

AURA CANDLE


Temperature: 0°

Humidity: 0%

VOC: 0

Pressure: 0hPa


)====="; //=================================================================== // This routine is executed when you open a browser at the IP address //=================================================================== void handleRoot() { //String s = Web_page; //Display HTML contents server.send(200, "text/html", Web_page); //Send web page } void handleTEMP() { // This function is called by the script to update the sensor value float temp; temp = bme.temperature; server.send(200, "text/plain", String((float)temp,2)); //server.send(200, "text/plain", String((float)temp)); //Send sensor reading when there's a client ajax request } void handleHUMI() { // This function is called by the script to update the sensor value float humi; humi = bme.humidity; server.send(200, "text/plain", String((float)humi,2)); //Send sensor reading when there's a client ajax request } void handleVOC() { // This function is called by the script to update the sensor value float voc; voc = bme.gas_resistance / 1000.0; server.send(200, "text/plain", String((float)voc,0)); //Send sensor reading when there's a client ajax request } void handlePRES() { // This function is called by the script to update the sensor value float pres; pres = bme.pressure / 100.0; server.send(200, "text/plain", String((float)pres,0)); //Send sensor reading when there's a client ajax request } void setup(void) { Serial.begin(115200); WiFi.mode(WIFI_STA); // Connect to your wifi WiFi.begin(ssid, password); // Start the Wi-Fi services Serial.println("Connecting to : "+String(ssid)); while (WiFi.waitForConnectResult() != WL_CONNECTED) {Serial.print(".");} // Wait for WiFi to connect Serial.println(" Connected to : "+String(ssid)); Serial.print("Use IP address: "); Serial.println(WiFi.localIP()); //IP address assigned to your ESP //---------------------------------------------------------------- server.on("/", handleRoot); // This displays the main webpage, it is called when you open a client connection on the IP address using a browser server.on("/TEMPread", handleTEMP); // To update Temperature called by the function getSensorData server.on("/HUMIread", handleHUMI); // To update Humidity called by the function getSensorData server.on("/VOCread", handleVOC); // To update VOC called by the function getSensorData server.on("/PRESread", handlePRES); // To update Pressure called by the function getSensorData //---------------------------------------------------------------- server.begin(); // Start the webserver //NEOPIXEL flickerDepth = (burnDepth + flutterDepth) / 2.4; burnLow = grnHigh - burnDepth; burnDelay = (cycleTime / 2) / burnDepth; flickLow = grnHigh - flickerDepth; flickDelay = (cycleTime / 2) / flickerDepth; flutLow = grnHigh - flutterDepth; flutDelay = ((cycleTime / 2) / flutterDepth); strip.begin(); strip.show(); delay(3000); //BOSCH SENSOR // Serial.begin(9600); while (!Serial); Serial.println(F("BME680 test")); if (!bme.begin()) { Serial.println("Could not find a valid BME680 sensor, check wiring!"); while (1); } // Set up oversampling and filter initialization bme.setTemperatureOversampling(BME680_OS_8X); bme.setHumidityOversampling(BME680_OS_2X); bme.setPressureOversampling(BME680_OS_4X); bme.setIIRFilterSize(BME680_FILTER_SIZE_3); bme.setGasHeater(320, 150); // 320*C for 150 ms } void loop(void) { //SERVER server.handleClient(); // Keep checking for a client connection if (millis() % 5000 == 0) { count++; Serial.println(count);} // Display a serial diagnostic print to check its running delay(1); //BOSCH SENSOR if (! bme.performReading()) { Serial.println("Failed to perform reading :("); return; } // Serial.print("Temperature = "); // Serial.print(bme.temperature); // Serial.println(" *C"); // // Serial.print("Pressure = "); // Serial.print(bme.pressure / 100.0); // Serial.println(" hPa"); // // Serial.print("Humidity = "); // Serial.print(bme.humidity); // Serial.println(" %"); // // Serial.print("Gas = "); // Serial.print(bme.gas_resistance / 1000.0); // Serial.println(" KOhms"); // // Serial.print("Approx. Altitude = "); // Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); // Serial.println(" m"); // // Serial.println(); //delay(2000); //IF if (bme.gas_resistance / 1000.0 > 400) { Serial.println("flicker"); flicker(10); } else if (bme.gas_resistance / 1000.0 < 400) { Serial.println("flut"); flutter(10); } // Serial.println("delay"); // delay(100); } // basic fire funciton - not called in main loop void fire(int grnLow) { for (int grnPx = grnHigh; grnPx > grnLow; grnPx--) { strip.setPixelColor(0, redPx, grnPx, bluePx); strip.setPixelColor(1, redPx, grnPx, bluePx); strip.setPixelColor(2, redPx, grnPx, bluePx); strip.setPixelColor(3, redPx, grnPx, bluePx); strip.setPixelColor(4, redPx, grnPx, bluePx); strip.setPixelColor(5, redPx, grnPx, bluePx); strip.show(); delay(fDelay); } for (int grnPx = grnLow; grnPx < grnHigh; grnPx++) { strip.setPixelColor(0, redPx, grnPx, bluePx); strip.setPixelColor(1, redPx, grnPx, bluePx); strip.setPixelColor(2, redPx, grnPx, bluePx); strip.setPixelColor(3, redPx, grnPx, bluePx); strip.setPixelColor(4, redPx, grnPx, bluePx); strip.setPixelColor(5, redPx, grnPx, bluePx); strip.show(); delay(fDelay); } } // fire animation void on(int f) { fRep = f * 1000; int grnPx = grnHigh - 5; strip.setPixelColor(0, redPx, grnPx, bluePx); strip.setPixelColor(1, redPx, grnPx, bluePx); strip.setPixelColor(2, redPx, grnPx, bluePx); strip.setPixelColor(3, redPx, grnPx, bluePx); strip.setPixelColor(4, redPx, grnPx, bluePx); strip.setPixelColor(5, redPx, grnPx, bluePx); strip.show(); delay(fRep); } void burn(int f) { fRep = f * 8; fDelay = burnDelay; for (int var = 0; var < fRep; var++) { fire(burnLow); } } void flicker(int f) { fRep = f * 8; // fDelay = burnDelay; // fire(burnLow); fDelay = flickDelay; for (int var = 0; var < fRep; var++) { fire(flickLow); } // fDelay = burnDelay; // fire(burnLow); // fire(burnLow); // fire(burnLow); //Serial.println("Fire done"); } void flutter(int f) { fRep = f * 8; // fDelay = burnDelay; // fire(burnLow); // fDelay = flickDelay; // fire(flickLow); fDelay = flutDelay; for (int var = 0; var < fRep; var++) { fire(flutLow); } // fDelay = flickDelay; // fire(flickLow); // fire(flickLow); // fDelay = burnDelay; // fire(burnLow); // fire(burnLow); //Serial.println("Fire done"); }