Skip to content

Network Light

Phil Schatzmann edited this page May 26, 2024 · 15 revisions

Device URL

The network light which is part of the gupnp-dlna-tools is a sample test application that can be used easily because it is quite simple.

We can use it to investigate the basic functionality and subsequently implement a control point example which switches the light on and off.

It announces itself via UDP with

NOTIFY * HTTP/1.1.
Host: 239.255.255.250:1900.
Cache-Control: max-age=1800.
Location: http://192.168.1.35:41607/836edb54-5955-49b1-8cf7-8d054e34479e.xml.
Server: Linux/6.5.0-35-generic UPnP/1.0 GUPnP/1.4.3.
NTS: ssdp:alive.
NT: upnp:rootdevice.
USN: uuid:836edb54-5955-49b1-8cf7-8d054e34479e::upnp:rootdevice.

So, the device url is available at http://192.168.1.35:39377/62c9fe67-c027-41b9-b026-9d4c4d697345.xml

Device XML

This provides the following device XML

<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:DimmableLight:1</deviceType>
<friendlyName>GUPnP Network Light</friendlyName>
<manufacturer>GUPnP Developers</manufacturer>
<manufacturerURL>http://www.gupnp.org</manufacturerURL>
<modelDescription>Software emulated UPnP light bulb</modelDescription>
<modelName>Network Light</modelName>
<modelNumber>0.1</modelNumber>
<modelURL>http://www.gupnp.org</modelURL>
<serialNumber>0.1</serialNumber>
<UDN>uuid:62c9fe67-c027-41b9-b026-9d4c4d697345</UDN>
<iconList>
<icon>
<mimetype>image/png</mimetype>
<width>256</width>
<height>256</height>
<depth>32</depth>
<url>/pixmaps/network-light-256x256.png</url>
</icon>
<icon>
<mimetype>image/png</mimetype>
<width>22</width>
<height>22</height>
<depth>32</depth>
<url>/pixmaps/network-light-22x22.png</url>
</icon>
</iconList>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:SwitchPower:1</serviceType>
<serviceId>urn:upnp-org:serviceId:SwitchPower:1</serviceId>
<SCPDURL>/xml/SwitchPower-scpd.xml</SCPDURL>
<controlURL>/SwitchPower/Control</controlURL>
<eventSubURL>/SwitchPower/Events</eventSubURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:Dimming:1</serviceType>
<serviceId>urn:upnp-org:serviceId:Dimming:1</serviceId>
<SCPDURL>/xml/Dimming-scpd.xml</SCPDURL>
<controlURL>/Dimming/Control</controlURL>
<eventSubURL>/Dimming/Events</eventSubURL>
</service>
</serviceList>
<presentationURL/>
</device>
</root>

It provides 2 Services: SwitchPower and Dimming!

Example Service SwitchPower

The SwitchPower service description XML (=SCPDURL) can be found at http://192.168.1.35:39377/xml/SwitchPower-scpd.xml and it provides:

<?xml version="1.0"?>
<scpd xmlns="urn:schemas-upnp-org:service-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>

<actionList>
<action>
<name>SetTarget</name>
<argumentList>
<argument>
<name>newTargetValue</name>
<relatedStateVariable>Target</relatedStateVariable>
<direction>in</direction>
</argument>
</argumentList>
</action>

<action>
<name>GetTarget</name>
<argumentList>
<argument>
<name>RetTargetValue</name>
<relatedStateVariable>Target</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>

<action>
<name>GetStatus</name>
<argumentList>
<argument>
<name>ResultStatus</name>
<relatedStateVariable>Status</relatedStateVariable>
<direction>out</direction>
</argument>
</argumentList>
</action>
</actionList>

<serviceStateTable>
<stateVariable sendEvents="no">
<name>Target</name>
<dataType>boolean</dataType>
<defaultValue>0</defaultValue>
</stateVariable>

<stateVariable sendEvents="yes">
<name>Status</name>
<dataType>boolean</dataType>
<defaultValue>0</defaultValue>
</stateVariable>
</serviceStateTable>

</scpd>

With this, we can now try to switch the power on with the help of SetTarget.

Action: SwitchPower SetTarget

This can be done with a HTTP Post to the control address

POST /SwitchPower/Control HTTP/1.1
HOST: 192.168.1.35 43365
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:SwitchPower:1#SetTarget"

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetTarget xmlns:u="urn:schemas-upnp-org:service:SwitchPower:1">
<newTargetValue>1</newTargetValue>
</u:SetTarget>
</s:Body>
</s:Envelope>

Reply SwitchPower SetTarget

The post provides the following result:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetTargetResponse xmlns:u="urn:schemas-upnp-org:service:SwitchPower:1">
</u:SetTargetResponse>
</s:Body>
</s:Envelope>

Action: SwitchPower GetTarget

We can also get the value with a HTTP Post to the control address

POST /SwitchPower/Control HTTP/1.1
HOST: 192.168.1.35 43365
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:SwitchPower:1#GetTarget"

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetTarget xmlns:u="urn:schemas-upnp-org:service:SwitchPower:1"/>
</s:Body>
</s:Envelope>

Reply SwitchPower GetTarget

The post provides the following result:

<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetTargetResponse xmlns:u="urn:schemas-upnp-org:service:SwitchPower:1">
<RetTargetValue>1</RetTargetValue>
</u:GetTargetResponse>
</s:Body>
</s:Envelope>
Clone this wiki locally