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) {
73 if (red_f <= 0.425f) {
74 co = (0.425f - red_f) / 0.000405f;
80 this->carbon_monoxide_sensor_->publish_state(co);
83 if (this->nitrogen_dioxide_sensor_ !=
nullptr) {
84 float nitrogendioxide = 0.0f;
86 nitrogendioxide = (ox_f - 0.045f) / 6.13f;
87 if (nitrogendioxide < 0.1f)
88 nitrogendioxide = 0.0f;
89 if (nitrogendioxide > 10.0f)
90 nitrogendioxide = 10.0f;
92 this->nitrogen_dioxide_sensor_->publish_state(nitrogendioxide);
95 if (this->methane_sensor_ !=
nullptr) {
97 if (red_f <= 0.786f) {
98 methane = (0.786f - red_f) / 0.000023f;
99 if (methane < 1000.0f)
101 if (methane > 25000.0f)
104 this->methane_sensor_->publish_state(methane);
107 if (this->ethanol_sensor_ !=
nullptr) {
108 float ethanol = 0.0f;
109 if (red_f <= 0.306f) {
110 ethanol = (0.306f - red_f) / 0.00057f;
113 if (ethanol > 500.0f)
116 this->ethanol_sensor_->publish_state(ethanol);
119 if (this->hydrogen_sensor_ !=
nullptr) {
120 float hydrogen = 0.0f;
121 if (red_f <= 0.279f) {
122 hydrogen = (0.279f - red_f) / 0.00026f;
125 if (hydrogen > 1000.0f)
128 this->hydrogen_sensor_->publish_state(hydrogen);
131 if (this->ammonia_sensor_ !=
nullptr) {
132 float ammonia = 0.0f;
134 ammonia = (0.8f - red_f) / 0.0015f;
137 if (ammonia > 500.0f)
140 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.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
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)