diff --git a/WifiControlSensor/MQTT.h b/WifiControlSensor/MQTT.h index ff56b21..ab4fc0d 100644 --- a/WifiControlSensor/MQTT.h +++ b/WifiControlSensor/MQTT.h @@ -21,6 +21,9 @@ #define TELEINFO_IINST_FEED_FORMAT "/feeds/%s/%s/teleinfo/iinst" #define TELEINFO_PAPP_FEED_FORMAT "/feeds/%s/%s/teleinfo/papp" #define TELEINFO_BASE_FEED_FORMAT "/feeds/%s/%s/teleinfo/base" +#define SCD4X_TEMPERATURE_FEED_FORMAT "/feeds/%s/%s/scd4x/temperature" +#define SCD4X_HUMIDITY_FEED_FORMAT "/feeds/%s/%s/scd4x/humidity" +#define SCD4X_CO2_FEED_FORMAT "/feeds/%s/%s/scd4x/co2" #ifndef CONFIG_DISABLE_MQTT #include "Adafruit_MQTT.h" diff --git a/WifiControlSensor/SCD4X.ino b/WifiControlSensor/SCD4X.ino index faa4bc4..b6fe3d6 100644 --- a/WifiControlSensor/SCD4X.ino +++ b/WifiControlSensor/SCD4X.ino @@ -48,7 +48,7 @@ int SCD4XGetMeasure(float &temperature, float &humidity, uint16_t &co2) char errorMsg[256]; SKETCH_DEBUG_PRINT("Error with reading measurement. Error : "); errorToString(error, errorMsg, sizeof(errorMsg)); - SKETCH_DEBUG_PRINTLN(" Co2: %d", co2); + SKETCH_DEBUG_PRINTF(" Co2: %d\n", co2); return -1; } diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index eab291f..12cb37f 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -53,6 +53,7 @@ #include "Adafruit_MQTT_Client.h" #include "EEPROM.h" #include "Teleinfo.h" +#include "SCD4X.h" extern "C" { #include @@ -68,6 +69,8 @@ float dhtTemp, dhtHumidity; float bme680T, bme680P, bme680H, bme680G, bme680A; float bme680BSECT, bme680BSECP, bme680BSECH, bme680BSECIaq, bme680BSECIaqAcc; float teleIinst, telePapp, teleBase; +float SCD4xT, SCD4xH; +uint16_t SCD4xCo2; int dryness; uint8_t mode; int reconfig = 0; @@ -296,6 +299,9 @@ void setup() if(!TeleinfoSetup()){ SKETCH_DEBUG_PRINTLN("Teleinfo init success"); } + if(!SCD4XSetup()){ + SKETCH_DEBUG_PRINTLN("SCD4X init success"); + } WebSetupServer(mode); } samplingPeriod = conf.samplingPeriod; @@ -334,6 +340,12 @@ void loop() { batchInfo.push_back({dhtTemp, TEMPERATURE_DHT_FEED_FORMAT, 0, 0}); batchInfo.push_back({dhtHumidity, HUMIDITY_DHT_FEED_FORMAT, 0, 0}); } + if (!SCD4XGetMeasure(SCD4xT, SCD4xH, SCD4xCo2)) { + SKETCH_DEBUG_PRINTF("Current %f°C %f Humidity, Current C02 %d\n", SCD4xT, SCD4xH, SCD4xCo2); + batchInfo.push_back({SCD4xT, SCD4X_TEMPERATURE_FEED_FORMAT, 0, 0}); + batchInfo.push_back({SCD4xH, SCD4X_HUMIDITY_FEED_FORMAT, 0, 0}); + batchInfo.push_back({(float)SCD4xCo2, SCD4X_CO2_FEED_FORMAT, 0, 0}); + } if (!DryGetMeasure(dryness)) { SKETCH_DEBUG_PRINTF("Current dryness %d %%\n", (dryness * 100) / 1024); batchInfo.push_back({(float)dryness, DRY_FEED_FORMAT, 0, 0}); diff --git a/WifiControlSensor/config_device.h b/WifiControlSensor/config_device.h index ae5dbd3..06eea5b 100644 --- a/WifiControlSensor/config_device.h +++ b/WifiControlSensor/config_device.h @@ -35,7 +35,7 @@ //#define CONFIG_ENABLE_DRY_SENSOR //If the dry sensor is powered by a GPIO, this GPIO could be defined here //#define CONFIG_DRY_POWER_PIN 13 - +#define CONFIG_ENABLE_SCD4X // Enable light sleep to save some power (http://bbs.espressif.com/viewtopic.php?f=6&t=133&p=485&hilit=sleep+modem#p485) #define CONFIG_ENABLE_POWER_SAVE