15 ESP_LOGD(TAG,
"'%s': ratio=%.4f -> %.1f ppm", this->
get_name().c_str(), ratio, ppm);
21 ESP_LOGI(TAG,
"using the air reference from the configuration (%.4f V)", this->
reference_);
27 ESP_LOGI(TAG,
"warm-up of %" PRIu32
" s - no readings published before that", this->
warmup_time_ / 1000);
34 ESP_LOGI(TAG,
"air reference calibration in %" PRIu32
" s - the sensor must be in clean air",
delay / 1000);
36 ESP_LOGW(TAG,
"no air reference available, the PPM values stay unknown\n"
37 " set 'air_reference:' or enable 'calibration:'");
47 " VCC: %.2f V, AO multiplier: x%.3f, AO samples per reading: %u\n"
48 " Warm-up: %" PRIu32
" s, calibration: %s, sample spacing: %" PRIu32
" ms",
52 LOG_UPDATE_INTERVAL(
this);
54 ESP_LOGCONFIG(TAG,
" Air reference (vcc - V_AO): %.4f V", this->
reference_);
56 ESP_LOGCONFIG(TAG,
" Air reference: not available yet");
58#ifdef MICS_5524_GAS_COUNT
59 for (
auto *gas : this->
gases_) {
60 LOG_SENSOR(
" ",
"Gas", gas);
61 ESP_LOGCONFIG(TAG,
" Range: %.1f - %.1f ppm", gas->get_min_ppm(), gas->get_max_ppm());
69 for (uint8_t i = 0; i < this->
samples_; i++)
75#ifdef MICS_5524_GAS_COUNT
76 for (
auto *gas : this->
gases_) {
77 gas->publish_ratio(ratio);
89 ESP_LOGW(TAG,
"analog output reads %.4f V with vcc %.2f V\n check the AO wiring, 'vcc:' and 'voltage_multiplier:'",
102 if (std::isnan(air_value)) {
109 ESP_LOGD(TAG,
"V_AO=%.4f V, x=%.4f, ratio=%.4f", this->
vcc_ - air_value, air_value, ratio);
144 ESP_LOGI(TAG,
"calibrating the air reference, %" PRIu32
" samples - keep the sensor in clean air",
152 if (!std::isnan(reference)) {
170 const uint32_t required = std::max<uint32_t>((attempts + 1) / 2, 2);
172 if (
valid < required) {
173 ESP_LOGW(TAG,
"calibration failed, %" PRIu32
" of %" PRIu32
" samples were valid",
valid, attempts);
183 TAG,
"clean-air samples spread %.4f V around %.4f V (%.4f - %.4f V)\n the sensor was not settled in clean air",
193 "air reference = %.4f (%" PRIu32
"/%" PRIu32
" samples valid)\n"
194 " hard-code 'air_reference: %.4f' to skip the calibration at boot",
203 ESP_LOGW(TAG,
"retrying the calibration in %" PRIu32
" s",
delay / 1000);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void status_set_warning()
void enable_loop()
Enable this component's loop.
bool status_has_warning() const
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void disable_loop()
Disable this component's loop.
void status_clear_warning()
const StringRef & get_name() const
void begin_calibration_()
uint32_t calibration_samples_
0 when calibration is disabled.
bool has_reference_() const
uint32_t calibration_count_
uint32_t sample_interval_
Spacing of the clean-air calibration samples (ms); the ~16 ms loop tick is the floor.
static constexpr uint32_t CALIBRATION_START_ID
void finish_calibration_()
uint32_t calibration_delay_
float reference_
Clean-air reference x_air in volts, 0 while there is none.
void publish_ratio_(float ratio)
StaticVector< MiCS5524GasSensor *, MICS_5524_GAS_COUNT > gases_
float sample_voltage_()
Averaged, scaled output voltage (V); the conversions run back to back.
float voltage_multiplier_
void schedule_calibration_retry_()
void set_calibration(uint32_t delay, uint32_t samples, uint32_t sample_interval)
Calibrate at boot: start after delay ms, average samples readings sample_interval ms apart.
float read_air_value_()
x = vcc - V_AO, or NAN (and a status warning) when the voltage is unusable.
void dump_config() override
voltage_sampler::VoltageSampler * source_
uint32_t calibration_last_sample_
static constexpr uint32_t CALIBRATION_RETRY_MIN_MS
Floor of the delay between two calibration attempts (ms).
uint32_t calibration_attempts_
void process_calibration_()
float calibration_min_
Smallest and largest clean-air sample of the run, see calibration_is_stable().
micsmath::VendorCurve curve_
void publish_ratio(float ratio)
Publish the concentration for ratio; NAN publishes unknown.
void publish_state(float state)
Publish a new state to the front-end.
virtual float sample()=0
Get a voltage reading, in V.
bool calibration_is_stable(float min_value, float max_value, float mean)
True when the clean-air samples spread at most MAX_CALIBRATION_SPREAD of their mean.
float air_value_from_voltage(float voltage, float vcc)
x = VCC - V_ao: 0 at VCC (a saturated sensor, never clean air).
float ratio_from_air_value(float x, float x_air)
ratio = x / x_air (NaN when either value is unusable).
float ppm_from_vendor_curve(float ratio, const VendorCurve &curve)
ratio -> ppm as DFRobot_MICS getGasData(): 0 above the threshold or below the vendor range,...
ESPHOME_LOG_TAG(TAG, "mics_5524")
void HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.