View Source KNXex.TunnelClient (knxex v0.1.0)

KNXnet/IP Tunnel Client, which wraps around the KNXnetIP.Tunnel behaviour module.

The KNX Tunnel Client connects to a KNXnet/IP server (gateway or router) using a tunnelling connection, to send and receive KNX telegrams.

Processes interested in receiving received KNX telegram need to subscribe to them, using subscribe/1 and unsubscribe/1 to unsubscribe from them.

Each function takes an opts keyword list, which can have an optional :name option, which is then used to call the TunnelClient identified by the :name (a PID or registered name), and an optional :timeout option (defaults to 5000).

Link to this section Summary

Functions

Adds the given group address with the datapoint type (DPT) to the group address list. Unknown group addresses can not be used to send or receive telegrams.

Disconnects from the KNX/IP gateway/router and closes the KNXnet Tunnel server.

Gets all group addresses from the state.

Sends a GroupValueRead to group_address. Waits up to timeout for the response. Utilizes a Task to subscribe temporarily to events.

Removes the given group address from the group address list.

Sends a raw telegram. The returned reference is currently without any meaning to the user.

Sends a telegram. The DPT of the group_address must be known. The returned reference is currently without any meaning to the user.

Starts the KNXnet/IP Tunnel Client.

Subscribes to telegram notifications. The subscriber will receive messages in the form {:knx, KNXex.Telegram.t()}.

Unsubscribes from telegram notifications.

Encodes value according to the DPT of the group_address, and sends it in a GroupValueWrite to group_address.

Link to this section Functions

Link to this function

add_group_address(group_address, dpt, opts \\ [])

View Source
@spec add_group_address(KNXex.GroupAddress.t(), binary(), Keyword.t()) :: :ok

Adds the given group address with the datapoint type (DPT) to the group address list. Unknown group addresses can not be used to send or receive telegrams.

The DPT is in the form of "x.yyy" where x and y are numbers, i.e. 1.001.

@spec close(Keyword.t()) :: :ok

Disconnects from the KNX/IP gateway/router and closes the KNXnet Tunnel server.

Link to this function

get_group_addresses(opts \\ [])

View Source
@spec get_group_addresses(Keyword.t()) ::
  {:ok, %{optional(address :: String.t()) => dpt :: String.t()}}

Gets all group addresses from the state.

Link to this function

read_group_address(group_address, opts \\ [])

View Source
@spec read_group_address(KNXex.GroupAddress.t(), Keyword.t()) ::
  {:ok, KNXex.Telegram.t()}
  | {:error, :unknown_group_address}
  | {:error, :timeout}

Sends a GroupValueRead to group_address. Waits up to timeout for the response. Utilizes a Task to subscribe temporarily to events.

Link to this function

remove_group_address(group_address, opts \\ [])

View Source
@spec remove_group_address(KNXex.GroupAddress.t(), Keyword.t()) :: :ok

Removes the given group address from the group address list.

Link to this function

send_raw_telegram(telegram, opts \\ [])

View Source
@spec send_raw_telegram(KNXnetIP.Telegram.t(), Keyword.t()) :: :ok | {:error, term()}

Sends a raw telegram. The returned reference is currently without any meaning to the user.

Link to this function

send_telegram(telegram, opts \\ [])

View Source
@spec send_telegram(KNXex.Telegram.t(), Keyword.t()) :: :ok | {:error, term()}

Sends a telegram. The DPT of the group_address must be known. The returned reference is currently without any meaning to the user.

@spec start_link(Keyword.t()) :: {:ok, pid()} | {:error, {:already_started, pid()}}

Starts the KNXnet/IP Tunnel Client.

The following options are available (some are required):

  • allow_unknown_gpa: boolean() - Optional. Determines whether unknown Group Addresses are allowed (not ignored when received, defaults to false). This will also mean that you receive the raw undecoded value and you need to provide the raw encoded value when sending.

  • group_addresses: map() - Required. Group addresses map, where the key is the group address in x/y/z notation and the value is the DPT (datapoint type) - both being String.t(). The group address and its DPT is required to determine how to encode and decode received values.

  • local_ip: :inet.ip4_address() - Optional. The local IP address to use. If nil, the local IP address will be discovered.

  • server_ip: :inet.ip4_address() - Required. The KNX/IP gateway/router IP address to connect to.

All other given options are passed to the Tunnel behaviour module (i.e. :name can be given to override the process name to register).

Link to this function

subscribe(pid, opts \\ [])

View Source
@spec subscribe(pid(), Keyword.t()) :: :ok

Subscribes to telegram notifications. The subscriber will receive messages in the form {:knx, KNXex.Telegram.t()}.

Link to this function

unsubscribe(pid, opts \\ [])

View Source
@spec unsubscribe(pid(), Keyword.t()) :: :ok

Unsubscribes from telegram notifications.

Link to this function

write_group_address(group_address, value, opts \\ [])

View Source
@spec write_group_address(KNXex.GroupAddress.t(), term(), Keyword.t()) ::
  :ok | {:error, :unknown_group_address}

Encodes value according to the DPT of the group_address, and sends it in a GroupValueWrite to group_address.