SCD4X: Setup and MQTT

This commit is contained in:
Mathieu Maret 2023-11-27 23:47:53 +01:00
parent 0f8c14e51e
commit 346d7927d8
4 changed files with 17 additions and 2 deletions

View File

@ -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"

View File

@ -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;
}

View File

@ -53,6 +53,7 @@
#include "Adafruit_MQTT_Client.h"
#include "EEPROM.h"
#include "Teleinfo.h"
#include "SCD4X.h"
extern "C" {
#include <user_interface.h>
@ -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});

View File

@ -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