KNXnetIP v0.2.0 KNXnetIP.Datapoint View Source

Encoding and decoding of KNX datapoints.

KNX datapoints all have a type as well as a value. The type must be known in order to encode and decode a datapoint.

The datapoint type is a string, consisting of a main number and a subnumber seperated by a dot, e.g. "1.001". The type carries information as to the format, encoding, range and unit of the datapoint. A full list of datapoint types can be seen in the KNX specification (document 3/7/2).

Most datapoint types are mapped directly to a single-valued Elixir data type, but complex KNX values are mapped to tuples. The below table lists these mappings:

Datapoint TypeElixir typeEncodedDecoded
1.*boolean()<<1::6>>true
2.*{c, v}, all elements are integer()<<3::6>>{1, 1}
3.*{c, stepcode}, all elements are integer()<<3>>{0, 3}
4.*binary()<<"T">>"T"
5.*integer()<<123>>123
6.* (except 6.020)integer()<<123>>123
6.020{a, b, c, d, e, f}, all elements are integer()<<180>>{1, 0, 1, 1, 0, 4}
7.*integer()<<3421::16>>3421
8.*integer()<<3421::16>>3421
9.*float()<<13, 220>>30.0
10.*{day, hour, minutes, seconds}, all elements are integer()<204, 43, 12>>{6, 12, 43, 12}
11.*{day, month, year}, all elements are integer()<<12, 5, 19>>{12, 5, 2019}
12.*integer()<<203424034::32>>203424034
13.*integer()<<203424034::32>>203424034
14.*float()<<1174713696::32>>8493.34375
15.*{d6, d5, d4, d3, d2, d1, e, p, d, c, index}, all elements are integer()<<32, 118, 57, 158>>{2, 0, 7, 6, 3, 9, 1, 0, 0, 1, 14}
16.*binary()<<79, 75, 0, 0, ...>>OK
18.*{c, scene_number}, all elements are integer()<<152>>{1, 24}
20.*integer()<<13>>13

Link to this section Summary

Link to this section Functions

Link to this function decode(value, datapoint_type) View Source

Decode a datapoint.

Examples

To decode the value <<67, 152, 15, 131>> of a datapoint with type DPT_Value_Electric_Current (14.019):

iex> Datapoint.decode(<<67, 152, 15, 131>>, "14.019")
{:ok, 304.1211853027344}
Link to this function encode(value, datapoint_type) View Source

Encode a datapoint.

Examples

To encode the value 23.2 with the type DPT_Value_Temp (9.001):

iex> Datapoint.encode(23.2, "9.001")
{:ok, <<12, 136>>}