From 246c47d96ec4c1feb58596c4248cbe054eacbe42 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 16 Nov 2020 15:10:16 -0300 Subject: [PATCH 1/3] KNX: Change DPT9 to DPT14 for sensors and KnxTX --- tasmota/xdrv_11_knx.ino | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tasmota/xdrv_11_knx.ino b/tasmota/xdrv_11_knx.ino index ce8aa6250..774697d92 100644 --- a/tasmota/xdrv_11_knx.ino +++ b/tasmota/xdrv_11_knx.ino @@ -561,7 +561,7 @@ void KNX_CB_Action(message_t const &msg, void *arg) dtostrfd(tempvar,0,tempchar); } else { // VALUE - float tempvar = knx.data_to_2byte_float(msg.data); + float tempvar = knx.data_to_4byte_float(msg.data); dtostrfd(tempvar,2,tempchar); } AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_KNX D_RECEIVED_FROM " %d.%d.%d " D_COMMAND " %s: %s " D_TO " %s"), @@ -630,18 +630,18 @@ void KNX_CB_Action(message_t const &msg, void *arg) } else if (chan->type == KNX_TEMPERATURE) // Reply Temperature { - knx.answer_2byte_float(msg.received_on, last_temp); + knx.answer_4byte_float(msg.received_on, last_temp); if (Settings.flag.knx_enable_enhancement) { - knx.answer_2byte_float(msg.received_on, last_temp); - knx.answer_2byte_float(msg.received_on, last_temp); + knx.answer_4byte_float(msg.received_on, last_temp); + knx.answer_4byte_float(msg.received_on, last_temp); } } else if (chan->type == KNX_HUMIDITY) // Reply Humidity { - knx.answer_2byte_float(msg.received_on, last_hum); + knx.answer_4byte_float(msg.received_on, last_hum); if (Settings.flag.knx_enable_enhancement) { - knx.answer_2byte_float(msg.received_on, last_hum); - knx.answer_2byte_float(msg.received_on, last_hum); + knx.answer_4byte_float(msg.received_on, last_hum); + knx.answer_4byte_float(msg.received_on, last_hum); } } #ifdef USE_RULES @@ -737,10 +737,10 @@ void KnxSensor(uint8_t sensor_type, float value) uint8_t i = KNX_GA_Search(sensor_type); while ( i != KNX_Empty ) { KNX_addr.value = Settings.knx_GA_addr[i]; - knx.write_2byte_float(KNX_addr, value); + knx.write_4byte_float(KNX_addr, value); if (Settings.flag.knx_enable_enhancement) { - knx.write_2byte_float(KNX_addr, value); - knx.write_2byte_float(KNX_addr, value); + knx.write_4byte_float(KNX_addr, value); + knx.write_4byte_float(KNX_addr, value); } AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_KNX "%s " D_SENT_TO " %d.%d.%d "), @@ -1050,10 +1050,10 @@ void CmndKnxTxVal(void) float tempvar = CharToFloat(XdrvMailbox.data); dtostrfd(tempvar,2,XdrvMailbox.data); - knx.write_2byte_float(KNX_addr, tempvar); + knx.write_4byte_float(KNX_addr, tempvar); if (Settings.flag.knx_enable_enhancement) { - knx.write_2byte_float(KNX_addr, tempvar); - knx.write_2byte_float(KNX_addr, tempvar); + knx.write_4byte_float(KNX_addr, tempvar); + knx.write_4byte_float(KNX_addr, tempvar); } AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_KNX "%s = %s " D_SENT_TO " %d.%d.%d"), From 0648881cae78b24345948577e4c3dc114116ed72 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 16 Nov 2020 15:25:54 -0300 Subject: [PATCH 2/3] KNX Lib: Fix 32bits decode --- lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-conversion.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-conversion.cpp b/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-conversion.cpp index 9dc2fd563..06c5127a2 100644 --- a/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-conversion.cpp +++ b/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-conversion.cpp @@ -83,5 +83,7 @@ uint32_t ESPKNXIP::data_to_4byte_uint(uint8_t *data) float ESPKNXIP::data_to_4byte_float(uint8_t *data) { - return (float)((data[1] << 24) | (data[2] << 16) | (data[3] << 8) |data[4]); -} \ No newline at end of file + union { float f; uint32_t i; } num; + num.i = (uint32_t)((data[1] << 24) | (data[2] << 16) | (data[3] << 8) | (data[4] << 0)); + return num.f; +} From 2afba01557fdf1dd2f43b631badcc6670ac31a3d Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 16 Nov 2020 15:26:32 -0300 Subject: [PATCH 3/3] KNX Lib: Fix 32bits encode --- lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-send.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-send.cpp b/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-send.cpp index e71e5954c..270c89b64 100644 --- a/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-send.cpp +++ b/lib/lib_div/esp-knx-ip-0.5.2/src/esp-knx-ip-send.cpp @@ -182,7 +182,13 @@ void ESPKNXIP::send_4byte_uint(address_t const &receiver, knx_command_type_t ct, void ESPKNXIP::send_4byte_float(address_t const &receiver, knx_command_type_t ct, float val) { - uint8_t buf[] = {0x00, ((uint8_t *)&val)[3], ((uint8_t *)&val)[2], ((uint8_t *)&val)[1], ((uint8_t *)&val)[0]}; + union { float f; uint32_t i; } num; + num.f = val; + uint8_t buf[] = {0x00, + (uint8_t)((num.i & 0xFF000000) >> 24), + (uint8_t)((num.i & 0x00FF0000) >> 16), + (uint8_t)((num.i & 0x0000FF00) >> 8), + (uint8_t)((num.i & 0x000000FF) >> 0)}; send(receiver, ct, 5, buf); }