scd4x #1
@ -14,8 +14,6 @@
|
|||||||
//Use Default i2c pin GPIO4(D2): SDA, GPIO5(D1):SCL
|
//Use Default i2c pin GPIO4(D2): SDA, GPIO5(D1):SCL
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
#include <SFE_BMP180.h>
|
|
||||||
#include "debug_sketch.h"
|
|
||||||
|
|
||||||
int BME680GetMeasure(float &t, float &p, float &h, float &g, float &a);
|
int BME680GetMeasure(float &t, float &p, float &h, float &g, float &a);
|
||||||
int BME680Setup();
|
int BME680Setup();
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
#define TELEINFO_IINST_FEED_FORMAT "/feeds/%s/%s/teleinfo/iinst"
|
#define TELEINFO_IINST_FEED_FORMAT "/feeds/%s/%s/teleinfo/iinst"
|
||||||
#define TELEINFO_PAPP_FEED_FORMAT "/feeds/%s/%s/teleinfo/papp"
|
#define TELEINFO_PAPP_FEED_FORMAT "/feeds/%s/%s/teleinfo/papp"
|
||||||
#define TELEINFO_BASE_FEED_FORMAT "/feeds/%s/%s/teleinfo/base"
|
#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
|
#ifndef CONFIG_DISABLE_MQTT
|
||||||
#include "Adafruit_MQTT.h"
|
#include "Adafruit_MQTT.h"
|
||||||
|
|
||||||
|
23
WifiControlSensor/SCD4X.h
Normal file
23
WifiControlSensor/SCD4X.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef CONFIG_ENABLE_SCD4X
|
||||||
|
#include "debug_sketch.h"
|
||||||
|
|
||||||
|
int SCD4XGetMeasure(float &t, float &h, uint16_t &co2);
|
||||||
|
int SCD4XSetup();
|
||||||
|
bool SCD4XIsConnected();
|
||||||
|
|
||||||
|
#else
|
||||||
|
int SCD4XGetMeasure(float &, float &, uint16_t &)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
int SCD4XSetup()
|
||||||
|
{
|
||||||
|
SKETCH_DEBUG_PRINTLN("SCD4X is disabled at build time");
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
bool SCD4XIsConnected()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
#endif
|
61
WifiControlSensor/SCD4X.ino
Normal file
61
WifiControlSensor/SCD4X.ino
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#ifdef CONFIG_ENABLE_SCD4X
|
||||||
|
#include "SCD4X.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SensirionI2CScd4x.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
SensirionI2CScd4x scd4x;
|
||||||
|
|
||||||
|
int SCD4XConnected = 0;
|
||||||
|
|
||||||
|
int SCD4XSetup()
|
||||||
|
{
|
||||||
|
Wire.begin();
|
||||||
|
scd4x.begin(Wire);
|
||||||
|
|
||||||
|
// Stop previous measurement
|
||||||
|
uint16_t error = scd4x.stopPeriodicMeasurement();
|
||||||
|
if (error) {
|
||||||
|
SKETCH_DEBUG_PRINTLN("Cannot connect to SCD4X");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start new measurement
|
||||||
|
error = scd4x.startPeriodicMeasurement();
|
||||||
|
if (error) {
|
||||||
|
SKETCH_DEBUG_PRINTLN("Cannot start measurement for SCD4X");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
SCD4XConnected = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int SCD4XGetMeasure(float &temperature, float &humidity, uint16_t &co2)
|
||||||
|
{
|
||||||
|
// Read Measurement
|
||||||
|
bool isDataReady = false;
|
||||||
|
|
||||||
|
uint16_t error = scd4x.getDataReadyFlag(isDataReady);
|
||||||
|
if (error) {
|
||||||
|
SKETCH_DEBUG_PRINTLN("Error trying to execute getDataReadyFlag() for SCD4X ");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!isDataReady) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
error = scd4x.readMeasurement(co2, temperature, humidity);
|
||||||
|
if (error || co2 == 0) {
|
||||||
|
char errorMsg[256];
|
||||||
|
SKETCH_DEBUG_PRINT("Error with reading measurement. Error : ");
|
||||||
|
errorToString(error, errorMsg, sizeof(errorMsg));
|
||||||
|
SKETCH_DEBUG_PRINTF(" Co2: %d\n", co2);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
bool SCD4XIsConnected()
|
||||||
|
{
|
||||||
|
return SCD4XConnected != 0;
|
||||||
|
}
|
||||||
|
#endif
|
@ -37,6 +37,9 @@ void WebHandleRoot() {
|
|||||||
#ifdef CONFIG_ENABLE_DHT
|
#ifdef CONFIG_ENABLE_DHT
|
||||||
"" + (DHTIsConnected() ? "<h6>DHT</h6>Temperature " + String(dhtTemp, 0) + "C<br/> Humidity " + String(dhtHumidity, 0) + "%<br/>" : "DHT Disconnected" ) + ""
|
"" + (DHTIsConnected() ? "<h6>DHT</h6>Temperature " + String(dhtTemp, 0) + "C<br/> Humidity " + String(dhtHumidity, 0) + "%<br/>" : "DHT Disconnected" ) + ""
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_ENABLE_SCD4X
|
||||||
|
"" + (SCD4XIsConnected() ? "<h6>SCD4X</h6>Temperature " + String(SCD4xT, 0) + "C<br/> Humidity " + String(SCD4xH, 0) + "%<br/> CO2 " + String(SCD4xCo2) + "ppm<br/>" : "SCD4X Disconnected" ) + ""
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_ENABLE_BME680
|
#ifdef CONFIG_ENABLE_BME680
|
||||||
"" + (BME680IsConnected() ? "<h6>BME680</h6>Temperature " + String(bme680T, 2) + "C<br/> Pressure " + String(bme680P, 2) + "hPa<br/> Humidity " + String(bme680H, 2) + "%<br/> Gaz " + String(bme680G, 2) + "kOhm<br/>" : "BME680 Disconnected" ) + ""
|
"" + (BME680IsConnected() ? "<h6>BME680</h6>Temperature " + String(bme680T, 2) + "C<br/> Pressure " + String(bme680P, 2) + "hPa<br/> Humidity " + String(bme680H, 2) + "%<br/> Gaz " + String(bme680G, 2) + "kOhm<br/>" : "BME680 Disconnected" ) + ""
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include "Adafruit_MQTT_Client.h"
|
#include "Adafruit_MQTT_Client.h"
|
||||||
#include "EEPROM.h"
|
#include "EEPROM.h"
|
||||||
#include "Teleinfo.h"
|
#include "Teleinfo.h"
|
||||||
|
#include "SCD4X.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <user_interface.h>
|
#include <user_interface.h>
|
||||||
@ -68,6 +69,8 @@ float dhtTemp, dhtHumidity;
|
|||||||
float bme680T, bme680P, bme680H, bme680G, bme680A;
|
float bme680T, bme680P, bme680H, bme680G, bme680A;
|
||||||
float bme680BSECT, bme680BSECP, bme680BSECH, bme680BSECIaq, bme680BSECIaqAcc;
|
float bme680BSECT, bme680BSECP, bme680BSECH, bme680BSECIaq, bme680BSECIaqAcc;
|
||||||
float teleIinst, telePapp, teleBase;
|
float teleIinst, telePapp, teleBase;
|
||||||
|
float SCD4xT, SCD4xH;
|
||||||
|
uint16_t SCD4xCo2;
|
||||||
int dryness;
|
int dryness;
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
int reconfig = 0;
|
int reconfig = 0;
|
||||||
@ -296,6 +299,9 @@ void setup()
|
|||||||
if(!TeleinfoSetup()){
|
if(!TeleinfoSetup()){
|
||||||
SKETCH_DEBUG_PRINTLN("Teleinfo init success");
|
SKETCH_DEBUG_PRINTLN("Teleinfo init success");
|
||||||
}
|
}
|
||||||
|
if(!SCD4XSetup()){
|
||||||
|
SKETCH_DEBUG_PRINTLN("SCD4X init success");
|
||||||
|
}
|
||||||
WebSetupServer(mode);
|
WebSetupServer(mode);
|
||||||
}
|
}
|
||||||
samplingPeriod = conf.samplingPeriod;
|
samplingPeriod = conf.samplingPeriod;
|
||||||
@ -334,6 +340,12 @@ void loop() {
|
|||||||
batchInfo.push_back({dhtTemp, TEMPERATURE_DHT_FEED_FORMAT, 0, 0});
|
batchInfo.push_back({dhtTemp, TEMPERATURE_DHT_FEED_FORMAT, 0, 0});
|
||||||
batchInfo.push_back({dhtHumidity, HUMIDITY_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)) {
|
if (!DryGetMeasure(dryness)) {
|
||||||
SKETCH_DEBUG_PRINTF("Current dryness %d %%\n", (dryness * 100) / 1024);
|
SKETCH_DEBUG_PRINTF("Current dryness %d %%\n", (dryness * 100) / 1024);
|
||||||
batchInfo.push_back({(float)dryness, DRY_FEED_FORMAT, 0, 0});
|
batchInfo.push_back({(float)dryness, DRY_FEED_FORMAT, 0, 0});
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
//If the dry sensor is powered by a GPIO, this GPIO could be defined here
|
//If the dry sensor is powered by a GPIO, this GPIO could be defined here
|
||||||
//#define CONFIG_DRY_POWER_PIN 13
|
//#define CONFIG_DRY_POWER_PIN 13
|
||||||
|
|
||||||
|
//Advised CONFIG_SAMPLING_PERIOD_MS is 5s for this sensor
|
||||||
|
//#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)
|
// 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
|
#define CONFIG_ENABLE_POWER_SAVE
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user