9 static const char *
const TAG =
"mics_4514";
11 static const uint8_t SENSOR_REGISTER = 0x04;
12 static const uint8_t POWER_MODE_REGISTER = 0x0a;
15 ESP_LOGCONFIG(TAG,
"Setting up MICS 4514...");
18 if (power_mode == 0x00) {
19 ESP_LOGCONFIG(TAG,
"Waking up MICS 4514, sensors will have data after 3 minutes...");
23 this->
set_timeout(
"warmup", 3 * 60 * 1000, [
this]() {
25 ESP_LOGCONFIG(TAG,
"MICS 4514 setup complete.");
30 ESP_LOGCONFIG(TAG,
"Device already awake.");
32 ESP_LOGCONFIG(TAG,
"MICS 4514 setup complete.");
34 void MICS4514Component::dump_config() {
35 ESP_LOGCONFIG(TAG,
"MICS 4514:");
37 LOG_UPDATE_INTERVAL(
this);
38 LOG_SENSOR(
" ",
"Nitrogen Dioxide", this->nitrogen_dioxide_sensor_);
39 LOG_SENSOR(
" ",
"Carbon Monoxide", this->carbon_monoxide_sensor_);
40 LOG_SENSOR(
" ",
"Methane", this->methane_sensor_);
41 LOG_SENSOR(
" ",
"Ethanol", this->ethanol_sensor_);
42 LOG_SENSOR(
" ",
"Hydrogen", this->hydrogen_sensor_);
43 LOG_SENSOR(
" ",
"Ammonia", this->ammonia_sensor_);
46 void MICS4514Component::update() {
56 ESP_LOGV(TAG,
"Got data: %02X %02X %02X %02X %02X %02X", data[0], data[1], data[2], data[3], data[4], data[5]);
71 if (this->carbon_monoxide_sensor_ !=
nullptr) {
75 }
else if (red_f < 0.01) {
78 co = 4.2 / pow(red_f, 1.2);
80 this->carbon_monoxide_sensor_->publish_state(co);
83 if (this->nitrogen_dioxide_sensor_ !=
nullptr) {
84 float nitrogendioxide = 0.0f;
86 nitrogendioxide = 0.0;
88 nitrogendioxide = 0.164 * pow(ox_f, 0.975);
90 this->nitrogen_dioxide_sensor_->publish_state(nitrogendioxide);
93 if (this->methane_sensor_ !=
nullptr) {
95 if (red_f > 0.9f || red_f < 0.5) {
98 methane = 630 / pow(red_f, 4.4);
100 this->methane_sensor_->publish_state(methane);
103 if (this->ethanol_sensor_ !=
nullptr) {
104 float ethanol = 0.0f;
105 if (red_f > 1.0f || red_f < 0.02) {
108 ethanol = 1.52 / pow(red_f, 1.55);
110 this->ethanol_sensor_->publish_state(ethanol);
113 if (this->hydrogen_sensor_ !=
nullptr) {
114 float hydrogen = 0.0f;
115 if (red_f > 0.9f || red_f < 0.02) {
118 hydrogen = 0.85 / pow(red_f, 1.75);
120 this->hydrogen_sensor_->publish_state(hydrogen);
123 if (this->ammonia_sensor_ !=
nullptr) {
124 float ammonia = 0.0f;
125 if (red_f > 0.98f || red_f < 0.2532) {
128 ammonia = 0.9 / pow(red_f, 4.6);
130 this->ammonia_sensor_->publish_state(ammonia);
const float DATA
For components that import data from directly connected sensors like DHT.
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
void status_set_warning(const char *message="unspecified")
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
virtual void setup()
Where the component's initialization should happen.
No error found during execution of method.
void status_clear_warning()
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Implementation of SPI Controller mode.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
void IRAM_ATTR HOT delay(uint32_t ms)