Provides implementation for UPnP+ steps as described in "C.1.7 UCA Steps as Analogies to UDA" of UDA 2.0.
To include UcaLib in the Nerves Image for a target add it as a dependency
in ../nerves_uccd/mix.exs:
def deps do
[{:nerves, "~> 0.5.0", runtime: false},
{:uca_lib, in_umbrella: true}, # <--- here
deps(@target)
endRefers to "C.5 Creating a Device or Control Point Resource" of UDA 2.0
# config.exs
config :uca_lib, Registration,
jid: "user_1@localhost",
password: "pass_1",
host: "localhost"# Connect to an UCS (XMPP server)
{:ok, pid} = UcaLib.Registration.connect host: "169.254.42.110"
# Disconnect from the UCS
UcaLib.Registration.disconnect pidRefers to "C.6 Presence and Discovery" of UDA 2.0
# Send presence of type "available" to the UCS
UcaLib.Discovery.activate pid
# Send presence of type "unavailable" to the UCS
UcaLib.Discovery.deactivate pidRefers to "C.7 PubSub (Analog of Eventing)" of UDA 2.0
- Connect to the server and activate the device
alias UcaLib.{Registration, Discovery, Eventing, Worker, Eventing}
alias Romeo.Stanza
{:ok, pid} = Registration.connect
:ok = Discovery.activate pid- Setup the Eventing
It includes:
- discovery of a pubsub service (it defaults to
pubsub.localhostand can be set via config) - ensuring that the device's pubsub node exists (by default it is named after the resource part of the device JID)
Eventing.setup pid- Connect to the service and activate the device's
Same as for the publisher
- Setup the Eventing
Same as for the publisher expect for creating the device's node.
Eventing.setup pid, create_node: false- Subscribe to a pubsub node of a device
device_jid = "user_1@localhost/urn:schemas-upnp-org:device:Player:1:6603896f-1d42-450b-8a84-0ee323fcacb8"
on_notify = &(IO.puts "=== Got notification on #{inspect &1}: #{inspect &2}")
Eventing.subscribe pid, device_jid, on_notify subitem = Eventing.xml_node("subitem", [], [Eventing.xml_node_content("hello")])
item = Eventing.xml_node("item", [{"id", "12345"}], [subitem])
Eventing.publish pid, item=== Got notification on "5D79BD21BD473": [{:xmlel, "item", [{"id", "12345"}], [{:xmlel, "subitem", [], [xmlcdata: "hello"]}]}]