diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea96d6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +#hide credentials from git +secrets.h + diff --git a/esp8266-sensor.ino b/esp8266-sensor.ino index 2f70af7..5f99380 100644 --- a/esp8266-sensor.ino +++ b/esp8266-sensor.ino @@ -2,12 +2,13 @@ #define SERIAL_DEBUG //#define OLED_OUTPUT //#define BATTERY_USE -//#define BME2_USE +#define BME2_USE //#define BME6_USE -//#define BH_USE -#define SHT_USE +#define BH_USE +//#define SHT_USE //#define VEML_USE //#define CCS_USE +#define SGP30_USE const bool metric = true; /************************* generic libs *********************************/ #include @@ -79,13 +80,12 @@ const bool metric = true; /************************* WiFi Client *********************************/ -#define WLAN_SSID "IoT" -#define WLAN_PASS "TF0xJJHtMz5kJUdh3dqf" +//see secrets.h const int WIFI_CONNECT_TIMEOUT = 10; // seconds - max time for wifi connect to router, if exceeded go to sleep //ToDo Legacy IPv4 -IPAddress ip(10, 0, 4, 7); +IPAddress ip(10, 0, 4, 14); IPAddress gateway(10, 0, 4, 1); IPAddress subnet(255, 255, 255, 240); IPAddress dns(10, 0, 4, 1); @@ -94,45 +94,42 @@ IPAddress mqttBroker(10, 0, 4, 1); //failsafe const int FW_VERSION = 10; const char* fwUrlBase = "http://10.0.4.2/fota/"; /************************* MQTT Broker Setup *********************************/ -#define name "bathroom" -const int MQTT_PORT = 1883; -const char MQTT_SERVER[] = "mqtt.koelner.dynvpn.de"; +#define name "test" +//see secrets.h char MQTT_CLIENTID[10]; -const char MQTT_USERNAME[] = "input"; -const char MQTT_PASSWORD[] = "tFnlKJu9"; -const char MQTT_WILL_TOPIC[] = "bathroom/sys/will"; +const char MQTT_WILL_TOPIC[] = "test/sys/will"; const int MQTT_WILL_QOS = 0; const int MQTT_WILL_RETAIN = 0; const char MQTT_WILL_MESSAGE[] = "Finally died..."; /****************************** Feeds ***************************************/ //ToDo: generate feed from CLIENTID and determine the ClientID from the ChipID #if defined(BME2_USE) || defined(BME6_USE) -const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature"; -const char PRESSURE_FEED[] = "bathroom/sensors/pressure"; -const char HUMIDITY_FEED[] = "bathroom/sensors/humidity"; -const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity"; +const char TEMPERATURE_FEED[] = "test/sensors/temperature"; +const char PRESSURE_FEED[] = "test/sensors/pressure"; +const char HUMIDITY_FEED[] = "test/sensors/humidity"; +const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity"; #endif #if defined(SHT_USE) -const char TEMPERATURE_FEED[] = "bathroom/sensors/temperature"; -const char HUMIDITY_FEED[] = "bathroom/sensors/humidity"; -const char ABSHUMIDITY_FEED[] = "bathroom/sensors/abshumidity"; +const char TEMPERATURE_FEED[] = "test/sensors/temperature"; +const char HUMIDITY_FEED[] = "test/sensors/humidity"; +const char ABSHUMIDITY_FEED[] = "test/sensors/abshumidity"; #endif #ifdef BME6_USE -const char IAQ_FEED[] = "bathroom/sensors/iaq"; -const char IAQPREC_FEED[] = "bathroom/sensors/iaqprec"; +const char IAQ_FEED[] = "test/sensors/iaq"; +const char IAQPREC_FEED[] = "test/sensors/iaqprec"; #endif #ifdef VEML_USE -const char UVA_FEED[] = "bathroom/sensors/uva"; -const char UVB_FEED[] = "bathroom/sensors/uvb"; -const char UVINDEX_FEED[] = "bathroom/sensors/uvindex"; +const char UVA_FEED[] = "test/sensors/uva"; +const char UVB_FEED[] = "test/sensors/uvb"; +const char UVINDEX_FEED[] = "test/sensors/uvindex"; #endif #ifdef BH_USE -const char LIGHT_FEED[] = "bathroom/sensors/light"; +const char LIGHT_FEED[] = "test/sensors/light"; #endif -#ifdef CCS_USE -const char ECO2_FEED[] = "bathroom/sensors/eco2"; -const char TVOC_FEED[] = "bathroom/sensors/tvoc"; +#if defined (CCS_USE) || defined(SGP30_USE) +const char ECO2_FEED[] = "test/sensors/eco2"; +const char TVOC_FEED[] = "test/sensors/tvoc"; #endif #ifdef BATTERY_USE -const char BATTERY_FEED[] = "bathroom/sys/battery"; +const char BATTERY_FEED[] = "test/sys/battery"; #endif diff --git a/main.ino b/main.ino index 5d83270..d0e90ce 100644 --- a/main.ino +++ b/main.ino @@ -6,10 +6,13 @@ struct { uint8_t channel; // 1 byte, 5 in total uint8_t bssid[6]; // 6 bytes, 11 in total uint8_t txPow = 0; // 1 byte, 12 in total - IPAddress mqttServer=mqttBroker; //save the dns lookup + IPAddress mqttServer = mqttBroker; //save the dns lookup #ifdef CCS_USE bool ccsInit = false; #endif +#ifdef SGP30_USE + bool sgpInit = false; +#endif } rtcData; /************************* RTC Mem *********************************/ #define WiFi_RTC 0 @@ -102,6 +105,10 @@ CCS811 ccs; #define CCSRESET D6 //GPIO12 #endif +#ifdef SGP30_USE +#include "SparkFun_SGP30_Arduino_Library.h" +SGP30 sgp; +#endif void messageReceived(String &topic, String &payload) { #ifdef SERIAL_DEBUG @@ -217,7 +224,7 @@ char uva[8]; char uvb[8]; char uvindex[5]; #endif -#ifdef CCS_USE +#if defined(CCS_USE) || defined(SGP30_USE) float eco2(NAN); String eco2_str; char eco2C[8]; @@ -239,6 +246,7 @@ bool veml6075Check = false; bool bh1750Check = false; bool ccs811Check = false; bool sht30Check = false; +bool sgp30Check = false; WiFiClient mqttSocket; MQTTClient mqttClient; @@ -378,10 +386,10 @@ void initSensors() { } #endif -/*********************BME280 I2C init **************************************/ + /*********************BME280 I2C init **************************************/ #ifdef BME2_USE #ifdef SERIAL_DEBUG -Serial.print(F("\tBME280 init...\t")); + Serial.print(F("\tBME280 init...\t")); #endif #ifdef OLED_OUTPUT @@ -417,10 +425,10 @@ Serial.print(F("\tBME280 init...\t")); #endif } #endif -/*********************SHT3X I2C init **************************************/ + /*********************SHT3X I2C init **************************************/ #ifdef SHT_USE #ifdef SERIAL_DEBUG -Serial.print(F("\tSHT30 init...\t")); + Serial.print(F("\tSHT30 init...\t")); #endif #ifdef OLED_OUTPUT @@ -545,6 +553,87 @@ Serial.print(F("\tSHT30 init...\t")); #endif } #endif + /*********************SGP30 I2C init **************************************/ +#ifdef SGP30_USE + // Extend I2C clock stretch timeout (See Notes) + //Wire.setClockStretchLimit(500); + Wire.setClockStretchLimit(400000); +#ifdef SERIAL_DEBUG + Serial.print(F("\tSGP30 init...\t")); +#endif + +#ifdef OLED_OUTPUT + // clear the display + display.clear(); + display.drawStringMaxWidth(0, 0, 128, "SGP30 init" ); + // write the buffer to the display + display.display(); +#endif + if (!sgp.begin()) + { + delay(10); +#ifdef SERIAL_DEBUG + Serial.println(F("no SGP30 detected!")); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 16, 128, "SGP30 FAILED" ); + // write the buffer to the display + display.display(); +#endif + + } + else { + sgp30Check = true; + delay(100); + /* + //Get SGP30's ID + sgp.getSerialID(); + //Get version number + sgp.getFeatureSetVersion(); + Serial.print("SerialID: 0x"); + Serial.print((unsigned long)sgp.serialID, HEX); + Serial.print("\tFeature Set Version: 0x"); + Serial.println(sgp.featureSetVersion, HEX);*/ + SGP30ERR error; + //measureTest() should not be called after a call to initAirQuality() + error = sgp.measureTest(); + if (error == SUCCESS) { + Serial.println("Success!"); + } + else if (error == ERR_BAD_CRC) { + Serial.println("CRC Failed"); + } + else if (error == ERR_I2C_TIMEOUT) { + Serial.println("I2C Timed out"); + } + else if (error == SELF_TEST_FAIL) { + Serial.println("Self Test Failed"); + } + //if (!rtcData.sgpInit) { + if (error == SELF_TEST_FAIL) + { + Serial.println(F("SGP30 not initialised")); + sgp.initAirQuality(); + Serial.println(F("SGP30 warm up ")); + + error = sgp.measureTest(); + if (error == SUCCESS) { + rtcData.sgpInit = true; + } + } +#ifdef SERIAL_DEBUG + Serial.println(F("SGP30 ready.")); +#endif + + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 16, 128, "SGP30 ready" ); + // write the buffer to the display + display.display(); +#endif + } +#endif /******************** i2c init END ****************/ } @@ -556,7 +645,7 @@ void setup() { // if serial is not initialized all following calls to serial end dead. #ifdef SERIAL_DEBUG Serial.flush(); - Serial.begin(115200); + Serial.begin(9600); while (!Serial) { delay(1); } // Wait diff --git a/measurement.ino b/measurement.ino index 4928b7c..8f809f1 100644 --- a/measurement.ino +++ b/measurement.ino @@ -1,7 +1,7 @@ /********************* Measurement **************************************/ void measurement() { - + #ifdef BME2_USE if (bme280Check) { bme.read(pressure, temperature, humidity, tempUnit, presUnit); @@ -94,6 +94,7 @@ void measurement() { yield(); } #endif + #ifdef CCS_USE if (ccs811Check) { yield(); @@ -129,688 +130,791 @@ void measurement() { #endif } #endif - /************************** ADC Measurement *********************************/ -#ifdef BATTERY_USE - adc = analogRead(A0); + /******************** SGP30 ********************/ +#ifdef SGP30_USE + if (sgp30Check) { + yield(); + uint8_t sgp_error = 0; + // set environmental data + //sgp.setHumidity(humidity); + sgp.measureAirQuality(); + + // Data is ready + eco2 = float(sgp.CO2); + tvoc = float(sgp.TVOC); + } #ifdef SERIAL_DEBUG - Serial.println("ADC Read:\t" + String(adc) ); + //Serial.println(F("ERROR: SGP30 Data Not Ready")); #endif - yield(); - delay(10); - batt_str = String(float(voltageDivCorrelation(adc) - BATT_MEASUREMENT_OFFSET) / 100); - batt_str.toCharArray(batt, batt_str.length() + 1); + +#endif +/************************** ADC Measurement *********************************/ +#ifdef BATTERY_USE +adc = analogRead(A0); #ifdef SERIAL_DEBUG - Serial.print("Battery Read:\t" + batt_str + " V" + "\t\t\t"); +Serial.println("ADC Read:\t" + String(adc) ); +#endif +yield(); +delay(10); +batt_str = String(float(voltageDivCorrelation(adc) - BATT_MEASUREMENT_OFFSET) / 100); +batt_str.toCharArray(batt, batt_str.length() + 1); +#ifdef SERIAL_DEBUG +Serial.print("Battery Read:\t" + batt_str + " V" + "\t\t\t"); #endif #ifdef SERIAL_DEBUG - Serial.print("Publish Battery: \t\t"); +Serial.print("Publish Battery: \t\t"); #endif - if (! mqttClient.publish(BATTERY_FEED, batt, true, 1) || !mqttClient.loop()) { +if (! mqttClient.publish(BATTERY_FEED, batt, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif +} +else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif +} +yield(); +mqttClient.loop(); +yield(); +delay(10); +#endif +/********************* Temperature **************************************/ +#ifdef BME2_USE +if (bme280Check) { +#ifdef SERIAL_DEBUG + Serial.print("Temperature:\t"); + Serial.print(temperature); + Serial.print(" °" + String(metric ? 'C' : 'F') ); + Serial.print("\t\t\t"); +#endif + temp_str = String(temperature); + temp_str.toCharArray(temp, temp_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + temp_str + "°" + String(metric ? 'C' : 'F')); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish Temperature: \t"); +#endif + if (! mqttClient.publish(TEMPERATURE_FEED, temp, true, 1) || !mqttClient.loop()) { #ifdef SERIAL_DEBUG Serial.println("Failed!"); #endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); + /********************* Pressure **************************************/ +#ifdef SERIAL_DEBUG + Serial.print("Pressure:\t"); + Serial.print(pressure); + Serial.print(" hPa"); + Serial.print("\t\t"); +#endif + pres_str = String(pressure); + pres_str.toCharArray(pres, pres_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 16, 128, pres_str + " hPa"); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish Pressure: \t"); +#endif + if (! mqttClient.publish(PRESSURE_FEED, pres, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 16, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 16, 128, "o"); +#endif + + } + mqttClient.loop(); + yield(); + delay(10); + /********************* Humidity **************************************/ +#ifdef SERIAL_DEBUG + Serial.print("Humidity:\t"); + Serial.print(humidity); + Serial.print(" %" ); + Serial.print("\t\t\t"); +#endif + hum_str = String(humidity); + hum_str.toCharArray(hum, hum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(hum) + " %"); +#endif +#ifdef SERIAL_DEBUG + Serial.print("Publish Humidity: \t"); +#endif + + if (! mqttClient.publish(HUMIDITY_FEED, hum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + } else { #ifdef SERIAL_DEBUG Serial.println("OK"); #endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif } - yield(); mqttClient.loop(); yield(); delay(10); -#endif - /********************* Temperature **************************************/ -#ifdef BME2_USE - if (bme280Check) { -#ifdef SERIAL_DEBUG - Serial.print("Temperature:\t"); - Serial.print(temperature); - Serial.print(" °" + String(metric ? 'C' : 'F') ); - Serial.print("\t\t\t"); -#endif - temp_str = String(temperature); - temp_str.toCharArray(temp, temp_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + temp_str + "°" + String(metric ? 'C' : 'F')); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish Temperature: \t"); -#endif - if (! mqttClient.publish(TEMPERATURE_FEED, temp, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - /********************* Pressure **************************************/ -#ifdef SERIAL_DEBUG - Serial.print("Pressure:\t"); - Serial.print(pressure); - Serial.print(" hPa"); - Serial.print("\t\t"); -#endif - pres_str = String(pressure); - pres_str.toCharArray(pres, pres_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 16, 128, pres_str + " hPa"); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish Pressure: \t"); -#endif - if (! mqttClient.publish(PRESSURE_FEED, pres, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 16, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 16, 128, "o"); -#endif - - } - mqttClient.loop(); - yield(); - delay(10); - /********************* Humidity **************************************/ -#ifdef SERIAL_DEBUG - Serial.print("Humidity:\t"); - Serial.print(humidity); - Serial.print(" %" ); - Serial.print("\t\t\t"); -#endif - hum_str = String(humidity); - hum_str.toCharArray(hum, hum_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(hum) + " %"); -#endif -#ifdef SERIAL_DEBUG - Serial.print("Publish Humidity: \t"); -#endif - - if (! mqttClient.publish(HUMIDITY_FEED, hum, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - - } - else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - /********************* Temperature **************************************/ -#ifdef SHT_USE - if (sht30Check) { -#ifdef SERIAL_DEBUG - Serial.print("Temperature:\t"); - Serial.print(temperature); - Serial.print(" °" + String(metric ? 'C' : 'F') ); - Serial.print("\t\t\t"); -#endif - temp_str = String(temperature); - temp_str.toCharArray(temp, temp_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + temp_str + "°" + String(metric ? 'C' : 'F')); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish Temperature: \t"); -#endif - if (! mqttClient.publish(TEMPERATURE_FEED, temp, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - - /********************* Humidity **************************************/ -#ifdef SERIAL_DEBUG - Serial.print("Humidity:\t"); - Serial.print(humidity); - Serial.print(" %" ); - Serial.print("\t\t\t"); -#endif - hum_str = String(humidity); - hum_str.toCharArray(hum, hum_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(hum) + " %"); -#endif -#ifdef SERIAL_DEBUG - Serial.print("Publish Humidity: \t"); -#endif - - if (! mqttClient.publish(HUMIDITY_FEED, hum, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - - } - else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif //SHT_USE - /********************* Temperature **************************************/ -#ifdef SI7021_USE - if (si7021Check) { -#ifdef SERIAL_DEBUG - Serial.print("Temperature:\t"); - Serial.print(temperature); - Serial.print(" °" + String(metric ? 'C' : 'F') ); - Serial.print("\t\t\t"); -#endif - temp_str = String(temperature); - temp_str.toCharArray(temp, temp_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + temp_str + "°" + String(metric ? 'C' : 'F')); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish Temperature: \t"); -#endif - if (! mqttClient.publish(TEMPERATURE_FEED, temp, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - - /********************* Humidity **************************************/ -#ifdef SERIAL_DEBUG - Serial.print("Humidity:\t"); - Serial.print(humidity); - Serial.print(" %" ); - Serial.print("\t\t\t"); -#endif - hum_str = String(humidity); - hum_str.toCharArray(hum, hum_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(hum) + " %"); -#endif -#ifdef SERIAL_DEBUG - Serial.print("Publish Humidity: \t"); -#endif - - if (! mqttClient.publish(HUMIDITY_FEED, hum, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - - } - else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - /********************* UVA **************************************/ -#ifdef VEML_USE - if (veml6075Check) { -#ifdef SERIAL_DEBUG - Serial.print("UVA:\t\t"); - Serial.print(uvalight); - Serial.print(" Ctr per mW/cm²" ); - Serial.print("\t"); -#endif - uva_str = String(uvalight); - uva_str.toCharArray(uva, uva_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(uva) + " "); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish UVA: \t\t"); -#endif - - if (! mqttClient.publish(UVA_FEED, uva, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - - } - else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - - } - mqttClient.loop(); - yield(); - delay(10); - /********************* UVB **************************************/ -#ifdef SERIAL_DEBUG - Serial.print("UVB:\t\t"); - Serial.print(uvblight); - Serial.print(" Ctr per mW/cm²" ); - Serial.print("\t"); -#endif - uvb_str = String(uvblight); - uvb_str.toCharArray(uvb, uvb_str.length() + 1); - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(uvb) + " "); -#endif -#ifdef SERIAL_DEBUG - Serial.print("Publish UVB: \t\t"); -#endif - if (! mqttClient.publish(UVB_FEED, uvb, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - - } - else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - /********************* UVIndex **************************************/ -#ifdef SERIAL_DEBUG - Serial.print("UVIndex:\t\t"); - Serial.print(uvi); - Serial.print("\t\t\t"); -#endif - uvindex_str = String(uvi); - uvindex_str.toCharArray(uvindex, uvindex_str.length() + 1); - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(uvindex) + " "); -#endif -#ifdef SERIAL_DEBUG - Serial.print("Publish UVIndex: \t\t"); -#endif - if (! mqttClient.publish(UVINDEX_FEED, uvindex, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - } - mqttClient.loop(); - delay(10); - } -#endif - /********************* visible light **************************************/ -#ifdef BH_USE - if (bh1750Check && vislight >= 0.0) { -#ifdef SERIAL_DEBUG - Serial.print("Light:\t\t"); - Serial.print(vislight); - Serial.print(" lx" ); - Serial.print("\t\t"); -#endif - light_str = String(int(vislight)); - light_str.toCharArray(light, light_str.length() + 1); - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 32, 128, " " + String(light) + " lx"); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("\tPublish Light: \t\t"); -#endif - - if (!mqttClient.publish(LIGHT_FEED, light, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 32, 128, "o"); -#endif - } - mqttClient.loop(); - delay(10); - } -#endif - /********************* Absolute Humidity **************************************/ -#ifdef SHT_USE - if (sht30Check) { - absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); -#ifdef SERIAL_DEBUG - Serial.print("abs Humidity:\t"); - Serial.print(absHumidity); - Serial.print(" g/m^3"); - Serial.print("\t\t"); -#endif - absHum_str = String(absHumidity); - absHum_str.toCharArray(absHum, absHum_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish abs Humidity: \t"); -#endif - if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - /********************* Absolute Humidity **************************************/ -#ifdef SI7021_USE - if (si7021Check) { - absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); -#ifdef SERIAL_DEBUG - Serial.print("abs Humidity:\t"); - Serial.print(absHumidity); - Serial.print(" g/m^3"); - Serial.print("\t\t"); -#endif - absHum_str = String(absHumidity); - absHum_str.toCharArray(absHum, absHum_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish abs Humidity: \t"); -#endif - if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - - /********************* Absolute Humidity **************************************/ -#ifdef BME2_USE - if (bme280Check) { - absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); -#ifdef SERIAL_DEBUG - Serial.print("abs Humidity:\t"); - Serial.print(absHumidity); - Serial.print(" g/m^3"); - Serial.print("\t\t"); -#endif - absHum_str = String(absHumidity); - absHum_str.toCharArray(absHum, absHum_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish abs Humidity: \t"); -#endif - if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - - /********************* eCO2 **************************************/ -#ifdef CCS_USE - //fix sensors internal wait delay - if (ccs811Check && eco2 > 0.00) { -#ifdef SERIAL_DEBUG - Serial.print("eCO2:\t\t"); - Serial.print(eco2); - Serial.print(" ppm"); - Serial.print("\t\t"); -#endif - eco2_str = String(eco2); - eco2_str.toCharArray(eco2C, eco2_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + eco2_str + "ppm" ); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish eCO2: \t\t"); -#endif - if (! mqttClient.publish(ECO2_FEED, eco2C, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - /********************* TVOC **************************************/ -#ifdef CCS_USE - //fix sensors internal wait delay - if (ccs811Check && eco2 > 0.00) { -#ifdef SERIAL_DEBUG - Serial.print("TVOC:\t\t"); - Serial.print(tvoc); - Serial.print(" ppb"); - Serial.print("\t\t"); -#endif - tvoc_str = String(tvoc); - tvoc_str.toCharArray(tvocC, tvoc_str.length() + 1); -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(0, 0, 128, " " + tvoc_str + "ppb" ); -#endif - -#ifdef SERIAL_DEBUG - Serial.print("Publish TVOC: \t\t"); -#endif - if (! mqttClient.publish(TVOC_FEED, tvocC, true, 1) || !mqttClient.loop()) { -#ifdef SERIAL_DEBUG - Serial.println("Failed!"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "x"); -#endif - - } else { -#ifdef SERIAL_DEBUG - Serial.println("OK"); -#endif - -#ifdef OLED_OUTPUT - display.drawStringMaxWidth(110, 0, 128, "o"); -#endif - } - mqttClient.loop(); - yield(); - delay(10); - } -#endif - /************************************ END *******************************/ - mqttClient.loop(); - yield(); - delay(10); - return; +} +#endif +/********************* Temperature **************************************/ +#ifdef SHT_USE +if (sht30Check) { +#ifdef SERIAL_DEBUG + Serial.print("Temperature:\t"); + Serial.print(temperature); + Serial.print(" °" + String(metric ? 'C' : 'F') ); + Serial.print("\t\t\t"); +#endif + temp_str = String(temperature); + temp_str.toCharArray(temp, temp_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + temp_str + "°" + String(metric ? 'C' : 'F')); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish Temperature: \t"); +#endif + if (! mqttClient.publish(TEMPERATURE_FEED, temp, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); + + /********************* Humidity **************************************/ +#ifdef SERIAL_DEBUG + Serial.print("Humidity:\t"); + Serial.print(humidity); + Serial.print(" %" ); + Serial.print("\t\t\t"); +#endif + hum_str = String(humidity); + hum_str.toCharArray(hum, hum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(hum) + " %"); +#endif +#ifdef SERIAL_DEBUG + Serial.print("Publish Humidity: \t"); +#endif + + if (! mqttClient.publish(HUMIDITY_FEED, hum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + + } + else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif //SHT_USE +/********************* Temperature **************************************/ +#ifdef SI7021_USE +if (si7021Check) { +#ifdef SERIAL_DEBUG + Serial.print("Temperature:\t"); + Serial.print(temperature); + Serial.print(" °" + String(metric ? 'C' : 'F') ); + Serial.print("\t\t\t"); +#endif + temp_str = String(temperature); + temp_str.toCharArray(temp, temp_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + temp_str + "°" + String(metric ? 'C' : 'F')); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish Temperature: \t"); +#endif + if (! mqttClient.publish(TEMPERATURE_FEED, temp, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); + + /********************* Humidity **************************************/ +#ifdef SERIAL_DEBUG + Serial.print("Humidity:\t"); + Serial.print(humidity); + Serial.print(" %" ); + Serial.print("\t\t\t"); +#endif + hum_str = String(humidity); + hum_str.toCharArray(hum, hum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(hum) + " %"); +#endif +#ifdef SERIAL_DEBUG + Serial.print("Publish Humidity: \t"); +#endif + + if (! mqttClient.publish(HUMIDITY_FEED, hum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + + } + else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif +/********************* UVA **************************************/ +#ifdef VEML_USE +if (veml6075Check) { +#ifdef SERIAL_DEBUG + Serial.print("UVA:\t\t"); + Serial.print(uvalight); + Serial.print(" Ctr per mW/cm²" ); + Serial.print("\t"); +#endif + uva_str = String(uvalight); + uva_str.toCharArray(uva, uva_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(uva) + " "); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish UVA: \t\t"); +#endif + + if (! mqttClient.publish(UVA_FEED, uva, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + + } + else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif + + } + mqttClient.loop(); + yield(); + delay(10); + /********************* UVB **************************************/ +#ifdef SERIAL_DEBUG + Serial.print("UVB:\t\t"); + Serial.print(uvblight); + Serial.print(" Ctr per mW/cm²" ); + Serial.print("\t"); +#endif + uvb_str = String(uvblight); + uvb_str.toCharArray(uvb, uvb_str.length() + 1); + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(uvb) + " "); +#endif +#ifdef SERIAL_DEBUG + Serial.print("Publish UVB: \t\t"); +#endif + if (! mqttClient.publish(UVB_FEED, uvb, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + + } + else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); + /********************* UVIndex **************************************/ +#ifdef SERIAL_DEBUG + Serial.print("UVIndex:\t\t"); + Serial.print(uvi); + Serial.print("\t\t\t"); +#endif + uvindex_str = String(uvi); + uvindex_str.toCharArray(uvindex, uvindex_str.length() + 1); + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(uvindex) + " "); +#endif +#ifdef SERIAL_DEBUG + Serial.print("Publish UVIndex: \t\t"); +#endif + if (! mqttClient.publish(UVINDEX_FEED, uvindex, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif + } + mqttClient.loop(); + delay(10); +} +#endif +/********************* visible light **************************************/ +#ifdef BH_USE +if (bh1750Check && vislight >= 0.0) { +#ifdef SERIAL_DEBUG + Serial.print("Light:\t\t"); + Serial.print(vislight); + Serial.print(" lx" ); + Serial.print("\t\t"); +#endif + light_str = String(int(vislight)); + light_str.toCharArray(light, light_str.length() + 1); + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 32, 128, " " + String(light) + " lx"); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("\tPublish Light: \t\t"); +#endif + + if (!mqttClient.publish(LIGHT_FEED, light, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 32, 128, "o"); +#endif + } + mqttClient.loop(); + delay(10); +} +#endif +/********************* Absolute Humidity **************************************/ +#ifdef SHT_USE +if (sht30Check) { + absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); +#ifdef SERIAL_DEBUG + Serial.print("abs Humidity:\t"); + Serial.print(absHumidity); + Serial.print(" g/m^3"); + Serial.print("\t\t"); +#endif + absHum_str = String(absHumidity); + absHum_str.toCharArray(absHum, absHum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish abs Humidity: \t"); +#endif + if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif +/********************* Absolute Humidity **************************************/ +#ifdef SI7021_USE +if (si7021Check) { + absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); +#ifdef SERIAL_DEBUG + Serial.print("abs Humidity:\t"); + Serial.print(absHumidity); + Serial.print(" g/m^3"); + Serial.print("\t\t"); +#endif + absHum_str = String(absHumidity); + absHum_str.toCharArray(absHum, absHum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish abs Humidity: \t"); +#endif + if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif + +/********************* Absolute Humidity **************************************/ +#ifdef BME2_USE +if (bme280Check) { + absHumidity = EnvironmentCalculations::AbsoluteHumidity(temperature, humidity, EnvironmentCalculations::TempUnit_Celsius); +#ifdef SERIAL_DEBUG + Serial.print("abs Humidity:\t"); + Serial.print(absHumidity); + Serial.print(" g/m^3"); + Serial.print("\t\t"); +#endif + absHum_str = String(absHumidity); + absHum_str.toCharArray(absHum, absHum_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + absHum_str + "g/m^3" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish abs Humidity: \t"); +#endif + if (! mqttClient.publish(ABSHUMIDITY_FEED, absHum, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif + +/********************* eCO2 **************************************/ +#ifdef CCS_USE +//fix sensors internal wait delay +if (ccs811Check && eco2 > 0.00) { +#ifdef SERIAL_DEBUG + Serial.print("eCO2:\t\t"); + Serial.print(eco2); + Serial.print(" ppm"); + Serial.print("\t\t"); +#endif + eco2_str = String(eco2); + eco2_str.toCharArray(eco2C, eco2_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + eco2_str + "ppm" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish eCO2: \t\t"); +#endif + if (! mqttClient.publish(ECO2_FEED, eco2C, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif +/********************* TVOC **************************************/ +#ifdef CCS_USE +//fix sensors internal wait delay +if (ccs811Check && eco2 > 0.00) { +#ifdef SERIAL_DEBUG + Serial.print("TVOC:\t\t"); + Serial.print(tvoc); + Serial.print(" ppb"); + Serial.print("\t\t"); +#endif + tvoc_str = String(tvoc); + tvoc_str.toCharArray(tvocC, tvoc_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + tvoc_str + "ppb" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish TVOC: \t\t"); +#endif + if (! mqttClient.publish(TVOC_FEED, tvocC, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif + +/********************* SGP30 eCO2 **************************************/ +#ifdef SGP30_USE +//fix sensors internal wait delay +if (sgp30Check) { +#ifdef SERIAL_DEBUG + Serial.print("eCO2:\t\t"); + Serial.print(eco2); + Serial.print(" ppm"); + Serial.print("\t\t"); +#endif + eco2_str = String(eco2); + eco2_str.toCharArray(eco2C, eco2_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + eco2_str + "ppm" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish eCO2: \t\t"); +#endif + if (! mqttClient.publish(ECO2_FEED, eco2C, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif +/********************* TVOC **************************************/ +#ifdef SGP30_USE +//fix sensors internal wait delay +if (sgp30Check) { +#ifdef SERIAL_DEBUG + Serial.print("TVOC:\t\t"); + Serial.print(tvoc); + Serial.print(" ppb"); + Serial.print("\t\t"); +#endif + tvoc_str = String(tvoc); + tvoc_str.toCharArray(tvocC, tvoc_str.length() + 1); +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(0, 0, 128, " " + tvoc_str + "ppb" ); +#endif + +#ifdef SERIAL_DEBUG + Serial.print("Publish TVOC: \t\t"); +#endif + if (! mqttClient.publish(TVOC_FEED, tvocC, true, 1) || !mqttClient.loop()) { +#ifdef SERIAL_DEBUG + Serial.println("Failed!"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "x"); +#endif + + } else { +#ifdef SERIAL_DEBUG + Serial.println("OK"); +#endif + +#ifdef OLED_OUTPUT + display.drawStringMaxWidth(110, 0, 128, "o"); +#endif + } + mqttClient.loop(); + yield(); + delay(10); +} +#endif +/************************************ END *******************************/ +mqttClient.loop(); +yield(); +delay(10); +return; }