View Source KNXex.MulticastClient (knxex v0.1.0)

KNXnet/IP Multicast Client.

The KNX Multicast Client uses multicast to send and receive KNX telegrams (or any other KNX frame). The Client adds its membership to the multicast group and listens for incoming telegrams.

Outgoing KNX frames are sent using multicast, too. The KNX/IP router must be correctly configured to forward the KNX frame to their KNX/TP connection. You may have multiple for each area or line, so the correct KNX/IP router, that should forward the KNX frame, must have the filter table correctly configured.

Each function takes an opts keyword list, which can have an optional :name option, which is then used to call the MulticastClient 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.

Returns a specification to start this module under a supervisor.

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 frame. The frame body must be binary or have a FrameEncoder implementation.

Starts the KNXnet/IP Multicast 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.

Returns a specification to start this module under a supervisor.

See Supervisor.

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_frame(frame, opts \\ [])

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

Sends a raw frame. The frame body must be binary or have a FrameEncoder implementation.

If the frame body is a frame, the request_type can be set to :auto and it will be derived from the FrameEncoder implementation.

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

Starts the KNXnet/IP Multicast 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.

  • frame_callback: (KNXex.Frame.t(), :handled | unhandled) -> any() - Optional. A callback module can be specified, that will be called for all frames which are not explicitely handled by this server module. Two arity: (KNXex.Frame.t(), :handled | :unhandled) - :handled for frames handled by this server module.

  • 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.

  • multicast_ip: :inet.ip4_address() - Optional. The multicast IP address to use. If nil, it will default to 224.0.23.12.

  • source_address: KNXex.IndividualAddress.t() - Required. The KNX individual address that will be used as source address for all non-raw frames. The source address is required, as the KNX/IP router does not fill it in, if the source is 0.0.0 (it is transmitted as-is to the KNX bus).

All other given options are passed to the GenServer 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, reference()} | {:error, :unknown_group_address}

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

The returned reference is currently without any meaning to the user.