8 static const char *
const TAG =
"pylontech";
9 static const int MAX_DATA_LENGTH_BYTES = 256;
10 static const uint8_t ASCII_LF = 0x0A;
16 ESP_LOGCONFIG(TAG,
"pylontech:");
18 ESP_LOGE(TAG,
"Connection with pylontech failed!");
22 listener->dump_config();
25 LOG_UPDATE_INTERVAL(
this);
29 ESP_LOGCONFIG(TAG,
"Setting up pylontech...");
54 ESP_LOGV(TAG,
"received %d bytes", recv);
60 buffer_index_read_ = (buffer_index_read_ + 1) % NUM_BUFFERS;
66 ESP_LOGV(TAG,
"Read from serial: %s", buffer.substr(0, buffer.size() - 2).c_str());
75 const int parsed = sscanf(
76 buffer.c_str(),
"%d %d %d %d %d %d %d %d %7s %7s %7s %7s %d%% %*d-%*d-%*d %*d:%*d:%*d %*s %*s %5s %*s",
77 &
l.bat_num, &
l.volt, &
l.curr, &
l.tempr, &
l.tlow, &
l.thigh, &
l.vlow, &
l.vhigh,
l.base_st,
l.volt_st,
78 l.curr_st,
l.temp_st, &
l.coulomb, mostempr_s);
81 ESP_LOGD(TAG,
"invalid bat_num in line %s", buffer.substr(0, buffer.size() - 2).c_str());
85 ESP_LOGW(TAG,
"invalid line: found only %d items in %s", parsed, buffer.substr(0, buffer.size() - 2).c_str());
88 auto mostempr_parsed = parse_number<int>(mostempr_s);
89 if (mostempr_parsed.has_value()) {
90 l.mostempr = mostempr_parsed.value();
93 ESP_LOGW(TAG,
"bat_num %d: received no mostempr",
l.bat_num);
97 listener->on_line_read(&
l);
void write_str(const char *str)
void loop() override
Read data once available.
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
void setup() override
Setup the sensor and test for a connection.
void dump_config() override
std::vector< PylontechListener * > listeners_
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
void update() override
Schedule data readings.
bool read_byte(uint8_t *data)
Implementation of SPI Controller mode.
void process_line_(std::string &buffer)
std::string buffer_[NUM_BUFFERS]