mirror of
https://github.com/esphome/esphome.git
synced 2025-01-03 19:31:46 +01:00
fix: modbus_textsensor response is too long in some cases (#6333)
This commit is contained in:
parent
3e2ce363a2
commit
0cdd0b295e
1 changed files with 3 additions and 3 deletions
|
@ -13,10 +13,10 @@ void ModbusTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Modbus Controller Te
|
||||||
|
|
||||||
void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) {
|
void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) {
|
||||||
std::ostringstream output;
|
std::ostringstream output;
|
||||||
uint8_t max_items = this->response_bytes;
|
uint8_t items_left = this->response_bytes;
|
||||||
uint8_t index = this->offset;
|
uint8_t index = this->offset;
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
while ((max_items != 0) && index < data.size()) {
|
while ((items_left > 0) && index < data.size()) {
|
||||||
uint8_t b = data[index];
|
uint8_t b = data[index];
|
||||||
switch (this->encode_) {
|
switch (this->encode_) {
|
||||||
case RawEncoding::HEXBYTES:
|
case RawEncoding::HEXBYTES:
|
||||||
|
@ -33,7 +33,7 @@ void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) {
|
||||||
output << (char) b;
|
output << (char) b;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
items_left--;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue