/* * Monitor vzduchu se 6 parametry * Ridici elektronika ESP32LP-kit * Cidla: SEN55 (pevne castice, teplota, vlhkost, NOX a VOC index * Odeslani data na TMEP.cz * * chiptron.cz (c) 2022 * #MartyNaHrad martynahrad.cz */ #include #include #include #include "SparkFun_SCD4x_Arduino_Library.h" // library http://librarymanager/All#SparkFun_SCD4x #include // library https://github.com/Sensirion/embedded-i2c-sen5x /*--------------------- UPRAV NASTAVENI ---------------------*/ const char* ssid = "PASSWORD"; const char* password = "SSID"; // vypln tvou domenu cidla, kterou sis zaregistroval na tmep.cz PRO PRASNOST (cidlo SEN55) String serverNamePM = "http://serverNamePM.tmep.cz/index.php?"; // vypln tve GUID cidla pro prasnost String GUID_PM = "GUID_PM"; // vypln tvou domenu cidla, kterou sis zaregistroval na tmep.cz PRO CO2 (pokud mas, cidlo SCD41) String serverNameCO2 = "http://serverNameCO2.tmep.cz/index.php?"; // vypln tve GUID cidla pro SCD41 - CO2, teplota, tlak String GUID_CO2 = "GUID_CO2"; // vypln tvou domenu cidla, kterou sis zaregistroval na tmep.cz PRO NOX index (SEN55) String serverNameNOX = "http://serverNameNOX.tmep.cz/index.php?"; // vypln tve GUID cidla pro NOX indes String GUID_NOX = "GUID_NOX"; // vypln tvou domenu cidla, kterou sis zaregistroval na tmep.cz PRO VOC index (SEN55) String serverNameVOC = "http://serverNameVOC.tmep.cz/index.php?"; // vypln tve GUID cidla pro VOC index String GUID_VOC = "GUID_VOC"; SCD4x SCD41; int scd41_co2 = 0; double scd41_temp = 0; double scd41_hum = 0; SensirionI2CSen5x sen5x; float sen55_pm1p0 = 0; float sen55_pm2p5 = 0; float sen55_pm4p0 = 0; float sen55_pm10p0 = 0; float sen55_temp = 0; float sen55_hum = 0; float sen55_voc = 0; float sen55_nox = 0; void setup() { Serial.begin(115200); Wire.begin(); /*---------- SCD41 ------------*/ if (SCD41.begin(true, true) == false) //measBegin______/ | //autoCalibrate _______/ { Serial.println("Chyba SCD41, SCD41.begin."); esp_sleep_enable_timer_wakeup(300 * 1000000); // uspani na 5 minut Serial.flush(); delay(100); esp_deep_sleep_start(); } /*--------- SEN55 ---------------*/ sen5x.begin(Wire); /*uint16_t error = sen5x.deviceReset(); if (error) { Serial.print("Chyba SEN55, deviceReset."); //DEEP SLEEP }*/ /*------------- Wi-Fi -----------*/ WiFi.begin(ssid, password); Serial.println("Pripojovani"); int count = 0; while(WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); if(count > 20) // pokud se po 20s nedokaze pripojit na WiFi, uspi se { esp_sleep_enable_timer_wakeup(300 * 1000000); // uspani na 5 minut Serial.flush(); delay(100); esp_deep_sleep_start(); } count++; } Serial.println(); Serial.print("Pripojeno do site, IP adresa zarizeni: "); Serial.println(WiFi.localIP()); } void loop() { /*------- SCD 41 - TEPLOTA, VLHKOST, CO2 -------*/ // Cekej na nova data while (!SCD41.readMeasurement()) { delay(100); } Serial.print("CO2(ppm):"); Serial.print(SCD41.getCO2()); scd41_co2 = SCD41.getCO2(); Serial.print("\tTemperature(C):"); Serial.print(SCD41.getTemperature(), 1); scd41_temp = SCD41.getTemperature(); Serial.print("\tHumidity(%RH):"); Serial.print(SCD41.getHumidity(), 1); scd41_hum = SCD41.getHumidity(); Serial.println(); /*------- SEN55 - PM1, 2.5, 4, 10, TEPLOTA, VLHKOST, NOX INDEX A VOC INDEX -------*/ float tempOffset = 0.0; uint16_t error = sen5x.setTemperatureOffsetSimple(tempOffset); error = sen5x.startMeasurement(); if (error) { Serial.print("Chyba SEN55, StartMeasurement."); } error = sen5x.readMeasuredValues( sen55_pm1p0, sen55_pm2p5, sen55_pm4p0, sen55_pm10p0, sen55_hum, sen55_temp, sen55_voc, sen55_nox); if (error) { Serial.print("Chyba SEN55, ReadMeasuredValues."); } else { Serial.print("MassConcentrationPm1p0:"); Serial.print(sen55_pm1p0); Serial.print("\t"); Serial.print("MassConcentrationPm2p5:"); Serial.print(sen55_pm2p5); Serial.print("\t"); Serial.print("MassConcentrationPm4p0:"); Serial.print(sen55_pm4p0); Serial.print("\t"); Serial.print("MassConcentrationPm10p0:"); Serial.print(sen55_pm10p0); Serial.print("\t"); Serial.print("AmbientTemperature:"); Serial.print(sen55_temp); Serial.print("\t"); Serial.print("AmbientHumidity:"); Serial.print(sen55_hum); Serial.print("\t"); Serial.print("VocIndex:"); Serial.print(sen55_voc); Serial.print("\t"); Serial.print("NoxIndex:"); Serial.println(sen55_nox); } /*------------ Odeslani hodnot na TMEP.cz ------------------*/ if(WiFi.status()== WL_CONNECTED) { //GUID, nasleduje hodnota teploty, pro vlhkost "humV", pro CO2 "CO2" cidla SCD41 // CO2 z SCD41 // Teplota a vlhkost ze SEN55 String serverPathCO2 = serverNameCO2 + "" + GUID_CO2 + "=" + sen55_temp + "&humV=" + sen55_hum + "&CO2=" + scd41_co2; sendhttpGet(serverPathCO2); delay(100); //GUID, nasleduje hodnota cidla prasnosti PM1006 a odeslani na druhou domenu String serverPathPM = serverNamePM + "" + GUID_PM + "=" + sen55_pm10p0; sendhttpGet(serverPathPM); delay(100); //GUID, nasleduje hodnota cidla prasnosti PM1006 a odeslani na druhou domenu String serverPathVOC = serverNameVOC + "" + GUID_VOC + "=" + sen55_voc; sendhttpGet(serverPathVOC); delay(100); //GUID, nasleduje hodnota cidla prasnosti PM1006 a odeslani na druhou domenu String serverPathNOX = serverNameNOX + "" + GUID_NOX + "=" + sen55_nox; sendhttpGet(serverPathNOX); } else { Serial.println("Wi-Fi odpojeno"); } esp_sleep_enable_timer_wakeup(300 * 1000000); // uspani na 5 minut Serial.flush(); delay(100); esp_deep_sleep_start(); } // funcke pro odeslani dat na TMEP.cz void sendhttpGet(String httpGet) { HTTPClient http; // odeslani dat String serverPath = httpGet; // zacatek http spojeni http.begin(serverPath.c_str()); // http get request int httpResponseCode = http.GET(); if (httpResponseCode>0) { Serial.print("HTTP odpoved: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); } else { Serial.print("Error kod: "); Serial.println(httpResponseCode); } // Free resources http.end(); }