From cc4f1c667ed15f1962c6bacaa7b30c0a7f329b43 Mon Sep 17 00:00:00 2001 From: Petapton <14984292+Petapton@users.noreply.github.com> Date: Wed, 26 Jun 2024 02:08:16 +0200 Subject: [PATCH] Fix float encoding in modbus server (#6986) --- esphome/components/modbus_controller/modbus_controller.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/modbus_controller/modbus_controller.cpp b/esphome/components/modbus_controller/modbus_controller.cpp index 9f73988b03..29d3137603 100644 --- a/esphome/components/modbus_controller/modbus_controller.cpp +++ b/esphome/components/modbus_controller/modbus_controller.cpp @@ -116,7 +116,8 @@ void ModbusController::on_modbus_read_registers(uint8_t function_code, uint16_t ESP_LOGD(TAG, "Matched register. Address: 0x%02X. Value type: %zu. Register count: %u. Value: %0.1f.", server_register->address, static_cast(server_register->value_type), server_register->register_count, value); - number_to_payload(sixteen_bit_response, value, server_register->value_type); + std::vector payload = float_to_payload(value, server_register->value_type); + sixteen_bit_response.insert(sixteen_bit_response.end(), payload.cbegin(), payload.cend()); current_address += server_register->register_count; found = true; break;