#include #include #include #include "bsec.h" #define ON_Board_LED 2 #define SEALEVELPRESSURE_HPA (1013.25) Bsec iaqSensor; String output; String send_Status_Read_BME680 = ""; float temperature; float humidity; float pressure; float IAQ; float CO2; float VOC; const char* IAQsts; const char* ssid = "xwarezhost"; const char* password = "xwarez"; String postData = ""; String payload = ""; void setup() { Serial.begin(115200); Wire.begin(); pinMode(ON_Board_LED,OUTPUT); digitalWrite(ON_Board_LED, HIGH); delay(2000); digitalWrite(ON_Board_LED, LOW); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(); Serial.println("-------------"); Serial.print("Connecting"); int connecting_process_timed_out = 20; //--> 20 = 20 seconds. connecting_process_timed_out = connecting_process_timed_out * 2; while (WiFi.status() != WL_CONNECTED) { Serial.print("."); digitalWrite(ON_Board_LED, HIGH); delay(250); digitalWrite(ON_Board_LED, LOW); delay(250); if(connecting_process_timed_out > 0) connecting_process_timed_out--; if(connecting_process_timed_out == 0) { delay(1000); ESP.restart(); } } digitalWrite(ON_Board_LED, LOW); Serial.println(); Serial.print("Successfully connected to : "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Serial.println("-------------"); iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire); bsec_virtual_sensor_t sensorList[10] = { BSEC_OUTPUT_RAW_TEMPERATURE, BSEC_OUTPUT_RAW_PRESSURE, BSEC_OUTPUT_RAW_HUMIDITY, BSEC_OUTPUT_RAW_GAS, BSEC_OUTPUT_IAQ, BSEC_OUTPUT_STATIC_IAQ, BSEC_OUTPUT_CO2_EQUIVALENT, BSEC_OUTPUT_BREATH_VOC_EQUIVALENT, BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE, BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY, }; iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP); } void loop() { unsigned long time_trigger = millis(); if (iaqSensor.run()) { output = String(time_trigger); output += ", " + String(iaqSensor.rawTemperature); output += ", " + String(iaqSensor.pressure); output += ", " + String(iaqSensor.rawHumidity); output += ", " + String(iaqSensor.gasResistance); output += ", " + String(iaqSensor.iaq); output += ", " + String(iaqSensor.iaqAccuracy); output += ", " + String(iaqSensor.temperature); output += ", " + String(iaqSensor.humidity); output += ", " + String(iaqSensor.staticIaq); output += ", " + String(iaqSensor.co2Equivalent); output += ", " + String(iaqSensor.breathVocEquivalent); Serial.println(output); } if(WiFi.status()== WL_CONNECTED) { HTTPClient http; int httpCode; get_BME680_sensor_data(); postData = "id=esp32_01"; postData += "&temperature=" + String(temperature); postData += "&humidity=" + String(humidity); postData += "&pressure=" + String(pressure); postData += "&IAQ=" + String(IAQ); postData += "&CO2=" + String(CO2); postData += "&VOC=" + String(VOC); postData += "&IAQsts=" + String(IAQsts); postData += "&status_read_sensor_bme680=" + send_Status_Read_BME680; payload = ""; digitalWrite(ON_Board_LED, HIGH); Serial.println(); Serial.println("---------------updateDHT11data_and_recordtable.php"); http.begin("http://172.20.10.3/ESP32_MySQL_Database/Final/updateDHT11data_and_recordtable.php"); http.addHeader("Content-Type", "application/x-www-form-urlencoded"); httpCode = http.POST(postData); payload = http.getString(); Serial.print("httpCode : "); Serial.println(httpCode); Serial.print("payload : "); Serial.println(payload); http.end(); Serial.println("---------------"); digitalWrite(ON_Board_LED, LOW); //........................................ delay(4000); } if ((iaqSensor.staticIaq > 0) && (iaqSensor.staticIaq <= 50)) { IAQsts = "Geras"; Serial.print("IAQ: Geras"); } if ((iaqSensor.staticIaq > 51) && (iaqSensor.staticIaq <= 100)) { IAQsts = "Vidutiniškas"; Serial.print("IAQ: Vidutiniškas"); } if ((iaqSensor.staticIaq > 101) && (iaqSensor.staticIaq <= 150)) { IAQsts = "Nesveika jautrioms asmenų grupėms"; Serial.print("IAQ: Nesveika jautrioms asmenų grupėms"); } if ((iaqSensor.staticIaq > 151) && (iaqSensor.staticIaq <= 200)) { IAQsts = "Nesveika"; Serial.print("IAQ: Nesveika"); } if ((iaqSensor.staticIaq > 201) && (iaqSensor.staticIaq <= 300)) { IAQsts = "Labai nesveika"; Serial.print("IAQ: Labai nesveika"); } if ((iaqSensor.staticIaq > 301) && (iaqSensor.staticIaq <= 500)) { IAQsts = "Pavojingas"; Serial.print("IAQ: Pavojingas"); } Serial.println(); delay(2000); } void get_BME680_sensor_data(){ Serial.println(); Serial.println("------get_BME680_sensor_data()"); temperature = iaqSensor.temperature; humidity = iaqSensor.humidity; pressure = iaqSensor.pressure / 100.0; IAQ = iaqSensor.staticIaq; CO2 = iaqSensor.co2Equivalent; VOC = iaqSensor.breathVocEquivalent; if ((iaqSensor.staticIaq > 0) && (iaqSensor.staticIaq <= 50)) { IAQsts = "Geras"; } if ((iaqSensor.staticIaq > 51) && (iaqSensor.staticIaq <= 100)) { IAQsts = "Vidutiniškas"; } if ((iaqSensor.staticIaq > 101) && (iaqSensor.staticIaq <= 150)) { IAQsts = "Nesveika jautrioms asmenų grupėms"; } if ((iaqSensor.staticIaq > 151) && (iaqSensor.staticIaq <= 200)) { IAQsts = "Nesveika"; } if ((iaqSensor.staticIaq > 201) && (iaqSensor.staticIaq <= 300)) { IAQsts = "Labai nesveika"; } if ((iaqSensor.staticIaq > 301) && (iaqSensor.staticIaq <= 500)) { IAQsts = "Pavojingas"; } if (isnan(temperature) || isnan(humidity)) { Serial.println("Failed to read from BME680 sensor!"); temperature = 0.00; humidity = 0; send_Status_Read_BME680 = "FAILED"; } else { send_Status_Read_BME680 = "SUCCCEED"; } Serial.printf("Temperature = %.2f ºC \n", temperature); Serial.printf("Humidity = %.2f % \n", humidity); Serial.printf("Pressure : %.2f hPa \n", pressure); Serial.printf("IAQ = %.2f PPM \n", IAQ); Serial.printf("CO2 eq = %.2f PPM \n", CO2); Serial.printf("Breath VOC = %.2f PPM \n", VOC); Serial.printf("Status Read BME680 Sensor : %s\n", send_Status_Read_BME680); Serial.printf("IAQ Status : \n", IAQsts); Serial.println("--------------------------"); }