estbeetoo/knx.js

Floating point values not working

Closed this issue · 3 comments

The 2 octet data type for floating point values (DPT 9.00x) is not working properly. This makes reading of temperature values problematic. Any plans to fix this?

Hello, @johnvestberg!
I'm sorry for not so fast response :)
We'll check how it works today with KNX gateway.

May I ask you to provide some more info (and may be error log) of your problem with floating point values?

Closed with #2f6b000

Hi, my turn to apologize for my late response! :)

The error I was experiencing was that for all data types larger than two bytes, the following code in KnxHelper.js (function GetData) was supposed to be executed:

var data = new Buffer(apdu.length);
//TODO: originally, here is utf code to char convert (String.fromCharCode).
apdu[i].copy(data);

However, the code never seemed to execute successfully, so I assume the copy method was throwing some unhandled exception or just caused the thread to abort. I am using the knx.js package as part of the node-red-contrib-knx package. I added a debug=true statement to the knx connection to get as much debug output as possible when running node-red from console. I added a console.log statement just after the apdu[i].copy(data) call, but that log never produced any output. Hence, my assumption that the thread just aborted or something similar.

My own workaround was just to convert the data to floating point when the data length was 3 (similar to your newly committed code). But short after that, I stumbled on the next issue, when I received KNX events with DPT 14 (4 bytes IEEE floating point values). My conclusion then (maybe wrong?) was that I cannot use the length of the data for deciding how to convert it, as several different data types have the same data length. For instance, DPT 13 and DPT 14 are both 4 bytes, but represent different data types.

For this reason, my current workaround is that for all data types bigger than 2 bytes, I write the values as a hex string representation. Then, in node-red when I consume the events, I have a javascript function that converts the hex strings to the respective data type depending on the group address that sent the event.

This workaround works (for now), but obviously it is not a very elegant solution.