ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
smt100.cpp
Go to the documentation of this file.
1#include "smt100.h"
2#include "esphome/core/log.h"
3
4namespace esphome::smt100 {
5
6ESPHOME_LOG_TAG(TAG, "smt100");
7
9 ESP_LOGV(TAG, "Sending measurement request");
10 this->write_str("GetAllMeasurements!\r");
11}
12
14 this->read_available([this](uint8_t readch) {
15 if (readch == 0)
16 return;
17 char *line = this->line_reader_.feed(readch);
18 this->line_reader_.log_if_overflowed(TAG);
19 if (line != nullptr && line[0] != '\0') {
20 char *token = strtok(line, ",");
21 if (!token)
22 return;
23 int counts = (int) strtol(token, nullptr, 10);
24 token = strtok(nullptr, ",");
25 if (!token)
26 return;
27 float permittivity = (float) strtod(token, nullptr);
28 token = strtok(nullptr, ",");
29 if (!token)
30 return;
31 float moisture = (float) strtod(token, nullptr);
32 token = strtok(nullptr, ",");
33 if (!token)
34 return;
35 float temperature = (float) strtod(token, nullptr);
36 token = strtok(nullptr, ",");
37 if (!token)
38 return;
39 float voltage = (float) strtod(token, nullptr);
40
41 PUBLISH_STATE(this->counts_sensor_, counts);
42
43 PUBLISH_STATE(this->permittivity_sensor_, permittivity);
44
45 PUBLISH_STATE(this->moisture_sensor_, moisture);
46
47 PUBLISH_STATE(this->temperature_sensor_, temperature);
48
49 PUBLISH_STATE(this->voltage_sensor_, voltage);
50 }
51 });
52}
53
55 ESP_LOGCONFIG(TAG, "SMT100:");
56
57 LOG_SENSOR(TAG, "Counts", this->counts_sensor_);
58 LOG_SENSOR(TAG, "Permittivity", this->permittivity_sensor_);
59 LOG_SENSOR(TAG, "Temperature", this->temperature_sensor_);
60 LOG_SENSOR(TAG, "Moisture", this->moisture_sensor_);
61 LOG_UPDATE_INTERVAL(this);
62}
63
64} // namespace esphome::smt100
void write_str(const char *str)
Definition uart.h:37
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
Definition uart.h:77
ESPHOME_LOG_TAG(TAG, "smt100")
uint16_t temperature
Definition sun_gtil2.cpp:12